Image-Text-to-Text
Transformers
Safetensors
deepseek_v41
text-generation
conversational
Eval Results
8-bit precision
fp8
Instructions to use deepseek-ai/DeepSeek-V4.1-Flash with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use deepseek-ai/DeepSeek-V4.1-Flash with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("image-text-to-text", model="deepseek-ai/DeepSeek-V4.1-Flash") 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)# pip install -U transformers accelerate # Load model directly from transformers import AutoModelForCausalLM model = AutoModelForCausalLM.from_pretrained("deepseek-ai/DeepSeek-V4.1-Flash", device_map="auto") - Inference
- HuggingChat
- Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use deepseek-ai/DeepSeek-V4.1-Flash with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "deepseek-ai/DeepSeek-V4.1-Flash" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "deepseek-ai/DeepSeek-V4.1-Flash", "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/deepseek-ai/DeepSeek-V4.1-Flash
- SGLang
How to use deepseek-ai/DeepSeek-V4.1-Flash 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 "deepseek-ai/DeepSeek-V4.1-Flash" \ --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": "deepseek-ai/DeepSeek-V4.1-Flash", "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 "deepseek-ai/DeepSeek-V4.1-Flash" \ --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": "deepseek-ai/DeepSeek-V4.1-Flash", "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 deepseek-ai/DeepSeek-V4.1-Flash with Docker Model Runner:
docker model run hf.co/deepseek-ai/DeepSeek-V4.1-Flash
CyberNative AI LLC commited on
Commit ·
cb16fdf
1
Parent(s): 314113f
Sync chat_template.jinja with the 16 October encoding.py changes
Browse files- chat_template.jinja +17 -3
chat_template.jinja
CHANGED
|
@@ -1,4 +1,4 @@
|
|
| 1 |
-
{#- DeepSeek-V4.1 chat template, ported from encoding/encoding.py in the model repo.
|
| 2 |
Extra kwargs: thinking_mode ("thinking" | "chat", default "thinking"; enable_thinking=true/false is accepted
|
| 3 |
as an alias), drop_thinking (default true), reasoning_effort (int in [1, 100] or "low"/"medium"/"high"/"max",
|
| 4 |
default "high"). Assistant reasoning is read from reasoning_content, or from thinking as an alias. -#}
|
|
@@ -75,6 +75,11 @@
|
|
| 75 |
{%- set mns = namespace(list=[]) -%}
|
| 76 |
{%- for msg in messages -%}
|
| 77 |
{%- set content = msg.get("content") -%}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 78 |
{%- set is_blocks = content is iterable and content is not string and content is not mapping -%}
|
| 79 |
{%- if content is string and IMG in content -%}
|
| 80 |
{{- raise_exception("Message content contains image special token " ~ IMG ~ ". Images should be provided as image content blocks.") -}}
|
|
@@ -151,10 +156,19 @@
|
|
| 151 |
{%- endfor -%}
|
| 152 |
{%- set msgs = sns.list -%}
|
| 153 |
|
| 154 |
-
{#- Mid-conversation system messages count as user turns
|
|
|
|
| 155 |
{%- set state = namespace(last_user=-1, has_tools=false) -%}
|
| 156 |
{%- for m in msgs -%}
|
| 157 |
-
{%-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 158 |
{%- if m.get("tools") -%}{%- set state.has_tools = true -%}{%- endif -%}
|
| 159 |
{%- endfor -%}
|
| 160 |
{%- set effective_drop = drop_thinking and not state.has_tools -%}
|
|
|
|
| 1 |
+
{#- DeepSeek-V4.1 chat template, ported from encoding/encoding.py in the model repo (synced with its 2026-10-16 revision).
|
| 2 |
Extra kwargs: thinking_mode ("thinking" | "chat", default "thinking"; enable_thinking=true/false is accepted
|
| 3 |
as an alias), drop_thinking (default true), reasoning_effort (int in [1, 100] or "low"/"medium"/"high"/"max",
|
| 4 |
default "high"). Assistant reasoning is read from reasoning_content, or from thinking as an alias. -#}
|
|
|
|
| 75 |
{%- set mns = namespace(list=[]) -%}
|
| 76 |
{%- for msg in messages -%}
|
| 77 |
{%- set content = msg.get("content") -%}
|
| 78 |
+
{%- if msg.role == "user" and msg.get("content_blocks") is not none -%}
|
| 79 |
+
{%- set content = msg.content_blocks -%}
|
| 80 |
+
{%- elif msg.role == "tool" and msg.get("content_blocks") and content is not string -%}
|
| 81 |
+
{%- set content = msg.content_blocks -%}
|
| 82 |
+
{%- endif -%}
|
| 83 |
{%- set is_blocks = content is iterable and content is not string and content is not mapping -%}
|
| 84 |
{%- if content is string and IMG in content -%}
|
| 85 |
{{- raise_exception("Message content contains image special token " ~ IMG ~ ". Images should be provided as image content blocks.") -}}
|
|
|
|
| 156 |
{%- endfor -%}
|
| 157 |
{%- set msgs = sns.list -%}
|
| 158 |
|
| 159 |
+
{#- Mid-conversation system messages count as user turns; user messages holding only tool results do not.
|
| 160 |
+
Tools anywhere disable drop_thinking. -#}
|
| 161 |
{%- set state = namespace(last_user=-1, has_tools=false) -%}
|
| 162 |
{%- for m in msgs -%}
|
| 163 |
+
{%- set starts_turn = (m.role == "system" and loop.index0 > 0) -%}
|
| 164 |
+
{%- if m.role == "user" -%}
|
| 165 |
+
{%- set turn = namespace(found=not m.content_blocks) -%}
|
| 166 |
+
{%- for b in m.content_blocks or [] -%}
|
| 167 |
+
{%- if b.type in ["text", "image", "image_url"] -%}{%- set turn.found = true -%}{%- endif -%}
|
| 168 |
+
{%- endfor -%}
|
| 169 |
+
{%- set starts_turn = turn.found -%}
|
| 170 |
+
{%- endif -%}
|
| 171 |
+
{%- if starts_turn -%}{%- set state.last_user = loop.index0 -%}{%- endif -%}
|
| 172 |
{%- if m.get("tools") -%}{%- set state.has_tools = true -%}{%- endif -%}
|
| 173 |
{%- endfor -%}
|
| 174 |
{%- set effective_drop = drop_thinking and not state.has_tools -%}
|