You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit 9a58ada
Browse filesBrowse the repository at this point in the historyBrowse files
[DeepSeek-V4](https://github.com/deepseek-ai/DeepSeek-V4) is the next-generation Mixture-of-Experts language model from DeepSeek-AI. It extends the V3 design with **Hyper-Connections (mHC)** for multi-stream residual mixing, **Compressed Sparse Attention (CSA)** with a learned token-importance indexer (DSA), **hash-routed MoE layers** for the first few decoder blocks, and a refined **Multi-Token Prediction (MTP)** head with separate `e_proj` / `h_proj` projections.
4
+
5
+
DeepSeek V4 models are supported via the Bridge system with auto-detected configuration and weight mapping.
6
+
7
+
## Model Architecture Features
8
+
9
+
-**Hybrid Attention (DSv4HybridSelfAttention)**: Per-layer mix of dense MLA and Compressed Sparse Attention selected by `compress_ratios`
10
+
-**Compressed Sparse Attention (CSA)** with **DSA Indexer**: Top-k token selection over windowed keys; `index_n_heads`, `index_head_dim`, `index_topk` control the indexer
11
+
-**Hyper-Connections (mHC)**: 4-stream residual mixing per layer (`hc_mult = 4`) with sinkhorn-iterated attention; per-MTP-layer `hc_head_*` learns output contraction
12
+
-**Hash-Routed MoE**: First few decoder layers use a deterministic vocab → expert mapping (`tid2eid`) instead of softmax routing
13
+
-**Multi-Token Prediction (MTP)**: One MTP layer with separate `e_proj` and `h_proj` projections (post-MCore #4518)
14
+
-**YaRN RoPE**: `rotary_scaling_factor=16`, `original_max_position_embeddings=65536`; `mscale=mscale_all_dim=1.0` for V4
-**`o_groups` Output Projection**: `o_lora_rank` low-rank output projection split into `o_groups` parallel groups
17
+
18
+
## Examples, Parallelism, and Limitations
19
+
20
+
For checkpoint conversion and inference scripts, recommended parallelism settings, and current known limitations, see the [DeepSeek V4 examples README](https://github.com/NVIDIA-NeMo/Megatron-Bridge/tree/main/examples/models/deepseek_v4).
End-to-end conversion and inference scripts for the DeepSeek V4 family on Megatron Bridge.
4
+
5
+
The bridge supports four published variants out of the same code path. The on-disk quantisation differs between post-trained (Flash, Pro) and pretrained-only (Flash-Base, Pro-Base) models — see [`docs/models/llm/deepseek-v4.md`](../../../docs/models/llm/deepseek-v4.md) for the per-variant scheme.
6
+
7
+
## MCore Dev Branch Requirement
8
+
9
+
DSv4 imports require MCore changes that are not yet on a tagged release: PR [#3430](https://github.com/NVIDIA/Megatron-LM/pull/3430), PR [#4458](https://github.com/NVIDIA/Megatron-LM/pull/4458), PR [#4481](https://github.com/NVIDIA/Megatron-LM/pull/4481), and PR [#4518](https://github.com/NVIDIA/Megatron-LM/pull/4518), and PR [#4839](https://github.com/NVIDIA/Megatron-LM/pull/4839). Until these merge to Megatron-LM `main` and the bridge submodule pin advances, point `3rdparty/Megatron-LM` at the Megatron-LM `dev` branch:
10
+
11
+
```bash
12
+
./scripts/switch_mcore.sh dev
13
+
uv sync
14
+
```
15
+
16
+
Use `./scripts/switch_mcore.sh main` and `uv sync --locked` to return to the pinned main-branch submodule.
17
+
18
+
| Variant | HF path | Quant scheme | Validation |
19
+
|---------|---------|--------------|------------|
20
+
| DeepSeek-V4-Flash |`deepseek-ai/DeepSeek-V4-Flash`| FP8 attn + MXFP4 experts | Verified on GB200, last-token logit cosine 0.96-0.99 (short prompts ~0.98, long prompts >1024 tokens ~0.96-0.99) vs official inference |
21
+
| DeepSeek-V4-Flash-Base |`deepseek-ai/DeepSeek-V4-Flash-Base`| uniform FP8 (F32 scales) | Verified on GB200, last-real-token logit cosine 0.9866-0.9930, mean 0.9907 vs official inference |
| DeepSeek-V4-Pro-Base |`deepseek-ai/DeepSeek-V4-Pro-Base`| uniform FP8 (F32 scales) | Same bridge code as Pro; end-to-end untested |
24
+
25
+
## Examples
26
+
27
+
-`conversion.sh` imports HF weights into Megatron Bridge and exports Megatron checkpoints back to HF format.
28
+
-`inference.sh` runs text generation against an HF or Megatron checkpoint.
29
+
30
+
Run `bash conversion.sh` after setting `WORKSPACE` and `MODEL_VARIANT`. See each script's header comments for the expected environment variables and `#SBATCH` directives to edit before submitting.
31
+
32
+
The bridge's `maybe_modify_loaded_hf_weight` hook dispatches dequantisation by tensor dtype:
33
+
34
+
-`int8` -> MXFP4 packed nibbles -> `bfloat16` via the E2M1 lookup table and per-row 16-K-tile E8M0 scales
35
+
-`float8_e4m3fn` with companion `.scale` -> `bfloat16` via 128x128 block-scale expansion, handling both E8M0 and F32 scale dtypes
36
+
37
+
No external dequantisation script is required.
38
+
39
+
## Parallelism Configurations
40
+
41
+
DSv4 currently requires **TP=1** because MLA tensor parallelism is not supported alongside the DSv4 hybrid attention path. Scale via expert and pipeline parallelism instead.
-**MTP is disabled for inference** via `disable_mtp_for_inference()`. MTP weights are mapped end-to-end and loaded into the Megatron model.
54
+
55
+
-**Fused mHC is not supported on H100.** Set `use_fused_mhc=False` in the bridge config when running on Hopper GPUs. Fused mHC is enabled by default and works on GB200.
56
+
57
+
-**`fast_hadamard_transform` is optional.** When unavailable, DSA falls back to a PyTorch hadamard implementation. Throughput is lower but numerical behavior is unchanged.
58
+
59
+
-**Logit parity is verified for Flash and Flash-Base** against the official inference stack at last-real-token logits. The remaining gap is structural, from different attention/HC kernel decompositions and accumulation precisions between MCore and official inference.
0 commit comments