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
Independent CPU decode/prefill regression evidence for the index_k fix in PR #12
Independent reproduction supporting PR #12
This reports additional end-to-end CPU evidence for the cache-ownership fix already submitted by @ZenAlexa in PR #12. Please use that PR for the code change; I am not proposing a duplicate.
Cause and scope
In inference/model.py, Indexer.forward publishes shared_attn.index_k inside if self.owns_k and latent is not None. On an incomplete compression group the source does not republish its cache, but the same forward still reads shared_attn.index_k. That slot can contain a later source's cache left over from the previous forward.
This breaks SharedAttentionRuntime's documented invariant that every source writes before its consumers read. Attention._compress_kv already republishes shared_attn.compress_kv on every source call, independently of whether a group completes.
The released configuration has KV sources [2, 8, 14, 20]: layers 2/8/14 have compression ratio 2; layer 20 has ratio 1 and publishes last. The ownership hazard therefore exists in the released schedule too. The numerical measurements below use reduced random-weight models, not the released 510 GB checkpoint; they do not quantify real-checkpoint quality loss.
Measurement: reference model versus itself
For each absolute position 200 through 223, compare:
- Prefill 200 tokens, then incremental one-token decode.
- A one-shot prefill of the identical token prefix ending at that position.
Both paths use the same reference-model source and identically initialized weights. This is CPU with local PyTorch replacements for the TileLang kernels, not a run of the official GPU kernels. The supplied CPU shim is used on both sides; activation fake quantization remains enabled. No Transformers model implementation or downloaded model weights participate.
Configuration: five layers, FP32 parameters, batch 2, max_seq_len=256, compress_ratios=(0,2,2,1,1), KV/index sources (1,3), index_topk=64, no Engram, vision, MTP or candidate prefilter. Sources are pinned to dba1be0a40aa45a94ad051997016db3960a90277.
| Reference code | Max absolute logit difference, all 24 decode positions | Argmax agreement (48 batch-position comparisons) |
|---|---|---|
| Unmodified | 1.991 | 70.83% (34/48) |
| With the same cache-publication fix as PR #12 | 4.029e-5 | 100% (48/48) |
For example, unmodified differences at positions 200–207 were 1.2, 0.021, 0.39, 0.020, 0.31, 0.031, 0.53, 0.044. The direct ownership violation occurs at incomplete-group steps (even positions for ratio 2). Its downstream effects can persist into subsequent positions; divergence is not confined exclusively to those steps.
The 128-token onset in this reduced setup should not be treated as a universal sliding-window threshold: index_topk=64 and ratio 2 also make 128 tokens the point after which selecting among more than 64 completed groups becomes relevant. The released model uses different indexer budgets.
Reproduction
Runnable scripts and observed output: https://gist.github.com/malaiwah/502ae094bd6e942720744d8683393f22
The gist contains the two Python files and observed output. Place check_decode.py and reference_cpu.py together. With PyTorch supporting float8_e4m3fn and float8_e8m0fnu, plus NumPy, Pillow and huggingface_hub installed:
hf download deepseek-ai/DeepSeek-V4.1-Flash --revision dba1be0a40aa45a94ad051997016db3960a90277 --include 'inference/*.py' --local-dir ./reference
python check_decode.py unpatched ./reference/inference
python check_decode.py patched ./reference/inference
The patched mode changes only the cache-publication guard in memory; it does not edit the downloaded sources. Exact small residuals can depend on the PyTorch version and CPU backend.
This complements the official-kernel H100 checks already described in PR #12. Discovered while validating Transformers PR #48721.