Instructions to use Qwen/Qwen2.5-0.5B-Instruct with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use Qwen/Qwen2.5-0.5B-Instruct with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="Qwen/Qwen2.5-0.5B-Instruct") messages = [ {"role": "user", "content": "Who are you?"}, ] pipe(messages)# Load model directly from transformers import AutoTokenizer, AutoModelForCausalLM tokenizer = AutoTokenizer.from_pretrained("Qwen/Qwen2.5-0.5B-Instruct") model = AutoModelForCausalLM.from_pretrained("Qwen/Qwen2.5-0.5B-Instruct", 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 Qwen/Qwen2.5-0.5B-Instruct with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "Qwen/Qwen2.5-0.5B-Instruct" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "Qwen/Qwen2.5-0.5B-Instruct", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker
docker model run hf.co/Qwen/Qwen2.5-0.5B-Instruct
- SGLang
How to use Qwen/Qwen2.5-0.5B-Instruct 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 "Qwen/Qwen2.5-0.5B-Instruct" \ --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": "Qwen/Qwen2.5-0.5B-Instruct", "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 "Qwen/Qwen2.5-0.5B-Instruct" \ --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": "Qwen/Qwen2.5-0.5B-Instruct", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }' - Docker Model Runner
How to use Qwen/Qwen2.5-0.5B-Instruct with Docker Model Runner:
docker model run hf.co/Qwen/Qwen2.5-0.5B-Instruct
Mechanistic interpretability study: executable replacement of all Qwen2.5-0.5B attention heads and MLPs
Hello Qwen team and community,
I am Maxim Zhivotok, an independent researcher from Ukraine. I have released a fully reproducible mechanistic interpretability study based directly on Qwen2.5-0.5B-Instruct:
“Executable Matrix Programs: Faithful Weight-Derived Replacement and Factorized Intervention in Pretrained Transformers.”
The method derives executable component-level matrix programs directly from the pretrained weights and reinserts them into the model’s native forward pass, without retraining the model or training a separate replacement network.
Main replacement results:
- all 336 attention heads replaced inside the native forward pass;
- all 24 SwiGLU MLP sublayers replaced;
- 0.258% median full-logit replacement discrepancy;
- 0.566% p95 discrepancy;
- 0.923% maximum discrepancy;
- 100% top-1 preservation across 64 prompts.
The work also provides:
- factorized QK routing and VO payload representations;
- native SwiGLU gate/read/write decomposition;
- factorized causal interventions;
- machine-readable attention, MLP, intervention, and downstream propagation results.
Preprint:
https://doi.org/10.5281/zenodo.21312311
Code and complete results:
https://github.com/maxwelhelp/matrix-programs
ORCID:
https://orcid.org/0009-0005-7722-6811
I would appreciate technical feedback from the Qwen team and community, particularly on:
- validation on larger Qwen2.5 or newer Qwen architectures;
- additional Qwen-specific benchmarks or prompt sets;
- the interpretation of the QK routing and VO payload factors;
- possible integration with existing Qwen analysis tooling.
Separately, this is my first arXiv cs.LG submission, and I am currently blocked by the endorsement requirement. If an eligible cs.LG endorser considers the public manuscript appropriate for the category after a brief look, I would be grateful if they could contact me privately.