Instructions to use Nanbeige/Nanbeige4.2-3B with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use Nanbeige/Nanbeige4.2-3B with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="Nanbeige/Nanbeige4.2-3B", trust_remote_code=True) messages = [ {"role": "user", "content": "Who are you?"}, ] pipe(messages)# Load model directly from transformers import AutoModelForCausalLM model = AutoModelForCausalLM.from_pretrained("Nanbeige/Nanbeige4.2-3B", trust_remote_code=True, device_map="auto") - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use Nanbeige/Nanbeige4.2-3B with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "Nanbeige/Nanbeige4.2-3B" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "Nanbeige/Nanbeige4.2-3B", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker
docker model run hf.co/Nanbeige/Nanbeige4.2-3B
- SGLang
How to use Nanbeige/Nanbeige4.2-3B 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 "Nanbeige/Nanbeige4.2-3B" \ --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": "Nanbeige/Nanbeige4.2-3B", "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 "Nanbeige/Nanbeige4.2-3B" \ --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": "Nanbeige/Nanbeige4.2-3B", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }' - Docker Model Runner
How to use Nanbeige/Nanbeige4.2-3B with Docker Model Runner:
docker model run hf.co/Nanbeige/Nanbeige4.2-3B
Nanbeige4.2-3B: A Small Model That Demands Serious Hardware
"Nanbeige4.2-3B" (https://huggingface.co/Nanbeige/Nanbeige4.2-3B) is a compact reasoning and agentic language model with roughly 4 billion total parameters, including 3 billion non-embedding parameters. It uses a Looped Transformer architecture that reuses layers to increase effective model capacity without increasing the parameter count. The developers report unusually strong results in mathematical reasoning, coding, and agentic tasks for a model of this size. That makes it worth testing, particularly for people interested in whether smaller models can perform useful work instead of merely generating fluent text.
My first attempt was to run the model in a CPU-based Hugging Face Space. Although the model is relatively small, the deployment did not produce reliable inference. It encountered software dependency problems, and one attempted configuration generated gibberish. The difficulty was not simply downloading the model. Nanbeige4.2 uses custom architecture code and depends on a very specific combination of Python, PyTorch, Transformers, CUDA, and FlashAttention. A seemingly minor version mismatch could allow the weights to load while breaking generation or producing other failures.
The model finally ran correctly in a Google Colab Pro notebook using an NVIDIA L4 GPU. The working configuration used Python 3.11.15 in an isolated virtual environment, PyTorch 2.8.0 with CUDA 12.8, Transformers 4.42.4, FlashAttention 2.8.3, Accelerate 1.14.0, SentencePiece 0.2.2, NumPy 1.26.4, and Protobuf 7.35.1. The L4 provided approximately 22 GB of usable GPU memory. The model’s BF16 weights occupied about 8.34 GB and loaded completely onto the GPU.
Once the environment was correct, plain GPU inference worked cleanly using the developer’s official "apply_chat_template()" and "model.generate()" workflow. Nanbeige correctly answered the decimal comparison between 9.11 and 9.8. It then solved a first-order linear differential equation and correctly obtained the exact solution, including verification by substitution and the initial condition.
The next test was a college-level second-order differential equation with resonance. For the problem y''-3y'+2y=e^x, with y(0)=1 and y'(0)=0, the model correctly derived the complementary solution, recognized the resonance, found the appropriate particular solution, applied both initial conditions, and reached the correct result:
[
y(x)=(1-x)e^x.
]
A harder Cauchy–Euler problem exposed the model’s limit. After substituting t=\ln x, it dropped a factor of t from the transformed forcing term. That single error corrupted the particular solution and final answer. The model therefore passed the simple and standard college-level differential-equation tests but failed the more demanding transformation-and-resonance problem.
The result is encouraging but also realistic. Nanbeige4.2-3B is much more capable than many small models I have tested, and it can produce coherent, well-structured mathematical work when the problem is within its range. But it is not reliably correct on harder mathematics, even when its explanation appears polished. Its answers still require independent verification. The model is worth exploring because it pushes useful reasoning into a relatively compact size—but getting there requires a carefully matched GPU environment, and small size should not be confused with effortless deployment.
The Google colab notebook
https://colab.research.google.com/drive/105mONlcWDYEgUbK8YeqaPFAhbDVoW7is?usp=sharing
Interesting, never thought about using it for math.
But for some reason my brain has thrown a question into my mind, would it be capable to do it through the programming language.
It was specifically trained to be good at coding, therefore it may have improved capabilities to solve such equations using a programing language (requires a basic toolset). This may be worth trying.
But still, your tests demonstrate its plain math capabilities which is useful.


