Instructions to use Qwen/Qwen3.5-2B with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use Qwen/Qwen3.5-2B with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("image-text-to-text", model="Qwen/Qwen3.5-2B") messages = [ { "role": "user", "content": [ {"type": "image", "url": "https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/p-blog/candy.JPG"}, {"type": "text", "text": "What animal is on the candy?"} ] }, ] pipe(text=messages)# Load model directly from transformers import AutoProcessor, AutoModelForImageTextToText processor = AutoProcessor.from_pretrained("Qwen/Qwen3.5-2B") model = AutoModelForImageTextToText.from_pretrained("Qwen/Qwen3.5-2B") messages = [ { "role": "user", "content": [ {"type": "image", "url": "https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/p-blog/candy.JPG"}, {"type": "text", "text": "What animal is on the candy?"} ] }, ] inputs = processor.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(processor.decode(outputs[0][inputs["input_ids"].shape[-1]:])) - Inference
- Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use Qwen/Qwen3.5-2B with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "Qwen/Qwen3.5-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": "Qwen/Qwen3.5-2B", "messages": [ { "role": "user", "content": [ { "type": "text", "text": "Describe this image in one sentence." }, { "type": "image_url", "image_url": { "url": "https://cdn.britannica.com/61/93061-050-99147DCE/Statue-of-Liberty-Island-New-York-Bay.jpg" } } ] } ] }'Use Docker
docker model run hf.co/Qwen/Qwen3.5-2B
- SGLang
How to use Qwen/Qwen3.5-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 "Qwen/Qwen3.5-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": "Qwen/Qwen3.5-2B", "messages": [ { "role": "user", "content": [ { "type": "text", "text": "Describe this image in one sentence." }, { "type": "image_url", "image_url": { "url": "https://cdn.britannica.com/61/93061-050-99147DCE/Statue-of-Liberty-Island-New-York-Bay.jpg" } } ] } ] }'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/Qwen3.5-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": "Qwen/Qwen3.5-2B", "messages": [ { "role": "user", "content": [ { "type": "text", "text": "Describe this image in one sentence." }, { "type": "image_url", "image_url": { "url": "https://cdn.britannica.com/61/93061-050-99147DCE/Statue-of-Liberty-Island-New-York-Bay.jpg" } } ] } ] }' - Docker Model Runner
How to use Qwen/Qwen3.5-2B with Docker Model Runner:
docker model run hf.co/Qwen/Qwen3.5-2B
fix chat template to avoid empty historical `<think>` blocks
This fixes a chat template issue where historical assistant turns can emit empty <think>...</think> blocks even when reasoning_content is empty.
That matters because these empty historical <think> blocks change the serialized prompt without adding any useful information.
The fix is a really simple one-line change in the template:
from:
{%- if loop.index0 > ns.last_query_index %}
to:
{%- if loop.index0 > ns.last_query_index and reasoning_content %}
Why this is important:
- it reduces unnecessary prompt drift
- it improves prefix-cache reuse
- it helps avoid avoidable cache misses
- it reduces extra token processing caused by equivalent histories rendering differently
In practice, this means less wasted compute and better cache stability, especially in longer multi-turn or tool-using conversations.
The change is intentionally minimal:
- keep the historical
<think>wrapper whenreasoning_contentis actually present - do not emit an empty
<think>block when there is no reasoning content
Without this guard, the template can produce prior turns like:
assistant
<think>
</think>
<tool_call>...
instead of rendering just the assistant content or tool call directly.
So this change preserves real reasoning content while avoiding empty reasoning scaffolding that can hurt caching behavior.
Edit: made a video explaining the bug
https://www.youtube.com/watch?v=3g70-ToSgr0
small update after more testing: i tried the stricter version that removes historical <think> blocks entirely, but i think that one is too aggressive.
it seems better for cache reuse, but it may affect reasoning behavior / separation in some cases.
so i’m reverting these prs back to the safer minimal fix:
{%- if loop.index0 > ns.last_query_index and reasoning_content %}
that still fixes the empty historical wrapper issue without changing historical turns as aggressively.