Views
No views yet
| Precision | Size | Use Case |
|---|---|---|
| Q4F16 | ~4.7GB | Recommended (Q4 MoE + FP16 dense) |
| FP16 | ~15.8GB | Higher quality |
| Q4 | ~5.2GB | Smallest size |
| Q8 | ~30.4GB | Highest-fidelity quantized variant |
LiquidAI/LFM2.5-8B-A1B.1.0000 and top-5 overlap 5/5 at the last valid token for each row.0.7144.CPUExecutionProvider and matched the same decoder/coherence thresholds as Q4. Average coherence similarity: 0.7145.0.9975.onnx/
├── model.onnx # FP32 model graph
├── model.onnx_data* # FP32 weights
├── model_fp16.onnx # FP16 model graph
├── model_fp16.onnx_data* # FP16 weights
├── model_q4.onnx # Q4 model graph
├── model_q4.onnx_data* # Q4 weights
├── model_q4f16.onnx # Q4 MoE experts + FP16 dense (recommended)
├── model_q4f16.onnx_data* # Q4F16 weights
├── model_q8.onnx # Q8 model graph
└── model_q8.onnx_data* # Q8 weights
* Large models split weights across multiple files:
model.onnx_data, model.onnx_data_1, model.onnx_data_2, etc.
All data files must be in the same directory as the .onnx file.1pip install onnxruntime transformers numpy huggingface_hub
2# or with GPU support:
3pip install onnxruntime-gpu transformers numpy huggingface_hub1from huggingface_hub import snapshot_download
2from transformers import AutoConfig, AutoTokenizer
3import numpy as np
4import onnxruntime
5
6# 1. Load config, tokenizer, and model
7model_id = "LiquidAI/LFM2.5-8B-A1B-ONNX"
8config = AutoConfig.from_pretrained(model_id)
9tokenizer = AutoTokenizer.from_pretrained(model_id)
10eos_token_id = config.eos_token_id
11
12filename = "model_q4f16.onnx" # Options: model.onnx, model_fp16.onnx, model_q4.onnx, model_q4f16.onnx, model_q8.onnx
13model_path = snapshot_download(repo_id=model_id, allow_patterns=f"onnx/{filename}*")
14session = onnxruntime.InferenceSession(f"{model_path}/onnx/{filename}")
15input_names = {inp.name for inp in session.get_inputs()}
16
17# 2. Prepare inputs
18prompt = "What is C. elegans?"
19messages = [{"role": "user", "content": prompt}]
20inputs = tokenizer.apply_chat_template(
21 messages,
22 add_generation_prompt=True,
23 tokenize=True,
24 return_dict=True,
25 return_tensors="np",
26)
27input_ids = inputs["input_ids"]
28attention_mask = inputs["attention_mask"]
29batch_size = input_ids.shape[0]
30
31past_cache_values = {}
32for inp in session.get_inputs():
33 name = inp.name
34 shape = inp.shape
35 dtype = np.float32 if inp.type == "tensor(float)" else np.float16
36 if name.startswith("past_key_values"):
37 past_cache_values[name] = np.zeros([batch_size, shape[1], 0, shape[3]], dtype=dtype)
38 elif name.startswith("past_conv"):
39 past_cache_values[name] = np.zeros([batch_size, shape[1], shape[2]], dtype=dtype)
40
41position_ids = np.arange(input_ids.shape[1], dtype=np.int64).reshape(1, -1)
42
43# 3. Generation loop
44max_new_tokens = 256
45generated_tokens = np.array([[]], dtype=np.int64)
46cur_len = input_ids.shape[1]
47for i in range(max_new_tokens):
48 if i == 0:
49 ids = input_ids
50 pos = position_ids
51 else:
52 ids = generated_tokens[:, -1:]
53 pos = np.array([[cur_len - 1]], dtype=np.int64)
54
55 feed = {
56 "input_ids": ids,
57 "attention_mask": attention_mask,
58 **past_cache_values,
59 }
60 if "position_ids" in input_names:
61 feed["position_ids"] = pos
62
63 outputs = session.run(None, feed)
64 logits = outputs[0]
65 next_token = logits[:, -1].argmax(-1, keepdims=True)
66
67 generated_tokens = (
68 next_token if generated_tokens.shape[1] == 0
69 else np.concatenate([generated_tokens, next_token], axis=-1)
70 )
71 attention_mask = np.concatenate(
72 [attention_mask, np.ones_like(next_token, dtype=np.int64)],
73 axis=-1,
74 )
75
76 output_names = [out.name for out in session.get_outputs()]
77 cache_outputs = {
78 name: value
79 for name, value in zip(output_names[1:], outputs[1:])
80 }
81 for key in past_cache_values:
82 present_key = key.replace("past_key_values", "present").replace("past_conv", "present_conv")
83 past_cache_values[key] = cache_outputs[present_key]
84
85 cur_len += 1
86 if np.isin(next_token, eos_token_id).any():
87 break
88
89 print(tokenizer.decode(next_token[0]), end="", flush=True)
90print()
91
92# 4. Output result
93print(tokenizer.batch_decode(generated_tokens, skip_special_tokens=True)[0])