Instructions to use Nanbeige/Nanbeige4.1-3B with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use Nanbeige/Nanbeige4.1-3B with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="Nanbeige/Nanbeige4.1-3B") messages = [ {"role": "user", "content": "Who are you?"}, ] pipe(messages)# Load model directly from transformers import AutoTokenizer, AutoModelForCausalLM tokenizer = AutoTokenizer.from_pretrained("Nanbeige/Nanbeige4.1-3B") model = AutoModelForCausalLM.from_pretrained("Nanbeige/Nanbeige4.1-3B", 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]:])) - Inference
- Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use Nanbeige/Nanbeige4.1-3B with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "Nanbeige/Nanbeige4.1-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.1-3B", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker
docker model run hf.co/Nanbeige/Nanbeige4.1-3B
- SGLang
How to use Nanbeige/Nanbeige4.1-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.1-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.1-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.1-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.1-3B", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }' - Docker Model Runner
How to use Nanbeige/Nanbeige4.1-3B with Docker Model Runner:
docker model run hf.co/Nanbeige/Nanbeige4.1-3B
What should Top-k be set to?
I was looking at the discussion here huggingface.co/Nanbeige/Nanbeige4.1-3B/discussions/2, and the conclusion seems to be either 0 or 50.
The discussion mentions that 50 is likely used because the official example utilizes the transformers defaults. However, since that example didn't set Temperature or Top-p either, it doesn't seem very convincing/conclusive.
So, what is the recommended value for Top-k? Thanks.
After testing it for a while on same promts, i assume the best settings are --temp 0.6 --top-p 0.95 --top-k 40 --min-p 0.01
Just by looking at output quality...
Setting top_k to 0 indeed shortens the thought chain. I might personally find 0 to be better.
I searched some guides, such as llm-sampling-parameters-guide, and found that top_k should be set to 0 by default, unless there are specific requirements. Min_p is also an issue; I've temporarily set it to 0, which is also the default value in Ollama.
My parameters are not meant to shorten COT, i just compared outputs. I'll try your suggestion (minp, topp), but after doing many comparisons, i doubt it will be better.
For example with my parameters, it created perfectly working and good looking snake game in html. Neon design, score, "play again" button.
My parameters are not meant to shorten COT, i just compared outputs. I'll try your suggestion (minp, topp), but after doing many comparisons, i doubt it will be better.
For example with my parameters, it created perfectly working and good looking snake game in html. Neon design, score, "play again" button.
Could you share your test cases publicly? I assumed that tweaking these wouldn't significantly impact intelligence, at least not in terms of benchmark results like MMLU.
Perhaps min_p should indeed be set to 0.01, and now I completely agree with this. Thanks.