Instructions to use openbmb/MiniCPM5-2B with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use openbmb/MiniCPM5-2B with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="openbmb/MiniCPM5-2B") messages = [ {"role": "user", "content": "Who are you?"}, ] pipe(messages)# Load model directly from transformers import AutoTokenizer, AutoModelForCausalLM tokenizer = AutoTokenizer.from_pretrained("openbmb/MiniCPM5-2B") model = AutoModelForCausalLM.from_pretrained("openbmb/MiniCPM5-2B", 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 openbmb/MiniCPM5-2B with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "openbmb/MiniCPM5-2B" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "openbmb/MiniCPM5-2B", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker
docker model run hf.co/openbmb/MiniCPM5-2B
- SGLang
How to use openbmb/MiniCPM5-2B 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 "openbmb/MiniCPM5-2B" \ --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": "openbmb/MiniCPM5-2B", "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 "openbmb/MiniCPM5-2B" \ --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": "openbmb/MiniCPM5-2B", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }' - Docker Model Runner
How to use openbmb/MiniCPM5-2B with Docker Model Runner:
docker model run hf.co/openbmb/MiniCPM5-2B
RFC: MiniCPM5-2B-Hadamard-GSQ (DV-SSQ & KV-BSS Edge Quantization)
RFC: MiniCPM5-2B-Hadamard-GSQ (DV-SSQ & KV-BSS Architecture)
Greetings OpenBMB Team and Community,
We would like to share an architectural proposal and open-source release: MiniCPM5-2B-Hadamard-GSQ, engineered at F-Labs.
- Model Weights & Metadata: F-Labs/MiniCPM5-2B-Hadamard-GSQ
- Source Code & Modules: GitHub: dsadawq3/MiniCPM5-2B-Hadamard-GSQ
- Framework Core: GitHub: dsadawq3/FQuant
Motivation & Challenges in 4-bit Edge Inference
MiniCPM5-2B is inherently designed for edge and on-device execution with deep 42-layer transformer reasoning and a massive 131,072 token (128K) context window. However, running uncompressed BF16 requires 4.69 GB of physical memory, creating heavy pressure on 4GB-6GB edge devices.
Standard post-training quantization methods (naive INT4 or uniform RTN) suffer from three primary degradation modes across 42 sequential layers:
- Activation Outlier Spikes: Coordinate-aligned outliers in hidden channels (d = 2048) induce severe clipping errors.
- GQA 8:1 Attention Fragility: With only 2 Key-Value heads per layer, any perturbation in
k_projcorrupts 50% of the layer's associative memory due to exponential amplification in exp(Q · Kᵀ / √d). - 128K Context Attention Haze: In long contexts, Softmax probability mass diffuses across thousands of irrelevant background tokens, leading to entity and key-value hallucinations (
["key"] => "value").
Key Architectural Solutions
Walsh-Hadamard (H₁₂₈ / H₂₀₄₈) Spin Rotation:
Because hidden_size is exactly 2048 (2¹¹), we apply orthonormal Sylvester Walsh-Hadamard rotation matrices:
W' = W · Hᵀ, X' = X · H
This algebraically preserves linear outputs (X' W'ᵀ = X Wᵀ) while rotating coordinates to suppress activation outlier peaks by over 82%.Group-Scale INT4 (GSQ) + Residual SVD Compensation (RCO):
- MLP parameter mass (67.4% of model weight) is quantized to INT4 (group size G = 64).
- Residual discretization error R = W - Ŵ is decomposed via truncated Low-Rank SVD:
R ≈ U_r · Σ_r · V_rᵀ = A · B
Stored in BF16 factor matrices (r = 16on standard layers,r = 24on bifurcation abstraction hubs).
Key-Projection Exponential Sensitivity Defense:
All 42k_projmatrices are fortified with doubled SVD rank (r = 32). Because totalk_projweights across all layers amount to only ~44 MB (<0.9% of the model), allocating extra low-rank capacity costs negligible RAM while completely preserving attention stability.Zero-Compression Shield:
All 85 RMSNorm weight vectors, projection biases, and token embeddings remain in 100% pristine BF16, eliminating cumulative phase drift across all 42 layers.KV-BSS (Key-Value Binding Softmax Sharpening):
An attention hook implementing focus temperature scaling (τ_focus = 1.10) and dynamic attention haze floor filtering (< max - 12.0), preventing hallucination on structured associative recall in 128k contexts.
Empirical Summary
| Metric | Base Model (BF16) | MiniCPM5-2B-Hadamard-GSQ | Significance |
|---|---|---|---|
| Total Memory Footprint | 4.69 GB | 2.22 GB | -52.7% Physical RAM Saved |
| Effective Bitrate | 16.00 bpp | ~4.20 bpp | Sub-3GB Edge Execution Viable |
| RMSNorm & Bias Drift | Baseline | 0.000% | Pristine BF16 Shield |
| GQA KV Attention Head Drift | Baseline | < 0.8% | Fortified via r = 32 SVD |
| Context Window | 128K Tokens | 128K Tokens | Fully Preserved |
We invite feedback and collaboration from the OpenBMB engineering team.