Instructions to use LiquidAI/LFM2.5-Encoder-350M-Diffusion with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use LiquidAI/LFM2.5-Encoder-350M-Diffusion with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="LiquidAI/LFM2.5-Encoder-350M-Diffusion", trust_remote_code=True) messages = [ {"role": "user", "content": "Who are you?"}, ] pipe(messages)# Load model directly from transformers import AutoTokenizer, AutoModelForMaskedLM tokenizer = AutoTokenizer.from_pretrained("LiquidAI/LFM2.5-Encoder-350M-Diffusion", trust_remote_code=True) model = AutoModelForMaskedLM.from_pretrained("LiquidAI/LFM2.5-Encoder-350M-Diffusion", 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 LiquidAI/LFM2.5-Encoder-350M-Diffusion with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "LiquidAI/LFM2.5-Encoder-350M-Diffusion" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "LiquidAI/LFM2.5-Encoder-350M-Diffusion", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker
docker model run hf.co/LiquidAI/LFM2.5-Encoder-350M-Diffusion
- SGLang
How to use LiquidAI/LFM2.5-Encoder-350M-Diffusion 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 "LiquidAI/LFM2.5-Encoder-350M-Diffusion" \ --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": "LiquidAI/LFM2.5-Encoder-350M-Diffusion", "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 "LiquidAI/LFM2.5-Encoder-350M-Diffusion" \ --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": "LiquidAI/LFM2.5-Encoder-350M-Diffusion", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }' - Docker Model Runner
How to use LiquidAI/LFM2.5-Encoder-350M-Diffusion with Docker Model Runner:
docker model run hf.co/LiquidAI/LFM2.5-Encoder-350M-Diffusion
LFM2.5-Encoder-350M-Diffusion
A full fine-tune of LFM2.5-Encoder-350M as a masked-diffusion instruction model that generates text by iteratively unmasking tokens instead of decoding left to right.
The model was SFT-trained on mlabonne/open-perfectblend, a dataset of roughly 1.39M conversations, for 3 epochs.
Masked diffusion is a natural extension of masked-language modeling: the model starts from masked answer tokens, repeatedly predicts all masked positions, fills the most confident tokens, and continues until the answer is complete.
Find more details about our encoders in our blog post.
๐ป Demos: Try this fine-tuned model running in a CPU-only Hugging Face space: Masked-diffusion text generation โ run the encoder as a chatbot that generates text by iteratively unmasking instead of left to right.
Usage
Install the required packages:
pip install torch transformers
Run masked-diffusion text generation:
import torch
from transformers import AutoModelForMaskedLM, AutoTokenizer
model_id = "LiquidAI/LFM2.5-Encoder-350M-Diffusion"
tokenizer = AutoTokenizer.from_pretrained(model_id, trust_remote_code=True)
model = AutoModelForMaskedLM.from_pretrained(model_id, trust_remote_code=True).eval()
messages = [{"role": "user", "content": "Give one short tip for writing clearer code."}]
prompt = tokenizer.apply_chat_template(messages, tokenize=False, add_generation_prompt=True)
inputs = tokenizer(prompt, return_tensors="pt")
num_new_tokens = 12
mask_id = tokenizer.mask_token_id
input_ids = torch.cat(
[inputs.input_ids, torch.full((1, num_new_tokens), mask_id, dtype=torch.long)],
dim=1,
)
attention_mask = torch.ones_like(input_ids)
with torch.no_grad():
for _ in range(num_new_tokens):
mask_positions = (input_ids[0] == mask_id).nonzero(as_tuple=True)[0]
if len(mask_positions) == 0:
break
logits = model(input_ids=input_ids, attention_mask=attention_mask).logits[0, mask_positions]
logits[:, len(tokenizer):] = -torch.inf
for token_id in tokenizer.all_special_ids:
if token_id != tokenizer.eos_token_id:
logits[:, token_id] = -torch.inf
probs = logits.softmax(dim=-1)
confidence, token_ids = probs.max(dim=-1)
best = confidence.argmax()
input_ids[0, mask_positions[best]] = token_ids[best]
generated = input_ids[0, inputs.input_ids.shape[1]:]
text = tokenizer.decode(generated, skip_special_tokens=True).split("[/Answer]")[0]
print(text.strip())
๐ฌ Contact
- Got questions or want to connect? Join our Discord community
- If you are interested in custom solutions with edge deployment, please contact our sales team.
Citation
@article{liquidAI2026Encoders,
author = {Liquid AI},
title = {LFM2.5-Encoders: Fast at Long Context, Even on CPU},
journal = {Liquid AI Blog},
year = {2026},
note = {www.liquid.ai/blog/lfm2-5-encoders},
}
- Downloads last month
- 27
Model tree for LiquidAI/LFM2.5-Encoder-350M-Diffusion
Base model
LiquidAI/LFM2.5-350M-Base