Instructions to use LiquidAI/LFM2-8B-A1B-smoltalk-LoRA with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- PEFT
How to use LiquidAI/LFM2-8B-A1B-smoltalk-LoRA with PEFT:
from peft import PeftModel from transformers import AutoModelForCausalLM base_model = AutoModelForCausalLM.from_pretrained("LiquidAI/LFM2-8B-A1B") model = PeftModel.from_pretrained(base_model, "LiquidAI/LFM2-8B-A1B-smoltalk-LoRA") - Notebooks
- Google Colab
- Kaggle
LFM2-8B-A1B SmolTalk LoRA
LoRA adapter for LiquidAI/LFM2-8B-A1B (8B total / 1B active MoE) fine-tuned on SmolTalk.
Published in the per-expert layout (...experts.<N>.w1/w3/w2.lora_*, Mixtral-style) β the interchange format that both HF PEFT and inference engines load:
- HF PEFT (
peft > 0.19.1,transformers β₯ 5.8): loaded via transformers' registeredlfm2_moeweight conversion, which folds the per-expert keys into the batched expert layout at load time. Verified token-identical to the originally trained adapter. - SGLang (with sgl-project/sglang#27813): loaded directly via the per-expert MoE LoRA path.
Full module coverage: attention (q/k/v/out_proj), ShortConv (in_proj/out_proj), dense MLP (layers 0β1), MoE router (gate), and all 32 experts on every MoE layer.
The
rank_pattern/alpha_patternentries inadapter_config.jsonare required: the fusedexperts.gate_up_projslot reconstructed from independent per-expert gate/up halves has rank 2r=16 (alpha scaled to 32 to preserve the effective scale of 2.0). The per-expert tensors themselves are rank 8.
Training
| Parameter | Value |
|---|---|
| Base model | LiquidAI/LFM2-8B-A1B |
| Dataset | HuggingFaceTB/smoltalk (5000-sample slice) |
| Rank (r) | 8 |
| Alpha | 16 |
| Dropout | 0 |
| Learning rate | 5e-5 (linear schedule, warmup 0.1) |
| Epochs | 3 |
| Effective batch size | 64 |
| Eval loss | 0.974 β 0.852 β 0.827 (epoch 1 β 2 β 3) |
Trained with PEFT target_parameters on the batched expert tensors; this artifact is a lossless repacking (bundled script: convert_lfm2_moe_lora_to_per_expert.py). The original target_parameters-format weights remain available at revision e3d7523.
Usage with HF PEFT
import torch
from transformers import AutoModelForCausalLM, AutoTokenizer
from peft import PeftModel
MODEL_ID = "LiquidAI/LFM2-8B-A1B"
base = AutoModelForCausalLM.from_pretrained(MODEL_ID, dtype=torch.bfloat16, device_map="auto")
model = PeftModel.from_pretrained(base, "LiquidAI/LFM2-8B-A1B-smoltalk-LoRA")
Requires peft > 0.19.1 (e.g. pip install git+https://github.com/huggingface/peft.git until the next release β 0.19.1 has a WeightConverter incompatibility with transformers β₯ 5.6 that affects loading any LoRA on this architecture).
Usage with SGLang
sglang serve \
--model-path LiquidAI/LFM2-8B-A1B \
--port 30000 \
--enable-lora --max-lora-rank 8 \
--lora-paths "smoltalk=LiquidAI/LFM2-8B-A1B-smoltalk-LoRA" \
--lora-target-modules q_proj k_proj v_proj out_proj gate_proj up_proj down_proj in_proj gate \
--lora-strict-loading
When serving with --dtype float16, also set SGLANG_MAMBA_CONV_DTYPE=float16 (the ShortConv state cache defaults to bf16). The default bf16 serving needs no extra flags.
curl -sS http://localhost:30000/generate \
-H "Content-Type: application/json" \
-d '{
"text": "Write a short story set in an unusual location.",
"sampling_params": {"temperature": 0.0, "max_new_tokens": 80},
"lora_path": "smoltalk"
}'
Correctness
Both load paths were verified by teacher-forced top-k logprob comparison (greedy, fp16, same GPU), with this exact artifact on both sides: HF+PEFT and SGLang produce token-identical generations; prefill logprob divergence mean 0.011 / max 0.026.
- Downloads last month
- 11