Text Generation
Transformers
Safetensors
lfm2
mixture-of-experts
tomoe
quantization
conversational
custom_code
8-bit precision
Instructions to use Nichonauta/LFM2.5-350M-ToMoE-INT4 with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use Nichonauta/LFM2.5-350M-ToMoE-INT4 with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="Nichonauta/LFM2.5-350M-ToMoE-INT4", trust_remote_code=True) messages = [ {"role": "user", "content": "Who are you?"}, ] pipe(messages)# Load model directly from transformers import AutoTokenizer, AutoModelForCausalLM tokenizer = AutoTokenizer.from_pretrained("Nichonauta/LFM2.5-350M-ToMoE-INT4", trust_remote_code=True) model = AutoModelForCausalLM.from_pretrained("Nichonauta/LFM2.5-350M-ToMoE-INT4", 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=40) print(tokenizer.decode(outputs[0][inputs["input_ids"].shape[-1]:])) - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use Nichonauta/LFM2.5-350M-ToMoE-INT4 with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "Nichonauta/LFM2.5-350M-ToMoE-INT4" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "Nichonauta/LFM2.5-350M-ToMoE-INT4", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker
docker model run hf.co/Nichonauta/LFM2.5-350M-ToMoE-INT4
- SGLang
How to use Nichonauta/LFM2.5-350M-ToMoE-INT4 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 "Nichonauta/LFM2.5-350M-ToMoE-INT4" \ --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": "Nichonauta/LFM2.5-350M-ToMoE-INT4", "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 "Nichonauta/LFM2.5-350M-ToMoE-INT4" \ --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": "Nichonauta/LFM2.5-350M-ToMoE-INT4", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }' - Docker Model Runner
How to use Nichonauta/LFM2.5-350M-ToMoE-INT4 with Docker Model Runner:
docker model run hf.co/Nichonauta/LFM2.5-350M-ToMoE-INT4
Upload README.md with huggingface_hub
Browse files
README.md
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
license: other
|
| 3 |
+
license_name: lfm1.0
|
| 4 |
+
license_link: https://huggingface.co/LiquidAI/LFM2.5-350M/blob/main/LICENSE
|
| 5 |
+
language:
|
| 6 |
+
- en
|
| 7 |
+
- ar
|
| 8 |
+
- zh
|
| 9 |
+
- fr
|
| 10 |
+
- de
|
| 11 |
+
- ja
|
| 12 |
+
- ko
|
| 13 |
+
- es
|
| 14 |
+
- pt
|
| 15 |
+
base_model: Nichonauta/LFM2.5-350M-ToMoE
|
| 16 |
+
tags:
|
| 17 |
+
- lfm2
|
| 18 |
+
- mixture-of-experts
|
| 19 |
+
- tomoe
|
| 20 |
+
- quantization
|
| 21 |
+
pipeline_tag: text-generation
|
| 22 |
+
library_name: transformers
|
| 23 |
+
---
|
| 24 |
+
|
| 25 |
+
# LFM2.5-350M-ToMoE-INT4
|
| 26 |
+
|
| 27 |
+
Weight-only **INT4** quantization of the real ToMoE MoE — **[Nichonauta/LFM2.5-350M-ToMoE](https://huggingface.co/Nichonauta/LFM2.5-350M-ToMoE)** (derived from [LiquidAI/LFM2.5-350M](https://huggingface.co/LiquidAI/LFM2.5-350M)).
|
| 28 |
+
|
| 29 |
+
Unlike the GGUF companions (which are **dense-equivalents** because llama.cpp cannot represent the channel-MoE), this repository stores the **actual pruned MoE weights** quantized in safetensors format:
|
| 30 |
+
|
| 31 |
+
- `LinearINT4` replaces the MLP/attention/conv Linear layers (per-channel symmetric for INT8; per-group of 64 with zero-point for INT4), packed 2-nibbles-per-byte for INT4.
|
| 32 |
+
- The **routers, embeddings and norms stay fp32** (tiny and sensitive); weights dequantize lazily in the forward pass.
|
| 33 |
+
- Same custom model definition (`modeling_lfm2_moe_final.py`, `trust_remote_code`), plus the `quantization` flag in `config.json`.
|
| 34 |
+
|
| 35 |
+
## Metrics vs the fp32 MoE
|
| 36 |
+
|
| 37 |
+
| Metric | fp32 MoE | INT8 | INT4 |
|
| 38 |
+
|---|---|---|---|
|
| 39 |
+
| PPL wikitext-2 (raw, 1810 tok) | 994 | 987 | 1221 |
|
| 40 |
+
| PPL chat-formatted (prompt+answer) | 314 | 785 | 941 |
|
| 41 |
+
| `model.safetensors` size | 1226 MB | 400 MB | — |
|
| 42 |
+
|
| 43 |
+
The 350M MoE sits at a fragile equilibrium (chat PPL 314 is already near the repetition-collapse regime): INT8 pushes it to ~785 and INT4 to ~941 on chat, while raw-text PPL stays roughly unchanged. This is a property of the pruned model, not of the quantizer.
|
| 44 |
+
|
| 45 |
+
## Usage (transformers, trust_remote_code)
|
| 46 |
+
|
| 47 |
+
```python
|
| 48 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer
|
| 49 |
+
|
| 50 |
+
model = AutoModelForCausalLM.from_pretrained(
|
| 51 |
+
"Nichonauta/LFM2.5-350M-ToMoE-INT4",
|
| 52 |
+
trust_remote_code=True,
|
| 53 |
+
torch_dtype=torch.bfloat16,
|
| 54 |
+
device_map="cuda:0",
|
| 55 |
+
attn_implementation="eager",
|
| 56 |
+
)
|
| 57 |
+
tokenizer = AutoTokenizer.from_pretrained("Nichonauta/LFM2.5-350M-ToMoE-INT4")
|
| 58 |
+
```
|
| 59 |
+
|
| 60 |
+
The `quantization` field in `config.json` makes the custom modeling file build the quantized Linear layers automatically.
|
| 61 |
+
|
| 62 |
+
## Files
|
| 63 |
+
|
| 64 |
+
- `model.safetensors` — INT4 weights + fp32 scales/zero-points + fp32 routers/embeddings/buffers
|
| 65 |
+
- `modeling_lfm2_moe_final.py` — custom model definition with `LinearINT4` support (trust_remote_code)
|
| 66 |
+
- `config.json` — model configuration (`quantization: "int4"`, `auto_map`)
|
| 67 |
+
- `tokenizer.json`, `tokenizer_config.json`, `chat_template.jinja`, `generation_config.json`, `LICENSE`
|
| 68 |
+
|
| 69 |
+
## License
|
| 70 |
+
|
| 71 |
+
Derivative of LiquidAI/LFM2.5-350M — released under the **LFM Open License v1.0** (see `LICENSE`).
|