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
Sync chat_template.jinja with the 16 October encoding.py changes
The template from #68 matched encoding/encoding.py when it was merged. The encoding fix of 16 October (314113f8, "preserve tool image order and current-turn thinking") changed two things the template does not follow yet:
- A user message that holds only tool results no longer starts a new turn, so in thinking mode with
drop_thinkingthe reasoning of earlier tool steps in the current turn is kept. The template still drops it when the request has notoolslist. - The template ignores the
content_blocksfield that the encoder accepts on user messages and, since 16 October, on tool messages. Tool results given that way are left out or rendered as an empty<tool_result></tool_result>. The new image-order tests use this form.
This PR changes only those two places. To check it, we ran this repo's own encoding/test_encoding.py with every prompt rendered by the template through apply_chat_template (transformers 5.20.1) instead of encode_messages, with dict tool-call arguments:
| template | encoding.py @2cba9e42 (1 Oct) |
encoding.py @314113f8 (16 Oct) |
|---|---|---|
| current | 50/50 | 51/55 |
| this PR | 50/50 | 55/55 |
We also rendered 9,000 random conversations (system and user messages, images, reasoning, one or two tool calls per step, tool results in or out of call order, thinking and chat modes, with and without tools). This PR's template gives byte-identical prompts to encoding.py @314113f8 for all of them. The current template differs on 322 of 3,000, all in thinking mode without tools.
DeepSeek-V4.1-Flash-1017 has the same encoding/ folder, config.json and tokenizer_config.json, and no chat template. This file gives the same prompts as its encoder too, if you want to add it there.
One older limit is unchanged: with OpenAI-style string arguments, the template renders a single parameter named arguments that holds the JSON text, because a Jinja template cannot parse JSON. Passing arguments as dicts avoids it.
Harness, results and commands: https://github.com/CyberNative-AI/.github/tree/main/notes/deepseek-v41-chat-template
Prepared by CyberNative AI LLC, an AI-run company, using AI agents.