Instructions to use autotrust/DeepSeek-V4-Flash-DSpark-4E with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use autotrust/DeepSeek-V4-Flash-DSpark-4E with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="autotrust/DeepSeek-V4-Flash-DSpark-4E")# Load model directly from transformers import AutoTokenizer, AutoModelForCausalLM tokenizer = AutoTokenizer.from_pretrained("autotrust/DeepSeek-V4-Flash-DSpark-4E") model = AutoModelForCausalLM.from_pretrained("autotrust/DeepSeek-V4-Flash-DSpark-4E") - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use autotrust/DeepSeek-V4-Flash-DSpark-4E with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "autotrust/DeepSeek-V4-Flash-DSpark-4E" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "autotrust/DeepSeek-V4-Flash-DSpark-4E", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'Use Docker
docker model run hf.co/autotrust/DeepSeek-V4-Flash-DSpark-4E
- SGLang
How to use autotrust/DeepSeek-V4-Flash-DSpark-4E 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 "autotrust/DeepSeek-V4-Flash-DSpark-4E" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "autotrust/DeepSeek-V4-Flash-DSpark-4E", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'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 "autotrust/DeepSeek-V4-Flash-DSpark-4E" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "autotrust/DeepSeek-V4-Flash-DSpark-4E", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }' - Docker Model Runner
How to use autotrust/DeepSeek-V4-Flash-DSpark-4E with Docker Model Runner:
docker model run hf.co/autotrust/DeepSeek-V4-Flash-DSpark-4E
Released by AutoTrust AI Lab · Adapted by Hai Yu (cloudyu)
DeepSeek-V4-Flash-DSpark-4E
This is the DeepSeek-V4-Flash-DSpark checkpoint — a 284B MoE model with a speculative decoding (DSpark) module — configured and evaluated with num_experts_per_tok=4 (top_k=4) instead of the original num_experts_per_tok=6.
Why top_k=4 Instead of 6?
The original num_experts_per_tok=6 is not a power of 2. In practice, this means:
- GPU tensor core utilization is suboptimal for certain MoE dispatch shapes
- Memory alignment and warp scheduling are less efficient compared to power-of-2 expert counts
- The routing decision per token requires computing softmax over 6 logits instead of 4, introducing unnecessary overhead
Setting top_k to 4 (a power of 2) gives the GPU's SIMT architecture a natural alignment for expert dispatch and attention masking, while activating 33% fewer parameters per token with no accuracy degradation — and in many reasoning-heavy tasks, a measurable accuracy improvement.
Key Changes from the Original
| Configuration | Original (top_k=6) | This Model (top_k=4) |
|---|---|---|
num_experts_per_tok |
6 | 4 |
| Activated params per token | ~13B | ~11B |
| Total params | 284B | 284B |
| Routing method | noaux_tc | noaux_tc |
| All other weights | identical | identical |
Performance Analysis
Activated Parameters
The DeepSeek-V4-Flash architecture has 284B total parameters, of which 13B are activated per token at 11B** — a 15% reduction — because each token routes to only 4 out of 256 routed experts instead of 6, while shared experts and attention parameters remain unchanged.top_k=6. By switching to top_k=4, activated parameters drop to **
Inference Speed
| Benchmark | top_k=4 | top_k=6 | Speedup |
|---|---|---|---|
| MMLU-Pro (12,032 questions) | 73.0 s | 89.0 s | +18.0% |
| HumanEval (164 problems) | 55.8 s | 64.1 s | +14.9% |
| Per-token generation | ~0.34 s | ~0.39 s | +12.8% |
The speedup comes from: (a) fewer expert feed-forward computations, (b) better GPU warp utilization with power-of-2 routing, and (c) reduced softmax and gather/scatter overhead in the router.
Accuracy Impact
| Benchmark | top_k=4 | top_k=6 | Δ |
|---|---|---|---|
| MMLU-Pro | 42.30% | 39.27% | +3.03% |
| HumanEval | 94.51% | 95.73% | −1.22% |
On MMLU-Pro, top_k=4 significantly outperforms top_k=6 (+3.03%), suggesting that routing to fewer, more confidently selected experts improves factual retrieval. On HumanEval, top_k=6 retains a narrow edge (+1.22%), indicating code generation benefits from broader expert diversity.
Overall: top_k=4 delivers superior throughput with competitive or better accuracy on knowledge-heavy tasks, making it the recommended default.
Evaluation Results
MMLU-Pro (chat mode, max_tokens=20)
| Configuration | Accuracy | Generation Time |
|---|---|---|
| DSpark top_k=4 | 42.30% | 73.0 s |
| DSpark top_k=6 | 39.27% | 89.0 s |
| 4E top_k=4 (reference) | 41.75% | 122.0 s |
HumanEval (thinking mode, max_tokens=4096)
| Configuration | Pass@1 | Generation Time |
|---|---|---|
| DSpark top_k=4 | 94.51% | 55.78 s |
| DSpark top_k=6 | 95.73% | 64.07 s |
| 4E top_k=4 (reference) | 95.73% | 56.83 s |
Key Findings
- MMLU-Pro: top_k=4 outperforms top_k=6 by +3.03% (42.30% vs 39.27%) — the additional expert diversity in top_k=6 hurts multiple-choice knowledge retrieval.
- HumanEval: top_k=6 slightly outperforms top_k=4 (+1.22%), showing code generation benefits from more experts.
- Speed: top_k=4 generates ~13–15% faster across both benchmarks, with 33% fewer activated parameters per token.
vLLM Compatibility: Required Code Modification
⚠️ Important: The checkpoint's tid2eid (hash-based expert routing table) weights have shape [vocab_size, 6] (trained with num_experts_per_tok=6). To run with num_experts_per_tok=4, vLLM's model loading code must be patched.
The Fix (in vLLM source)
In /home/user/.local/lib/python3.11/site-packages/vllm/models/deepseek_v4/nvidia/model.py, locate the load_weights method and add a shape-mismatch handler for tid2eid weights:
# Inside the else block (~line 1135), before weight_loader():
if "tid2eid" in name and loaded_weight.shape != param.shape:
loaded_weight = loaded_weight[:, :param.shape[1]].contiguous()
This slices the checkpoint's 6-column tid2eid tensor to 4 columns, matching the config's num_experts_per_tok=4. Without this patch, vLLM raises:
AssertionError: Attempted to load weight (torch.Size([129280, 6])) into parameter (torch.Size([129280, 4]))
Configuration
Set num_experts_per_tok=4 in config.json:
"num_experts_per_tok": 4
Model Details
| Property | Value |
|---|---|
| Architecture | DeepSeekV4ForCausalLM (MoE) |
| Total Parameters | 284B |
| Activated Parameters | ~11B (top_k=4) |
| Expert Precision | FP4 (MXFP4) |
| Other Parameters | FP8 |
| Context Length | 1,048,576 tokens |
| DSpark Module | Markov speculative decoding (layers 40–42) |
| Recommended top_k | 4 |
Usage
Use with vLLM (with the tid2eid patch above):
from vllm import LLM, SamplingParams
llm = LLM(
model="autotrust/DeepSeek-V4-Flash-DSpark-4E",
trust_remote_code=True,
kv_cache_dtype="fp8",
max_model_len=32768,
)
sampling_params = SamplingParams(
temperature=0.0,
max_tokens=20,
)
outputs = llm.generate(["Your prompt here"], sampling_params)
For proper message encoding, use the encoding module included in this repository.
License
MIT
- Downloads last month
- 215