Instructions to use styal/leffm-1.7b with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use styal/leffm-1.7b with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="styal/leffm-1.7b", trust_remote_code=True) messages = [ {"role": "user", "content": "Who are you?"}, ] pipe(messages)# pip install -U transformers accelerate # Load model directly from transformers import AutoTokenizer, AutoModelForCausalLM tokenizer = AutoTokenizer.from_pretrained("styal/leffm-1.7b", trust_remote_code=True) model = AutoModelForCausalLM.from_pretrained("styal/leffm-1.7b", trust_remote_code=True, device_map="auto") messages = [ {"role": "user", "content": "Who are you?"}, ] inputs = tokenizer.apply_chat_template( messages, add_generation_prompt=True, tokenize=True, return_dict=True, return_tensors="pt", ).to(model.device) outputs = model.generate(**inputs, max_new_tokens=256) print(tokenizer.decode(outputs[0][inputs["input_ids"].shape[-1]:])) - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- llama.cpp
How to use styal/leffm-1.7b with llama.cpp:
Install (macOS, Linux)
curl -LsSf https://llama.app/install.sh | sh # Start a local OpenAI-compatible server with a web UI: llama serve -hf styal/leffm-1.7b:Q8_0 # Run inference directly in the terminal: llama cli -hf styal/leffm-1.7b:Q8_0
Install from WinGet (Windows)
winget install llama.cpp # Start a local OpenAI-compatible server with a web UI: llama serve -hf styal/leffm-1.7b:Q8_0 # Run inference directly in the terminal: llama cli -hf styal/leffm-1.7b:Q8_0
Build from source code
git clone https://github.com/ggml-org/llama.cpp.git cd llama.cpp cmake -B build cmake --build build -j --target llama-app # Start a local OpenAI-compatible server with a web UI: ./build/bin/llama serve -hf styal/leffm-1.7b:Q8_0 # Run inference directly in the terminal: ./build/bin/llama cli -hf styal/leffm-1.7b:Q8_0
Use Docker
docker model run hf.co/styal/leffm-1.7b:Q8_0
- Llama new
- LM Studio
- Jan
- vLLM
How to use styal/leffm-1.7b with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "styal/leffm-1.7b" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "styal/leffm-1.7b", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker
docker model run hf.co/styal/leffm-1.7b:Q8_0
- SGLang
How to use styal/leffm-1.7b with SGLang:
Install from pip and serve model
# Install SGLang from pip: pip install sglang # Start the SGLang server: python3 -m sglang.launch_server \ --model-path "styal/leffm-1.7b" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "styal/leffm-1.7b", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker images
docker run --gpus all \ --shm-size 32g \ -p 30000:30000 \ -v ~/.cache/huggingface:/root/.cache/huggingface \ --env "HF_TOKEN=<secret>" \ --ipc=host \ lmsysorg/sglang:latest \ python3 -m sglang.launch_server \ --model-path "styal/leffm-1.7b" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "styal/leffm-1.7b", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }' - Ollama
How to use styal/leffm-1.7b with Ollama:
ollama run hf.co/styal/leffm-1.7b:Q8_0
- Unsloth Desktop
- Pi
How to use styal/leffm-1.7b with Pi:
Start the llama.cpp server
# Install llama.cpp: brew install llama.cpp # Start a local OpenAI-compatible server: llama serve -hf styal/leffm-1.7b:Q8_0
Configure the model in Pi
# Install Pi: npm install -g @earendil-works/pi-coding-agent # Add to ~/.pi/agent/models.json: { "providers": { "llama-cpp": { "baseUrl": "http://localhost:9931/v1", "api": "openai-completions", "apiKey": "none", "models": [ { "id": "styal/leffm-1.7b:Q8_0" } ] } } }Run Pi
# Start Pi in your project directory: pi
- Docker Model Runner
How to use styal/leffm-1.7b with Docker Model Runner:
docker model run hf.co/styal/leffm-1.7b:Q8_0
- Lemonade
How to use styal/leffm-1.7b with Lemonade:
Pull the model
# Download Lemonade from https://lemonade-server.ai/ lemonade pull styal/leffm-1.7b:Q8_0
Run and chat with the model
lemonade run user.leffm-1.7b-Q8_0
List all available models
lemonade list
- Hermes Agent
How to use styal/leffm-1.7b with Hermes Agent:
Start the llama.cpp server
# Install llama.cpp: brew install llama.cpp # Start a local OpenAI-compatible server: llama serve -hf styal/leffm-1.7b:Q8_0
Configure Hermes
# Install Hermes: curl -fsSL https://hermes-agent.nousresearch.com/install.sh | bash hermes setup # Point Hermes at the local server: hermes config set model.provider custom hermes config set model.base_url http://127.0.0.1:9931/v1 hermes config set model.default styal/leffm-1.7b:Q8_0
Run Hermes
hermes
- Atomic Chat
- OpenClaw
How to use styal/leffm-1.7b with OpenClaw:
Start the llama.cpp server
# Install llama.cpp: brew install llama.cpp # Start a local OpenAI-compatible server: llama serve -hf styal/leffm-1.7b:Q8_0
Configure OpenClaw
# Install OpenClaw: npm install -g openclaw@latest # Register the local server and set it as the default model: openclaw onboard --non-interactive --mode local \ --auth-choice custom-api-key \ --custom-base-url http://127.0.0.1:9931/v1 \ --custom-model-id "styal/leffm-1.7b:Q8_0" \ --custom-provider-id llama-cpp \ --custom-compatibility openai \ --custom-text-input \ --accept-risk \ --skip-health
Run OpenClaw
openclaw agent --local --agent main --message "Hello from Hugging Face"
|
Download README.md from styal/leffm-1.7b: direct link, hf CLI and curl.
- Browser
- Download file 7.44 kB
-
https://huggingface.co/styal/leffm-1.7b/resolve/main/README.md
- Command line
-
hf download hf://styal/leffm-1.7b/README.md
-
curl -L -o README.md https://huggingface.co/styal/leffm-1.7b/resolve/main/README.md
7.44 kB
| library_name: transformers | |
| pipeline_tag: text-generation | |
| base_model: LiquidAI/LFM3-1.7B | |
| tags: | |
| - gguf | |
| - safetensors | |
| - lfm3 | |
| - cascade | |
| - sparse-ffn | |
| - conversational | |
| license: other | |
| license_name: lfm1.0 | |
| license_link: https://huggingface.co/LiquidAI/LFM3-1.7B/blob/main/LICENSE | |
| # leffm-1.7b | |
| **leffm** — Liquid Efficient Foundation Model — is [LFM3-1.7B](https://huggingface.co/LiquidAI/LFM3-1.7B) | |
| with two changes, both trained in: | |
| - a **cascade FFN** that computes **30% fewer FLOPs per token**; | |
| - a **vocabulary cut** to 65,536 tokens (**7.4% fewer parameters**). | |
| Runs in [llama.cpp via styalai/leffm-llamacpp](https://github.com/styalai/leffm-llamacpp). | |
| | file | format | size | | |
| |---|---|---| | |
| | `leffm-1.7b-Q8_0.gguf` | GGUF, Q8_0 — **recommended** | 1.7 GB | | |
| | `model.safetensors` | Transformers, bf16 | 3.2 GB | | |
| ## Performance | |
| Batch-1 decode, Q8_0, greedy, best of five. Hardware: NVIDIA L4 (CUDA), Apple M5 (Metal, and CPU with | |
| `-t 4`). The CUDA row was measured with a build that has `-DGGML_CUDA_FA=OFF`: FlashAttention changes | |
| the attention kernels only, not the FFN cascade being compared. | |
| | backend | LFM3-1.7B | leffm | speedup | | |
| |---|---:|---:|---:| | |
| | CUDA | 9.01 ms/token | **7.54 ms/token** | **1.19x** | | |
| | Metal | 15.16 ms/token | **12.47 ms/token** | **1.22x** | | |
| | CPU | 22.8 ms/token | 25.4 ms/token | 0.90x | | |
| The GPU speedups are smaller than the 30% FLOP reduction because batch-1 decode is bandwidth-bound and | |
| the two selections cost real time. On CPU the model stays slower than dense: ggml's int8 matvec already | |
| runs at the part's limit, so reading 30% fewer bytes buys nothing there. | |
| ## Quality | |
| Perplexity on a held-out slice of `styal/calib-data` (64 sequences, 115,159 bytes), after one matched | |
| continued-pretraining run of 2.67M tokens — the dense control and leffm trained for the same 163 steps: | |
| | model | vocab | FFN | PPL/token | bits/byte | | |
| | --- | ---: | --- | ---: | ---: | | |
| | stock LFM3-1.7B | 128,000 | dense | 3.392 | 0.4270 | | |
| | dense, after CPT | 128,000 | dense | **2.832** | **0.3639** | | |
| | **leffm** | 65,536 | cascade | **3.035** | **0.3885** | | |
| Against the dense model trained the same way, leffm costs **+0.069 nats (+6.8% bits/byte)**. The cut | |
| tokenizer needs 1.0043x as many tokens for the same text, so bits/byte is the comparable column. | |
| In llama.cpp, on the same weights, the file measures PPL **3.450** with the cascade and **3.174** with | |
| the FFN forced dense (batch-1 decode, Q8_0). | |
| ## Huggingface | |
| You can use the bf16 version direcly with huggingface or use llama cpp form. | |
| ```python | |
| from transformers import AutoTokenizer, AutoModelForCausalLM | |
| tokenizer = AutoTokenizer.from_pretrained("styal/leffm-1.7b", trust_remote_code=True) | |
| model = AutoModelForCausalLM.from_pretrained("styal/leffm-1.7b", trust_remote_code=True, device_map="auto") | |
| messages = [ | |
| {"role": "user", "content": "Who are you?"}, | |
| ] | |
| inputs = tokenizer.apply_chat_template( | |
| messages, | |
| add_generation_prompt=True, | |
| tokenize=True, | |
| return_dict=True, | |
| return_tensors="pt", | |
| ).to(model.device) | |
| outputs = model.generate(**inputs, max_new_tokens=256) | |
| print(tokenizer.decode(outputs[0][inputs["input_ids"].shape[-1]:])) | |
| ``` | |
| ## Install | |
| Two steps: build the fork, download the file. Then run it. | |
| **Prerequisites** — `git`, CMake (3.14 or newer), a C++17 compiler. For NVIDIA GPUs: the CUDA toolkit | |
| (12.x or 13.x) with `nvcc` on `PATH`. On macOS nothing else is needed; the default build uses Metal. | |
| ### 1. Build the fork | |
| **NVIDIA GPU (CUDA)** — FlashAttention is built in, and `native` detects the local GPU: | |
| ```sh | |
| git clone https://github.com/styalai/leffm-llamacpp && cd leffm-llamacpp | |
| cmake -B build -DGGML_CUDA=ON -DCMAKE_CUDA_ARCHITECTURES=native -DCMAKE_BUILD_TYPE=Release | |
| cmake --build build -j --target llama-cli llama-bench | |
| ``` | |
| **Apple silicon (Metal — the default backend there) or CPU**: | |
| ```sh | |
| git clone https://github.com/styalai/leffm-llamacpp && cd leffm-llamacpp | |
| cmake -B build -DCMAKE_BUILD_TYPE=Release | |
| cmake --build build -j --target llama-cli llama-bench | |
| ``` | |
| - `-DCMAKE_CUDA_ARCHITECTURES=native` compiles for the GPU in the machine. Set it explicitly only to | |
| cross-compile: `89` Ada (L4, L40S, RTX 40xx), `80` A100, `86` A10 / RTX 30xx, `90` H100. | |
| - The second command enables Metal by itself on Apple silicon, and on a machine without a GPU it builds | |
| a CPU-only binary — the same flags work everywhere. | |
| A few minutes later `build/bin/llama-cli` and `build/bin/llama-bench` are ready. | |
| ### 2. Download the model | |
| ```sh | |
| hf auth login # this repo is private | |
| hf download styal/leffm-1.7b leffm-1.7b-Q8_0.gguf --local-dir . | |
| ``` | |
| ### 3. Run it | |
| ```sh | |
| ./build/bin/llama-cli -m leffm-1.7b-Q8_0.gguf -p "The quick brown fox" -n 64 | |
| ``` | |
| `-ngl 999` forces every layer onto the GPU; the default is auto, which already does that when the | |
| model fits (1.7 GB). `-cnv` starts a chat instead of a single completion. | |
| ### 4. Benchmark it | |
| ```sh | |
| ./build/bin/llama-bench -m leffm-1.7b-Q8_0.gguf -p 0 -n 32 -r 3 -ngl 999 --no-warmup | |
| ``` | |
| The `tg32` row is decode speed, `pp512` would be prompt processing. | |
| ### Nothing else to configure | |
| The file carries its own operating point — `llama-cli` logs | |
| `cascade FFN: c = 5120, k = 2304 (model metadata)` at load — so there are no environment variables, no | |
| vocabulary file and no `--no-repack` to remember. | |
| - `LLAMA_CASCADE=7680,7680` reproduces the dense FFN exactly — greedy output identical to | |
| `LLAMA_CASCADE=0,0` on these same weights. That is the arithmetic identity check. | |
| - `LLAMA_CASCADE=0,0` runs these weights with the ordinary dense FFN (this is how the two perplexity | |
| numbers above were taken). | |
| - Batch 1 only: the cascade is a single-token decode path. Prompt processing stays dense. | |
| ## What is it? | |
| ### The cascade FFN | |
| A gated FFN computes | |
| $$\mathrm{FFN}(x) = \big(\mathrm{silu}(xW_{\mathrm{gate}}^{T}) \odot (xW_{\mathrm{up}}^{T})\big) W_{\mathrm{down}}$$, | |
| with `F = 7,680` units. The gate has to see every unit — it is the router — but the other two | |
| projections do not: | |
| ``` | |
| x ──► W_gate all 7,680 units, the router | |
| │ | |
| ├─ stage 1: keep the top c = 5,120 units by |silu(gate)| | |
| │ | |
| ├─ W_up rows of those 5,120 units ──► u | |
| └─ stage 2: keep the top k = 2,304 units by |silu(gate) · u| | |
| │ | |
| └─ W_down columns of those 2,304 units ──► FFN(x) | |
| ``` | |
| So the FFN gathers 5,120 rows and 2,304 columns instead of running all 7,680 twice: **47.2M → 30.9M | |
| MACs per token (65.6% of dense)**. Both selections are exact top-k (a radix select over the float bit | |
| pattern), not a threshold, so the unit counts hold every token. | |
| ### The vocabulary cut | |
| The stock embedding table has 128,000 rows, 125,033 of them real tokens (the rest is padding). This | |
| model keeps 65,536 of them, chosen from `styal/calib-data`: | |
| 1. keep every special token and every single-character token (the BPE base alphabet) — these must | |
| exist for any text to tokenize; | |
| 2. rank the rest by frequency on that corpus, ties toward the shorter surface form; | |
| 3. keep the top 65,536. | |
| The input embedding and the output head are tied and cut together, and the tokenizer in this repo is | |
| the cut tokenizer — nothing is remapped at load time. The removed tokens carry 0.41% of the stock | |
| model's probability mass. | |
| ## Licence | |
| LFM Open License v1.0, inherited from LFM3-1.7B — see [LICENSE](LICENSE). | |