### Clone Repository and Navigate Source: https://github.com/liquid4all/docs/blob/main/examples/android/vision-language-model-example.mdx Clone the example repository and navigate to the VLM example directory. This is the initial setup step for running the application. ```bash git clone https://github.com/Liquid4All/LeapSDK-Examples.git cd LeapSDK-Examples/Android/VLMExample ``` -------------------------------- ### One-time Setup for leap-finetune Source: https://github.com/liquid4all/docs/blob/main/examples/customize-models/home-assistant.mdx Clone the leap-finetune repository, install dependencies, and log in to HuggingFace and Modal. This is a required setup step before training. ```bash git clone https://github.com/Liquid4All/leap-finetune cd leap-finetune && uv sync && cd - ``` ```bash huggingface-cli login ``` ```bash modal setup ``` -------------------------------- ### Complete Model Bundling Workflow Example Source: https://github.com/liquid4all/docs/blob/main/deployment/tools/model-bundling/quick-start.mdx This example demonstrates the full workflow for creating and downloading a custom model bundle, including installation, authentication, creation, monitoring, and downloading. ```bash # 1. Install and authenticate pip install leap-bundle leap-bundle login leap-bundle whoami # 2. Create a bundle request (GGUF by default) leap-bundle create # 3. Monitor the request (repeat until completed) leap-bundle list # 4. Download when ready leap-bundle download # 5. Your model files are now ready to use! ls -la ``` -------------------------------- ### Clone Repository and Install Dependencies Source: https://github.com/liquid4all/docs/blob/main/examples/laptop-examples/lfm2-english-to-korean.mdx Clone the repository to access the example code and install project dependencies using uv. ```bash git clone https://github.com/Liquid4All/cookbook.git cd cookbook/examples/lfm2-english-to-korean uv sync ``` -------------------------------- ### Setup Python Environment Source: https://github.com/liquid4all/docs/blob/main/examples/laptop-examples/audio-car-cockpit.mdx Clone the repository and set up the Python environment using make. This is the initial step for running the example. ```bash git clone https://github.com/Liquid4All/cookbook.git cd cookbook/examples/audio-car-cockpit make setup ``` -------------------------------- ### Install and Run Hand & Voice Racer Source: https://github.com/liquid4all/docs/blob/main/examples/web/hand-voice-racer.mdx Install project dependencies and start the development server. The audio model will download on first load. ```bash npm install npm run dev ``` -------------------------------- ### Run Documentation Locally Source: https://github.com/liquid4all/docs/blob/main/README.md Navigate to the docs directory, install dependencies, and start the development server using npm and Mintlify. The documentation will be available at http://localhost:3000. ```bash cd docs npm i mintlify dev ``` -------------------------------- ### Clone and Build Project Source: https://github.com/liquid4all/docs/blob/main/examples/laptop-examples/flight-search-assistant.mdx Clone the project repository from GitHub and navigate into the example directory. Install project dependencies using `uv sync`. ```bash git clone https://github.com/Liquid4All/cookbook.git cd cookbook/examples/flight-search-assistant uv sync ``` -------------------------------- ### Clone Repository and Setup Environment Source: https://github.com/liquid4all/docs/blob/main/examples/customize-models/car-maker-identification.mdx Clones the cookbook repository, navigates to the car maker identification example directory, and synchronizes the environment using 'uv'. ```bash git clone https://github.com/Liquid4All/cookbook.git cd cookbook/examples/car-maker-identification uv sync ``` -------------------------------- ### Python Quick Start with Transformers Source: https://github.com/liquid4all/docs/blob/main/lfm/models/lfm25-vl-450m-extract.mdx Install necessary libraries and run the LFM2.5-VL-450M-Extract model using the Transformers library. This example demonstrates loading the model, processor, and performing image-to-JSON extraction. ```bash pip install "transformers>=5.1.0" pillow torch accelerate ``` ```python from transformers import AutoModelForImageTextToText, AutoProcessor from transformers.image_utils import load_image model_id = "LiquidAI/LFM2.5-VL-450M-Extract" model = AutoModelForImageTextToText.from_pretrained( model_id, device_map="auto", dtype="bfloat16", trust_remote_code=True, ) processor = AutoProcessor.from_pretrained(model_id, trust_remote_code=True) image = load_image("https://huggingface.co/LiquidAI/LFM2.5-VL-450M-Extract/resolve/main/sample_image.png") fields_yaml = """wood_color: The overall coloration of the wood surface wood_texture: The tactile quality of the wood surface wood_pattern: The pattern types visible on the wood surface""" system_prompt = f"""Extract the following from the image: {fields_yaml} Respond with only a JSON object. Do not include any text outside the JSON.""" conversation = [ {"role": "system", "content": system_prompt}, {"role": "user", "content": [{"type": "image", "image": image}]}, ] inputs = processor.apply_chat_template( conversation, add_generation_prompt=True, return_tensors="pt", return_dict=True, tokenize=True, ).to(model.device) outputs = model.generate(**inputs, max_new_tokens=512, do_sample=False) response = processor.batch_decode( outputs[:, inputs["input_ids"].shape[1]:], skip_special_tokens=True, )[0] print(response) ``` -------------------------------- ### Install and Authenticate with Modal Source: https://github.com/liquid4all/docs/blob/main/examples/customize-models/satellite-vlm.mdx Install dependencies and authenticate with Hugging Face. This setup is required before preparing data or running fine-tuning jobs. ```bash uv sync uv run python -m modal setup uv run huggingface-cli login ``` -------------------------------- ### Install Dependencies Source: https://github.com/liquid4all/docs/blob/main/examples/web/audio-webgpu-demo.mdx Install the necessary Node.js packages for the demo. Verify npm is installed first. ```bash npm install ``` -------------------------------- ### Install make Source: https://github.com/liquid4all/docs/blob/main/examples/customize-models/car-maker-identification.mdx Installs the 'make' utility using apt-get. This is a prerequisite for certain development tasks. ```bash sudo apt-get install make ``` -------------------------------- ### Clone the Cookbook Repository Source: https://github.com/liquid4all/docs/blob/main/examples/customize-models/home-assistant.mdx Clone the repository containing the Home Assistant example. Navigate into the example directory. ```bash git clone https://github.com/Liquid4All/cookbook.git cd cookbook/examples/home-assistant ``` -------------------------------- ### Quick Start with vLLM Source: https://github.com/liquid4all/docs/blob/main/lfm/models/lfm25-1.2b-jp.mdx Integrate LFM2.5-1.2B-JP into your applications using vLLM for efficient inference. This example demonstrates basic text generation with specified sampling parameters. ```python from vllm import LLM, SamplingParams llm = LLM(model="LiquidAI/LFM2.5-1.2B-JP") sampling_params = SamplingParams(temperature=0.3, min_p=0.15, repetition_penalty=1.05, max_tokens=50) prompts = ["Hello, world!"] outputs = llm.generate(prompts, sampling_params) for output in outputs: prompt = output.prompt generated_text = output.outputs[0].text print(f"Prompt: {prompt!r}, Generated text: {generated_text!r}") ``` -------------------------------- ### Quick Start with Transformers Source: https://github.com/liquid4all/docs/blob/main/lfm/models/lfm2-vl-450m.mdx Use this snippet to quickly integrate the LFM2-VL-450M model with the Transformers library. Ensure the Transformers library is installed. ```javascript import { VlTransformers } from "/snippets/quickstart/vl-transformers.mdx"; ``` -------------------------------- ### Quick Start with SGLang Source: https://github.com/liquid4all/docs/blob/main/lfm/models/lfm25-1.2b-jp.mdx Utilize SGLang for streamlined inference with the LFM2.5-1.2B-JP model. This example focuses on setting up the model for text generation tasks. ```python from sglang.client.api import parse_request, post_request request = parse_request( "LiquidAI/LFM2.5-1.2B-JP", "Hello, world!", max_tokens=50, temperature=0.3, top_p=0.15, repetition_penalty=1.05, ) response = post_request(request) print(response.text) ``` -------------------------------- ### Run Leap Finetune with Installed CLI Source: https://github.com/liquid4all/docs/blob/main/lfm/fine-tuning/leap-finetune.mdx Execute Leap Finetune using the globally installed CLI tool, providing the absolute path to the configuration file. This is the standard way to run after installation. ```bash leap-finetune /absolute/path/to/config.yaml ``` -------------------------------- ### Linux/Windows Native SDK Setup (Gradle) Source: https://github.com/liquid4all/docs/blob/main/deployment/on-device/sdk/quick-start.mdx Apply the ai.liquid.leap.nativelibs plugin in settings.gradle.kts and build.gradle.kts. This plugin handles native library installation and linker flags. ```kotlin // settings.gradle.kts pluginManagement { repositories { mavenCentral(); gradlePluginPortal() } } dependencyResolutionManagement { repositories { mavenCentral() } } ``` ```kotlin // build.gradle.kts plugins { kotlin("multiplatform") version "2.3.20" id("ai.liquid.leap.nativelibs") version "0.10.7" } dependencies { implementation("ai.liquid.leap:leap-sdk:0.10.7") } kotlin { linuxX64 { binaries.executable() } // linuxArm64 { binaries.executable() } // mingwX64 { binaries.executable() } } ``` -------------------------------- ### Swift Background Download Example Source: https://github.com/liquid4all/docs/blob/main/deployment/on-device/sdk/model-loading.mdx Example demonstrating how to set up and use the ModelDownloader for background downloads in Swift. ```APIDOC ## Swift Background Download Setup ### Using Background Session Configuration To enable background downloads that continue when the app is suspended or killed, provide a background `URLSessionConfiguration`: ```swift let backgroundConfig = URLSessionConfiguration.background( withIdentifier: "com.myapp.leap.downloads" ) let downloader = ModelDownloader(sessionConfiguration: backgroundConfig) ``` ### Handling Background Events Forward `application(_:handleEventsForBackgroundURLSession:completionHandler:)` to `downloader.handleBackgroundEvents(completionHandler:)` to manage download completion events when the app is woken by the OS: ```swift func application(_ application: UIApplication, handleEventsForBackgroundURLSession identifier: String, completionHandler: @escaping () -> Void) { // Assuming 'downloader' is accessible here downloader.handleBackgroundEvents(completionHandler: completionHandler) } ``` ``` -------------------------------- ### Install Notebook Dependencies Source: https://github.com/liquid4all/docs/blob/main/notebooks/README.md Installs the necessary development dependencies for the notebooks. This command only needs to be run once. ```bash cd notebooks # install dependencies (only needs to be done once) uv sync --extra dev ``` -------------------------------- ### Clone Repository Source: https://github.com/liquid4all/docs/blob/main/examples/customize-models/car-maker-identification.mdx Clone the cookbook repository to access the example code. Navigate into the specific example directory. ```sh git clone https://github.com/Liquid4All/cookbook.git cd cookbook/examples/car-maker-identification ``` -------------------------------- ### Transformers Quick Start for Structured Extraction Source: https://github.com/liquid4all/docs/blob/main/lfm/models/lfm2-1.2b-extract.mdx Install the Transformers library and run a Python script to perform structured extraction using the LFM2-1.2B-Extract model. Ensure you have PyTorch and Accelerate installed. The example demonstrates setting a system prompt with a schema and a user input for extraction. ```bash pip install "transformers>=5.2.0" torch accelerate ``` ```python from transformers import AutoTokenizer, AutoModelForCausalLM model_id = "LiquidAI/LFM2-1.2B-Extract" tokenizer = AutoTokenizer.from_pretrained(model_id) model = AutoModelForCausalLM.from_pretrained(model_id, device_map="auto") system_prompt = """Identify and extract information matching the following schema. Return data as a JSON object. Missing data should be omitted. Schema: - name: "Person's full name" - email: "Email address" - company: "Company name" """ user_input = "Contact John Smith at john.smith@acme.com. He works at Acme Corp." messages = [ {"role": "system", "content": system_prompt}, {"role": "user", "content": user_input} ] inputs = tokenizer.apply_chat_template(messages, return_tensors="pt", return_dict=True).to(model.device) outputs = model.generate(**inputs, max_new_tokens=256, temperature=0, do_sample=False) response = tokenizer.decode(outputs[0], skip_special_tokens=True) print(response) ``` -------------------------------- ### Few-shot Prompting Example Source: https://github.com/liquid4all/docs/blob/main/lfm/key-concepts/text-generation-and-prompting.mdx Provides example interactions within the prompt to guide the model's output format and behavior. The model learns from these examples. ```python messages = [ {"role": "system", "content": "You are a helpful assistant that formats dates."}, {"role": "user", "content": "2024-01-15"}, {"role": "assistant", "content": "January 15, 2024"}, {"role": "user", "content": "2024-12-25"}, {"role": "assistant", "content": "December 25, 2024"}, {"role": "user", "content": "2024-03-08"} # Model follows the pattern ] ``` -------------------------------- ### Start Development Server Source: https://github.com/liquid4all/docs/blob/main/examples/web/audio-webgpu-demo.mdx Launch the local development server to run the demo. Access it via http://localhost:5173. ```bash npm run dev ``` -------------------------------- ### Example @Guide Annotations Source: https://github.com/liquid4all/docs/blob/main/deployment/on-device/sdk/constrained-generation.mdx Use specific, descriptive annotations for fields to guide the model effectively. Avoid generic descriptions. ```text ✓ @Guide("The programming language name (e.g., Swift, Python, JavaScript)") ✗ @Guide("A string") ``` -------------------------------- ### Colab Environment Setup for vLLM Source: https://github.com/liquid4all/docs/blob/main/notebooks/LFM2_Inference_with_vLLM.ipynb Configures the Colab environment by suppressing stdout and installing protobuf. This setup is specific to Google Colab. ```python # !modal_skip # These are only needed for Colab import contextlib import vllm.utils.system_utils as system_utils !uv pip install -qqq -U "protobuf<5" !VLLM_ENABLE_V1_MULTIPROCESSING=0 system_utils.suppress_stdout = contextlib.nullcontext ``` -------------------------------- ### Clone Repository and Navigate Source: https://github.com/liquid4all/docs/blob/main/examples/laptop-examples/invoice-extractor-tool-with-liquid-nanos.mdx Clone the cookbook repository and navigate to the invoice-parser example directory. This sets up the project locally. ```bash git clone https://github.com/Liquid4All/cookbook.git cd cookbook/examples/invoice-parser ``` -------------------------------- ### Quick Start with Transformers Source: https://github.com/liquid4all/docs/blob/main/lfm/models/lfm25-1.2b-jp.mdx Use this snippet to quickly start generating text with the LFM2.5-1.2B-JP model using the Hugging Face Transformers library. Ensure the 'transformers' library is installed. ```python from transformers import AutoTokenizer, AutoModelForCausalLM tokenizer = AutoTokenizer.from_pretrained("LiquidAI/LFM2.5-1.2B-JP") model = AutoModelForCausalLM.from_pretrained("LiquidAI/LFM2.5-1.2B-JP") inputs = tokenizer("Hello, world!", return_tensors="pt") outputs = model.generate(**inputs, do_sample=True, temperature=0.3, min_p=0.15, repetition_penalty=1.05, max_new_tokens=50) print(tokenizer.decode(outputs[0], skip_special_tokens=True)) ``` -------------------------------- ### Install leap-finetune and Dependencies Source: https://github.com/liquid4all/docs/blob/main/examples/customize-models/wildfire-prevention.mdx Clone the leap-finetune repository and install its dependencies using uv. Ensure you are in the project directory before running. ```bash git clone https://github.com/Liquid4All/leap-finetune.git cd leap-finetune && uv sync && cd .. ``` -------------------------------- ### Start Vision Model Server and Wait for Readiness Source: https://github.com/liquid4all/docs/blob/main/notebooks/LFM2_Inference_with_llama_cpp.ipynb Starts the llama-server with a vision model and polls for its health status. This setup is required before sending image-based requests via the OpenAI API. ```python import subprocess import time server = subprocess.Popen( ["llama-b7633/llama-server", "-hf", "LiquidAI/LFM2.5-VL-1.6B-GGUF:Q4_0", "-c", "4096", "--port", "8000"], stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL ) # Wait for server to be ready for i in range(60): try: result = subprocess.run( ["curl", "-sf", "http://localhost:8000/health"], capture_output=True, timeout=5 ) if result.returncode == 0: print(f"Server ready after {i + 1}s!") break except subprocess.TimeoutExpired: pass time.sleep(1) else: raise RuntimeError("Server failed to start within 60s") ``` -------------------------------- ### Clone Repository Source: https://github.com/liquid4all/docs/blob/main/examples/web/vl-webgpu-demo.mdx Clone the cookbook repository to access the example code. Ensure you have Git installed. ```bash git clone https://github.com/Liquid4All/cookbook.git cd cookbook/examples/vl-webgpu-demo ``` -------------------------------- ### Launch Audio Server and Demo Source: https://github.com/liquid4all/docs/blob/main/examples/laptop-examples/audio-car-cockpit.mdx Start the audio server and the demo application concurrently using make with parallel execution. The -j2 flag enables parallel jobs. ```bash make -j2 audioserver serve ``` -------------------------------- ### Clone Repository Source: https://github.com/liquid4all/docs/blob/main/examples/web/audio-webgpu-demo.mdx Clone the cookbook repository to access the example code. Ensure you have Git installed. ```bash git clone https://github.com/Liquid4All/cookbook.git cd cookbook/examples/audio-webgpu-demo ``` -------------------------------- ### Clone Baseten Inference Repository Source: https://github.com/liquid4all/docs/blob/main/deployment/gpu-inference/baseten.mdx Clone the Baseten inference repository to get started with model deployment. ```bash git clone https://github.com/Liquid4All/lfm-inference ``` -------------------------------- ### Install LiquidONNX Source: https://github.com/liquid4all/docs/blob/main/deployment/on-device/onnx.mdx Clone the repository and install dependencies. Use the `--extra gpu` flag for GPU inference. ```bash git clone https://github.com/Liquid4All/onnx-export.git cd onnx-export uv sync # For GPU inference uv sync --extra gpu ``` -------------------------------- ### Install Transformers and Run LFM2-2.6B-Transcript Source: https://github.com/liquid4all/docs/blob/main/lfm/models/lfm2-2.6b-transcript.mdx Install the necessary libraries and run the LFM2-2.6B-Transcript model for text generation. This example demonstrates how to load the model and tokenizer, apply a system prompt, and generate a response to a user query. ```bash pip install "transformers>=5.2.0" torch accelerate ``` ```python from transformers import AutoTokenizer, AutoModelForCausalLM model_id = "LiquidAI/LFM2-2.6B-Transcript" tokenizer = AutoTokenizer.from_pretrained(model_id) model = AutoModelForCausalLM.from_pretrained(model_id, device_map="auto") system_prompt = """You are an expert meeting analyst. Analyze the transcript carefully and provide clear, accurate information based on the content.""" user_input = """Provide a brief executive summary (2-3 sentences) of the key outcomes and decisions. Title: Budget Planning Meeting Date: March 15, 2024 Time: 2:00 PM Duration: 60 minutes Participants: Sarah Chen (Finance Director), Mike Johnson (Operations Manager) ---------- **Sarah Chen**: Good afternoon. Let's review our Q1 budget performance. **Mike Johnson**: Operations came in 5% under budget this quarter. **Sarah Chen**: For Q2, we need to allocate additional funds for the expansion. **Mike Johnson**: I'll provide a detailed breakdown by next week.""" messages = [ {"role": "system", "content": system_prompt}, {"role": "user", "content": user_input} ] inputs = tokenizer.apply_chat_template(messages, return_tensors="pt", return_dict=True).to(model.device) outputs = model.generate(**inputs, max_new_tokens=512, temperature=0.3, do_sample=True) response = tokenizer.decode(outputs[0], skip_special_tokens=True) print(response) ``` -------------------------------- ### Install Leap Finetune CLI Tool Source: https://github.com/liquid4all/docs/blob/main/lfm/fine-tuning/leap-finetune.mdx Install the Leap Finetune CLI globally as a `uv` tool for easy access from any directory. This simplifies repeated use. ```bash uv tool install git+https://github.com/Liquid4All/leap-finetune.git ``` -------------------------------- ### Clone Fal Inference Repository Source: https://github.com/liquid4all/docs/blob/main/deployment/gpu-inference/fal.mdx Clone the official Fal inference repository to your local machine to get started with deployments. ```bash git clone https://github.com/Liquid4All/lfm-inference ``` -------------------------------- ### Preview Documentation Locally Source: https://github.com/liquid4all/docs/blob/main/lfm/help/contributing.mdx Run this command to preview your documentation changes locally before submitting a pull request. Ensure you have Mintlify installed. ```bash mintlify dev ``` -------------------------------- ### Quick Start with llama.cpp Source: https://github.com/liquid4all/docs/blob/main/lfm/models/lfm25-1.2b-jp.mdx This snippet shows how to run the LFM2.5-1.2B-JP model using llama.cpp. Download the GGUF version of the model and use the provided sampling flags for generation. ```bash ./main -m LiquidAI/LFM2.5-1.2B-JP-GGUF -p "Hello, world!" --temp 0.3 --min-p 0.15 --repeat-penalty 1.05 -n 50 ``` -------------------------------- ### Initialize ModelDownloader with Swift convenience inits Source: https://github.com/liquid4all/docs/blob/main/deployment/on-device/sdk/model-loading.mdx Use Swift convenience inits for foreground downloads with default or custom configurations. Pass nil for sessionConfiguration to use default foreground behavior. ```swift public class ModelDownloader { public init(config: LeapDownloaderConfig, sessionConfiguration: URLSessionConfiguration?) public convenience init() public convenience init(config: LeapDownloaderConfig) public convenience init(sessionConfiguration: URLSessionConfiguration?) } ``` -------------------------------- ### Download llama.cpp Binaries Source: https://github.com/liquid4all/docs/blob/main/deployment/on-device/llama-cpp.mdx Download and extract pre-compiled llama.cpp binaries for Ubuntu x64. This is a quick way to get started with llama-cli. ```bash wget https://github.com/ggml-org/llama.cpp/releases/download/b7633/llama-b7633-bin-ubuntu-x64.tar.gz tar -xzf llama-b7633-bin-ubuntu-x64.tar.gz ``` -------------------------------- ### Install liquid-audio and Dependencies Source: https://github.com/liquid4all/docs/blob/main/lfm/models/lfm2-audio-1.5b.mdx Install the liquid-audio library and optional dependencies for demo purposes. Flash attention 2 is also optional for performance improvements. ```bash pip install liquid-audio pip install "liquid-audio[demo]" # optional, for demo dependencies pip install flash-attn --no-build-isolation # optional, for flash attention 2 ``` -------------------------------- ### Start llama-server with Hugging Face Model Source: https://github.com/liquid4all/docs/blob/main/deployment/on-device/llama-cpp.mdx Starts the llama-server, automatically downloading the specified model from Hugging Face. Configure context length and port. ```bash llama-server -hf LiquidAI/LFM2.5-1.2B-Instruct-GGUF -c 4096 --port 8080 ``` -------------------------------- ### Install vLLM and Run LFM2.5-1.2B-Base Source: https://github.com/liquid4all/docs/blob/main/lfm/models/lfm25-1.2b-base.mdx Install the vLLM library. Initialize the LLM with the LFM2.5-1.2B-Base model and configure sampling parameters. The base model performs raw text completion. ```bash pip install vllm==0.14 ``` ```python from vllm import LLM, SamplingParams llm = LLM(model="LiquidAI/LFM2.5-1.2B-Base") sampling_params = SamplingParams( temperature=0.8, min_p=0.05, max_tokens=512, ) # Base model uses raw text completion output = llm.generate("The future of AI is", sampling_params) print(output[0].outputs[0].text) ``` -------------------------------- ### Transformers Quick Start Source: https://github.com/liquid4all/docs/blob/main/lfm/models/lfm25-1.2b-instruct.mdx Use this snippet to quickly load and run the model with the Transformers library. Ensure you have the library installed and the model ID is correct. ```python from transformers import AutoModelForCausalLM, AutoTokenizer model_id = "LiquidAI/LFM2.5-1.2B-Instruct" model = AutoModelForCausalLM.from_pretrained(model_id) tokenizer = AutoTokenizer.from_pretrained(model_id) # Example usage with sampling parameters inputs = tokenizer("Hello, how are you?", return_tensors="pt") outputs = model.generate(**inputs, do_sample=True, temperature=0.1, top_k=50, repetition_penalty=1.05, max_new_tokens=50) print(tokenizer.decode(outputs[0], skip_special_tokens=True)) ``` -------------------------------- ### vLLM Quick Start for LFM2-700M Source: https://github.com/liquid4all/docs/blob/main/lfm/models/lfm2-700m.mdx Integrate LFM2-700M with vLLM for efficient inference. This example includes common sampling parameters for controlling text generation. ```javascript import { TextVllm } from "/snippets/quickstart/text-vllm.mdx"; ``` -------------------------------- ### Quick Start with llama.cpp (GGUF) Source: https://github.com/liquid4all/docs/blob/main/lfm/models/lfm2-vl-450m.mdx Use this snippet to run the LFM2-VL-450M model with llama.cpp, leveraging the GGUF format for efficient CPU and GPU inference. Adjust sampling flags as needed. ```javascript import { VlLlamacpp } from "/snippets/quickstart/vl-llamacpp.mdx"; ``` -------------------------------- ### Install Dependencies and Push Model Source: https://github.com/liquid4all/docs/blob/main/deployment/gpu-inference/baseten.mdx Install necessary dependencies and push your model to Baseten. Ensure you are in the cloned repository directory. ```bash cd bastenpip install trusstruss push lfm2-8b --publish ``` -------------------------------- ### vLLM Quick Start for LFM2-1.2B Source: https://github.com/liquid4all/docs/blob/main/lfm/models/lfm2-1.2b.mdx Integrate LFM2-1.2B with vLLM for efficient inference. This example demonstrates setting up the model and sampling parameters for text generation. ```python from vllm import LLM, SamplingParams model_id = "LiquidAI/LFM2-1.2B" sampling_params = SamplingParams(temperature=0.3, min_p=0.15, repetition_penalty=1.05, max_tokens=50) llm = LLM.from_pretrained(model_id, trust_remote_code=True) # Example usage: outputs = llm.generate("Hello, my name is", sampling_params) for output in outputs: prompt = output.prompt generated_text = output.outputs[0].text print(f"Prompt: {prompt!r}, Generated text: {generated_text!r}") ``` -------------------------------- ### SGLang Quick Start for LFM2-700M Source: https://github.com/liquid4all/docs/blob/main/lfm/models/lfm2-700m.mdx This snippet demonstrates how to use the LFM2-700M model with SGLang for inference. No specific sampling parameters are shown in this basic setup. ```javascript import { TextSglang } from "/snippets/quickstart/text-sglang.mdx"; ``` -------------------------------- ### Start Gradio Demo for liquid-audio Source: https://github.com/liquid4all/docs/blob/main/lfm/models/lfm2-audio-1.5b.mdx Launch the Gradio web server for the liquid-audio library. This provides an interactive interface for the model. ```bash liquid-audio-demo # Starts webserver on http://localhost:7860/ ``` -------------------------------- ### llama.cpp Quick Start Source: https://github.com/liquid4all/docs/blob/main/lfm/models/lfm25-1.2b-instruct.mdx This snippet shows how to run the model using llama.cpp. It requires downloading the GGUF version of the model and specifying sampling flags. ```bash git clone https://huggingface.co/LiquidAI/LFM2.5-1.2B-Instruct-GGUF cd LFM2.5-1.2B-Instruct-GGUF ./main -m LFM2.5-1.2B-Instruct.gguf -p "Hello, how are you?" --temp 0.1 --top-k 50 --repeat-penalty 1.05 -n 50 ``` -------------------------------- ### llama-server (OpenAI-compatible API) Example Source: https://github.com/liquid4all/docs/blob/main/deployment/on-device/llama-cpp.mdx Use the OpenAI Python client to interact with a locally running llama-server. Ensure the server is started with the correct model and port. ```python from openai import OpenAI client = OpenAI( base_url="http://localhost:8080/v1", api_key="not-needed" ) response = client.chat.completions.create( model="lfm2.5-1.2b-instruct", messages=[{"role": "user", "content": "What is machine learning?"}], temperature=0.1, max_tokens=512, extra_body={"top_k": 50, "repetition_penalty": 1.05}, ) print(response.choices[0].message.content) ``` -------------------------------- ### Transformers Quick Start for LFM2-1.2B Source: https://github.com/liquid4all/docs/blob/main/lfm/models/lfm2-1.2b.mdx Use this snippet to quickly load and run the LFM2-1.2B model with the Transformers library. Ensure you have the library installed and the model ID is correct. ```python from transformers import AutoModelForCausalLM, AutoTokenizer model_id = "LiquidAI/LFM2-1.2B" tokenizer = AutoTokenizer.from_pretrained(model_id) model = AutoModelForCausalLM.from_pretrained(model_id) # Example usage: inputs = tokenizer("Hello, my name is", return_tensors="pt") # Generate text outputs = model.generate(**inputs, do_sample=True, temperature=0.3, min_p=0.15, repetition_penalty=1.05, max_new_tokens=50) print(tokenizer.decode(outputs[0], skip_special_tokens=True)) ``` -------------------------------- ### Quick Start with llama.cpp Source: https://github.com/liquid4all/docs/blob/main/lfm/models/lfm25-350m.mdx This snippet shows how to run the LFM2.5-350M model using llama.cpp. It requires the GGUF format model and specifies sampling flags for generation. ```bash gguf_repo="LiquidAI/LFM2.5-350M-GGUF" sampling_flags="--temp 0.1 --top-k 50 --repeat-penalty 1.05" # Example usage: # ./main -m $gguf_repo -p "Hello, how are you?" $sampling_flags ``` -------------------------------- ### Migrate to LFM2.5-1.2B-Instruct for Tool Calling Source: https://github.com/liquid4all/docs/blob/main/lfm/models/lfm2-1.2b-tool.mdx Use this Python code to load the recommended LFM2.5-1.2B-Instruct model for tool calling. Refer to the Tool Use guide for complete examples. ```python from transformers import AutoTokenizer, AutoModelForCausalLM model_id = "LiquidAI/LFM2.5-1.2B-Instruct" tokenizer = AutoTokenizer.from_pretrained(model_id) model = AutoModelForCausalLM.from_pretrained(model_id, device_map="auto") # See the Tool Use guide for complete examples ``` -------------------------------- ### vLLM Quick Start Source: https://github.com/liquid4all/docs/blob/main/lfm/models/lfm25-1.2b-instruct.mdx Load and run the model with vLLM for efficient inference. Specify the model ID and sampling parameters. ```python from vllm import LLM, SamplingParams model_id = "LiquidAI/LFM2.5-1.2B-Instruct" sampling_params = SamplingParams(temperature=0.1, top_k=50, repetition_penalty=1.05, max_tokens=50) llm = LLM.from_pretrained(model_id) outputs = llm.generate("Hello, how are you?", sampling_params) for output in outputs: prompt = output.prompt generated_text = output.outputs[0].text print(f"Prompt: {prompt!r}, Generated text: {generated_text!r}") ``` -------------------------------- ### Clone Repository and Run Summarizer Source: https://github.com/liquid4all/docs/blob/main/examples/laptop-examples/meeting-summarization.mdx Clones the cookbook repository, navigates to the example directory, and runs the summarization CLI with specific model and transcript file arguments. ```bash git clone https://github.com/Liquid4All/cookbook.git cd cookbook/examples/meeting-summarization uv run summarize.py \ --model LiquidAI/LFM2-2.6B-Transcript-GGUF \ --hf-model-file LFM2-2.6B-Transcript-1-GGUF.gguf \ --transcript-file transcripts/example_1.txt ``` -------------------------------- ### Prefill for Structured Output Source: https://github.com/liquid4all/docs/blob/main/lfm/key-concepts/text-generation-and-prompting.mdx Starts the assistant's response with a partial structure, such as a JSON opening brace, to guide the model towards generating output in a specific format. ```python messages = [ {"role": "system", "content": "Extract information and return as JSON."}, {"role": "user", "content": "Extract the name and age from: John is 30 years old."}, {"role": "assistant", "content": "{\n \"name\": "} # Prefill with JSON structure ] ``` -------------------------------- ### Run Invoice Extractor with Make (Watch Mode) Source: https://github.com/liquid4all/docs/blob/main/examples/laptop-examples/invoice-extractor-tool-with-liquid-nanos.mdx Utilize the 'make run' command for watch mode if 'make' is installed. This simplifies starting the continuous invoice monitoring service. ```bash make run ``` -------------------------------- ### Install Required Packages Source: https://github.com/liquid4all/docs/blob/main/notebooks/💧_LFM2_DPO_with_TRL.ipynb Installs the necessary libraries for the tutorial, including transformers, trl, peft, and nvidia-ml-py. Ensure you are using the specified versions for compatibility. ```python !uv pip install transformers==4.54.0 trl>=0.18.2 peft>=0.15.2 nvidia-ml-py ``` -------------------------------- ### Colab Environment Setup for Vision Models Source: https://github.com/liquid4all/docs/blob/main/notebooks/LFM2_Inference_with_vLLM.ipynb Sets up the Colab environment for vision model inference by disabling multiprocessing and suppressing stdout. It also installs a specific version of protobuf. ```python # These are only needed for Colab import contextlib import vllm.utils.system_utils as system_utils !VLLM_ENABLE_V1_MULTIPROCESSING=0 !uv pip install -qqq -U "protobuf<5" system_utils.suppress_stdout = contextlib.nullcontext ``` -------------------------------- ### Install SGLang, Launch Server, and Query Source: https://github.com/liquid4all/docs/blob/main/lfm/models/lfm25-1.2b-base.mdx Install SGLang using uv pip. Launch the SGLang server with the LFM2.5-1.2B-Base model path. Query the server using an OpenAI-compatible client for text completion, noting that the base model does not use a chat template. ```bash uv pip install "sglang>=0.5.10" ``` ```bash sglang serve \ --model-path LiquidAI/LFM2.5-1.2B-Base \ --host 0.0.0.0 \ --port 30000 ``` ```python from openai import OpenAI client = OpenAI(base_url="http://localhost:30000/v1", api_key="None") # Base model uses raw text completion (not chat) response = client.completions.create( model="LiquidAI/LFM2.5-1.2B-Base", prompt="The future of AI is", temperature=0.8, max_tokens=512, ) print(response.choices[0].text) ``` -------------------------------- ### Gradle Groovy DSL Dependencies Source: https://github.com/liquid4all/docs/blob/main/deployment/on-device/sdk/desktop-platforms.mdx Integrate the Leap SDK into your Java or Kotlin JVM project using Gradle with Groovy DSL. This example shows the basic dependency setup. ```groovy plugins { id 'org.jetbrains.kotlin.jvm' version '2.3.20' id 'application' } repositories { mavenCentral() } dependencies { implementation 'ai.liquid.leap:leap-sdk:0.10.7' } application { mainClass = 'com.example.AppKt' } ``` -------------------------------- ### Quick Start with Transformers Source: https://github.com/liquid4all/docs/blob/main/lfm/models/lfm25-8b-a1b.mdx Load and run inference with the LFM2.5-8B-A1B model using the Hugging Face Transformers library. Ensure transformers>=5.0.0 is installed. For compatible GPUs, uncomment the `attn_implementation` line to use Flash Attention 2. ```python from transformers import AutoModelForCausalLM, AutoTokenizer, TextStreamer model_id = "LiquidAI/LFM2.5-8B-A1B" model = AutoModelForCausalLM.from_pretrained( model_id, device_map="auto", dtype="bfloat16", # attn_implementation="flash_attention_2" <- uncomment on compatible GPU ) tokenizer = AutoTokenizer.from_pretrained(model_id) streamer = TextStreamer(tokenizer, skip_prompt=True, skip_special_tokens=True) prompt = "What is C. elegans?" input_ids = tokenizer.apply_chat_template( [{"role": "user", "content": prompt}], add_generation_prompt=True, return_tensors="pt", tokenize=True, ).to(model.device) output = model.generate( input_ids, do_sample=True, temperature=0.2, top_k=80, repetition_penalty=1.05, max_new_tokens=8192, streamer=streamer, ) ```