Instructions to use Qwen/Qwen3.8-27B with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use Qwen/Qwen3.8-27B with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("image-text-to-text", model="Qwen/Qwen3.8-27B") 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, AutoModelForMultimodalLM processor = AutoProcessor.from_pretrained("Qwen/Qwen3.8-27B") model = AutoModelForMultimodalLM.from_pretrained("Qwen/Qwen3.8-27B", device_map="auto") 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.8-27B with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "Qwen/Qwen3.8-27B" # 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.8-27B", "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.8-27B
- SGLang
How to use Qwen/Qwen3.8-27B 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.8-27B" \ --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.8-27B", "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.8-27B" \ --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.8-27B", "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.8-27B with Docker Model Runner:
docker model run hf.co/Qwen/Qwen3.8-27B
Upload chat_template.jinja with huggingface_hub
Browse files- chat_template.jinja +24 -33
chat_template.jinja
CHANGED
|
@@ -27,11 +27,6 @@
|
|
| 27 |
{{- 'Video ' ~ video_count.value ~ ': ' }}
|
| 28 |
{%- endif %}
|
| 29 |
{{- '<|vision_start|><|video_pad|><|vision_end|>' }}
|
| 30 |
-
{%- elif 'audio' in item or item.type == 'audio' %}
|
| 31 |
-
{%- if is_system_content %}
|
| 32 |
-
{{- raise_exception('System message cannot contain audio.') }}
|
| 33 |
-
{%- endif %}
|
| 34 |
-
{{- '<|audio_start|><|audio_pad|><|audio_end|>' }}
|
| 35 |
{%- elif 'text' in item %}
|
| 36 |
{{- item.text }}
|
| 37 |
{%- else %}
|
|
@@ -44,29 +39,26 @@
|
|
| 44 |
{{- raise_exception('Unexpected content type.') }}
|
| 45 |
{%- endif %}
|
| 46 |
{%- endmacro %}
|
| 47 |
-
{#- Dynamic reasoning_effort (low/high/xhigh): low & xhigh inject a system directive line; high or unset = no injection (== high). #}
|
| 48 |
-
{%- if reasoning_effort is defined and reasoning_effort is not none %}
|
| 49 |
-
{%- if reasoning_effort not in ['low', 'high', 'xhigh'] %}
|
| 50 |
-
{{- raise_exception('Unknown reasoning_effort: ' + reasoning_effort|string + '. Expected one of: low, high, xhigh.') }}
|
| 51 |
-
{%- endif %}
|
| 52 |
-
{%- endif %}
|
| 53 |
-
{%- set add_reasoning = reasoning_effort is defined and reasoning_effort is not none and reasoning_effort in ['low', 'xhigh'] %}
|
| 54 |
-
{%- if add_reasoning %}
|
| 55 |
-
{%- if reasoning_effort == 'low' %}
|
| 56 |
-
{%- set reasoning_line = 'Reasoning effort is set to low. Keep your thinking brief and focused, moving directly to the conclusion without unnecessary elaboration.' %}
|
| 57 |
-
{%- elif reasoning_effort == 'xhigh' %}
|
| 58 |
-
{%- set reasoning_line = 'Reasoning effort is set to xhigh. Please think carefully through the task, validate key assumptions, consider plausible alternatives, and prioritize correctness, consistency, and clarity in the final answer.' %}
|
| 59 |
-
{%- endif %}
|
| 60 |
-
{%- set reasoning_prefix = reasoning_line + '\n\n' %}
|
| 61 |
-
{%- else %}
|
| 62 |
-
{%- set reasoning_prefix = '' %}
|
| 63 |
-
{%- endif %}
|
| 64 |
{%- if not messages %}
|
| 65 |
{{- raise_exception('No messages provided.') }}
|
| 66 |
{%- endif %}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 67 |
{%- if tools and tools is iterable and tools is not mapping %}
|
| 68 |
{{- '<|im_start|>system\n' }}
|
| 69 |
-
{
|
|
|
|
|
|
|
| 70 |
{{- "# Tools\n\nYou have access to the following functions:\n\n<tools>" }}
|
| 71 |
{%- for tool in tools %}
|
| 72 |
{{- "\n" }}
|
|
@@ -84,9 +76,13 @@
|
|
| 84 |
{%- else %}
|
| 85 |
{%- if messages[0].role == 'system' %}
|
| 86 |
{%- set content = render_content(messages[0].content, false, true)|trim %}
|
| 87 |
-
{
|
| 88 |
-
|
| 89 |
-
{
|
|
|
|
|
|
|
|
|
|
|
|
|
| 90 |
{%- endif %}
|
| 91 |
{%- endif %}
|
| 92 |
{%- set ns = namespace(multi_step_tool=true, last_query_index=messages|length - 1) %}
|
|
@@ -115,14 +111,9 @@
|
|
| 115 |
{%- set reasoning_content = '' %}
|
| 116 |
{%- if message.reasoning_content is string %}
|
| 117 |
{%- set reasoning_content = message.reasoning_content %}
|
| 118 |
-
{%- else %}
|
| 119 |
-
{%- if '</think>' in content %}
|
| 120 |
-
{%- set reasoning_content = content.split('</think>')[0].rstrip('\n').split('<think>')[-1].lstrip('\n') %}
|
| 121 |
-
{%- set content = content.split('</think>')[-1].lstrip('\n') %}
|
| 122 |
-
{%- endif %}
|
| 123 |
{%- endif %}
|
| 124 |
{%- set reasoning_content = reasoning_content|trim %}
|
| 125 |
-
{%- if
|
| 126 |
{{- '<|im_start|>' + message.role + '\n<think>\n' + reasoning_content + '\n</think>\n\n' + content }}
|
| 127 |
{%- else %}
|
| 128 |
{{- '<|im_start|>' + message.role + '\n' + content }}
|
|
@@ -141,7 +132,7 @@
|
|
| 141 |
{%- else %}
|
| 142 |
{{- '\n<tool_call>\n<function=' + tool_call.name + '>\n' }}
|
| 143 |
{%- endif %}
|
| 144 |
-
{%- if tool_call.arguments is defined %}
|
| 145 |
{%- for args_name, args_value in tool_call.arguments|items %}
|
| 146 |
{{- '<parameter=' + args_name + '>\n' }}
|
| 147 |
{%- set args_value = args_value | string if args_value is string else args_value | tojson | safe %}
|
|
|
|
| 27 |
{{- 'Video ' ~ video_count.value ~ ': ' }}
|
| 28 |
{%- endif %}
|
| 29 |
{{- '<|vision_start|><|video_pad|><|vision_end|>' }}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 30 |
{%- elif 'text' in item %}
|
| 31 |
{{- item.text }}
|
| 32 |
{%- else %}
|
|
|
|
| 39 |
{{- raise_exception('Unexpected content type.') }}
|
| 40 |
{%- endif %}
|
| 41 |
{%- endmacro %}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 42 |
{%- if not messages %}
|
| 43 |
{{- raise_exception('No messages provided.') }}
|
| 44 |
{%- endif %}
|
| 45 |
+
{%- set reasoning_instructions = '' %}
|
| 46 |
+
{%- if enable_thinking is undefined or enable_thinking is true %}
|
| 47 |
+
{%- set resolved_reasoning_effort = reasoning_effort|default('xhigh') %}
|
| 48 |
+
{%- if resolved_reasoning_effort not in ('xhigh', 'medium', 'low') %}
|
| 49 |
+
{{- raise_exception('Unexpected reasoning effort ' ~ reasoning_effort ~ '. Supported types are xhigh (default), medium, and low.') }}
|
| 50 |
+
{%- endif %}
|
| 51 |
+
{%- if resolved_reasoning_effort == 'xhigh' %}
|
| 52 |
+
{%- set reasoning_instructions = 'Reasoning effort is set to xhigh. Please think carefully through the task, validate key assumptions, consider plausible alternatives, and prioritize correctness, consistency, and clarity in the final answer.' %}
|
| 53 |
+
{%- elif resolved_reasoning_effort == 'low' %}
|
| 54 |
+
{%- set reasoning_instructions = 'Reasoning effort is set to low. Keep your thinking brief and focused, moving directly to the conclusion without unnecessary elaboration.' %}
|
| 55 |
+
{%- endif %}
|
| 56 |
+
{%- endif %}
|
| 57 |
{%- if tools and tools is iterable and tools is not mapping %}
|
| 58 |
{{- '<|im_start|>system\n' }}
|
| 59 |
+
{%- if reasoning_instructions %}
|
| 60 |
+
{{- reasoning_instructions + '\n\n' }}
|
| 61 |
+
{%- endif %}
|
| 62 |
{{- "# Tools\n\nYou have access to the following functions:\n\n<tools>" }}
|
| 63 |
{%- for tool in tools %}
|
| 64 |
{{- "\n" }}
|
|
|
|
| 76 |
{%- else %}
|
| 77 |
{%- if messages[0].role == 'system' %}
|
| 78 |
{%- set content = render_content(messages[0].content, false, true)|trim %}
|
| 79 |
+
{%- if content %}
|
| 80 |
+
{{- '<|im_start|>system\n' + (reasoning_instructions + '\n\n' if reasoning_instructions else '') + content + '<|im_end|>\n' }}
|
| 81 |
+
{%- elif reasoning_instructions %}
|
| 82 |
+
{{- '<|im_start|>system\n' + reasoning_instructions + '<|im_end|>\n' }}
|
| 83 |
+
{%- endif %}
|
| 84 |
+
{%- elif reasoning_instructions %}
|
| 85 |
+
{{- '<|im_start|>system\n' + reasoning_instructions + '<|im_end|>\n' }}
|
| 86 |
{%- endif %}
|
| 87 |
{%- endif %}
|
| 88 |
{%- set ns = namespace(multi_step_tool=true, last_query_index=messages|length - 1) %}
|
|
|
|
| 111 |
{%- set reasoning_content = '' %}
|
| 112 |
{%- if message.reasoning_content is string %}
|
| 113 |
{%- set reasoning_content = message.reasoning_content %}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 114 |
{%- endif %}
|
| 115 |
{%- set reasoning_content = reasoning_content|trim %}
|
| 116 |
+
{%- if preserve_thinking is undefined or preserve_thinking is true or loop.index0 > ns.last_query_index %}
|
| 117 |
{{- '<|im_start|>' + message.role + '\n<think>\n' + reasoning_content + '\n</think>\n\n' + content }}
|
| 118 |
{%- else %}
|
| 119 |
{{- '<|im_start|>' + message.role + '\n' + content }}
|
|
|
|
| 132 |
{%- else %}
|
| 133 |
{{- '\n<tool_call>\n<function=' + tool_call.name + '>\n' }}
|
| 134 |
{%- endif %}
|
| 135 |
+
{%- if tool_call.arguments is defined and tool_call.arguments != '' %}
|
| 136 |
{%- for args_name, args_value in tool_call.arguments|items %}
|
| 137 |
{{- '<parameter=' + args_name + '>\n' }}
|
| 138 |
{%- set args_value = args_value | string if args_value is string else args_value | tojson | safe %}
|