Views
No views yet


| Property | LFM2-350M | LFM2-700M | LFM2-1.2B | LFM2-2.6B |
|---|---|---|---|---|
| Parameters | 354,483,968 | 742,489,344 | 1,170,340,608 | 2,569,272,320 |
| Layers | 16 (10 conv + 6 attn) | 16 (10 conv + 6 attn) | 16 (10 conv + 6 attn) | 30 (22 conv + 8 attn) |
| Context length | 32,768 tokens | 32,768 tokens | 32,768 tokens | 32,768 tokens |
| Vocabulary size | 65,536 | 65,536 | 65,536 | 65,536 |
| Precision | bfloat16 | bfloat16 | bfloat16 | bfloat16 |
| Training budget | 10 trillion tokens | 10 trillion tokens | 10 trillion tokens | 10 trillion tokens |
| License | LFM Open License v1.0 | LFM Open License v1.0 | LFM Open License v1.0 | LFM Open License v1.0 |
temperature=0.3min_p=0.15repetition_penalty=1.05<|startoftext|><|im_start|>system
You are a helpful assistant trained by Liquid AI.<|im_end|>
<|im_start|>user
What is C. elegans?<|im_end|>
<|im_start|>assistant
It's a tiny nematode that lives in temperate soil environments.<|im_end|>.apply_chat_template() function from Hugging Face transformers.<|tool_list_start|> and <|tool_list_end|> special tokens), usually in the system prompt<|tool_call_start|> and <|tool_call_end|> special tokens), as the assistant answer.<|tool_response_start|> and <|tool_response_end|> special tokens), as a "tool" role.<|startoftext|><|im_start|>system
List of tools: <|tool_list_start|>[{"name": "get_candidate_status", "description": "Retrieves the current status of a candidate in the recruitment process", "parameters": {"type": "object", "properties": {"candidate_id": {"type": "string", "description": "Unique identifier for the candidate"}}, "required": ["candidate_id"]}}]<|tool_list_end|><|im_end|>
<|im_start|>user
What is the current status of candidate ID 12345?<|im_end|>
<|im_start|>assistant
<|tool_call_start|>[get_candidate_status(candidate_id="12345")]<|tool_call_end|>Checking the current status of candidate ID 12345.<|im_end|>
<|im_start|>tool
<|tool_response_start|>[{"candidate_id": "12345", "status": "Interview Scheduled", "position": "Clinical Research Associate", "date": "2023-11-20"}]<|tool_response_end|><|im_end|>
<|im_start|>assistant
The candidate with ID 12345 is currently in the "Interview Scheduled" stage for the position of Clinical Research Associate, with an interview date set for 2023-11-20.<|im_end|>.apply_chat_template() as shown in this page to automatically format the system prompt.npm i @huggingface/transformers1import { pipeline, TextStreamer } from "@huggingface/transformers";
2
3// Create a text generation pipeline
4const generator = await pipeline(
5 "text-generation",
6 "onnx-community/LFM2-2.6B-Exp-ONNX",
7 { dtype: "q4", device: "webgpu" },
8);
9
10// Define the list of messages
11const messages = [
12 { role: "user", content: "What's the capital of France?" },
13];
14
15// Generate a response
16const output = await generator(messages, {
17 max_new_tokens: 512,
18 do_sample: false,
19 streamer: new TextStreamer(generator.tokenizer, {
20 skip_prompt: true,
21 skip_special_tokens: true,
22 }),
23});
24console.log(output[0].generated_text.at(-1).content);1from transformers import AutoConfig, AutoTokenizer
2import onnxruntime
3import numpy as np
4from huggingface_hub import hf_hub_download
5
6# 1. Load config, processor, and model
7model_id = "onnx-community/LFM2-2.6B-Exp-ONNX"
8config = AutoConfig.from_pretrained(model_id)
9tokenizer = AutoTokenizer.from_pretrained(model_id)
10filename = "model_q4.onnx" # Options: "model.onnx", "model_fp16.onnx", "model_q4.onnx", "model_q4f16.onnx"
11model_path = hf_hub_download(repo_id=model_id, filename=f"onnx/{filename}") # Download the graph
12hf_hub_download(repo_id=model_id, filename=f"onnx/{filename}_data") # Download the weights
13session = onnxruntime.InferenceSession(model_path)
14
15## Set config values
16num_key_value_heads = config.num_key_value_heads
17head_dim = config.hidden_size // config.num_attention_heads
18num_hidden_layers = config.num_hidden_layers
19eos_token_id = config.eos_token_id
20hidden_size = config.hidden_size
21conv_L_cache = config.conv_L_cache
22layer_types = config.layer_types
23
24# 2. Prepare inputs
25prompt = "What is C. elegans?"
26messages = [{"role": "user", "content": prompt}]
27inputs = tokenizer.apply_chat_template(messages, add_generation_prompt=True, tokenize=True, return_dict=True, return_tensors="np")
28input_ids = inputs['input_ids']
29attention_mask = inputs['attention_mask']
30batch_size = input_ids.shape[0]
31past_cache_values = {}
32for i in range(num_hidden_layers):
33 if layer_types[i] == 'full_attention':
34 for kv in ('key', 'value'):
35 past_cache_values[f'past_key_values.{i}.{kv}'] = np.zeros([batch_size, num_key_value_heads, 0, head_dim], dtype=np.float32)
36 elif layer_types[i] == 'conv':
37 past_cache_values[f'past_conv.{i}'] = np.zeros([batch_size, hidden_size, conv_L_cache], dtype=np.float32)
38 else:
39 raise ValueError(f"Unsupported layer type: {layer_types[i]}")
40
41# 3. Generation loop
42max_new_tokens = 1024
43generated_tokens = np.array([[]], dtype=np.int64)
44for i in range(max_new_tokens):
45 logits, *present_cache_values = session.run(None, dict(
46 input_ids=input_ids,
47 attention_mask=attention_mask,
48 **past_cache_values,
49 ))
50
51 ## Update values for next generation loop
52 input_ids = logits[:, -1].argmax(-1, keepdims=True)
53 attention_mask = np.concatenate([attention_mask, np.ones_like(input_ids, dtype=np.int64)], axis=-1)
54 for j, key in enumerate(past_cache_values):
55 past_cache_values[key] = present_cache_values[j]
56 generated_tokens = np.concatenate([generated_tokens, input_ids], axis=-1)
57 if (input_ids == eos_token_id).all():
58 break
59
60 ## (Optional) Streaming
61 print(tokenizer.decode(input_ids[0]), end='', flush=True)
62print()
63
64# 4. Output result
65print(tokenizer.batch_decode(generated_tokens, skip_special_tokens=True)[0])| Notebook | Description | Link |
|---|---|---|
| SFT (Unsloth) | Supervised Fine-Tuning (SFT) notebook with a LoRA adapter using Unsloth. | ![]() |
| SFT (TRL) | Supervised Fine-Tuning (SFT) notebook with a LoRA adapter using TRL. | ![]() |
| DPO (TRL) | Preference alignment with Direct Preference Optimization (DPO) using TRL. | ![]() |
@article{liquidai2025lfm2,
title={LFM2 Technical Report},
author={Liquid AI},
journal={arXiv preprint arXiv:2511.23404},
year={2025}
}