Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
112 commits
Select commit Hold shift + click to select a range
897e727
Add DeepSeek V4 Flash SFT example
devin-ai-integration[bot] Jun 5, 2026
024450e
Pin DeepSeek SFT image dependency
devin-ai-integration[bot] Jun 5, 2026
7c2f698
Add DeepSeek SFT smoke training controls
devin-ai-integration[bot] Jun 5, 2026
2157fa5
Make DeepSeek SFT wandb secret optional
devin-ai-integration[bot] Jun 5, 2026
13bf269
Use cluster-stable DeepSeek SFT run IDs
devin-ai-integration[bot] Jun 5, 2026
739e88d
Resume DeepSeek SFT from checkpoints
devin-ai-integration[bot] Jun 5, 2026
f0b1f9f
Add mcore-bridge dep and fix README smoke data-folder
devin-ai-integration[bot] Jun 5, 2026
635d2a9
Fix DeepSeek SFT checkpoint reload and CLI args
devin-ai-integration[bot] Jun 5, 2026
17c5732
Upgrade transformers to 5.10.2 for native deepseek_v4 support; fix RE…
devin-ai-integration[bot] Jun 5, 2026
1246b9c
Install mcore-bridge with --no-deps to resolve transformers 5.10.2 co…
devin-ai-integration[bot] Jun 5, 2026
b17a6ed
Patch transformers 4.57.4 to recognize DeepSeek V4 config
devin-ai-integration[bot] Jun 5, 2026
0419e2c
Verify DeepSeek V4 config registration at image build time
devin-ai-integration[bot] Jun 5, 2026
245dab9
Split DeepSeek V4 config verification into separate image step
devin-ai-integration[bot] Jun 5, 2026
724bba1
Patch transformers AutoConfig module for DeepSeek V4
devin-ai-integration[bot] Jun 5, 2026
894e062
Populate DeepSeek V4 config defaults for mcore bridge
devin-ai-integration[bot] Jun 5, 2026
6a80d85
Skip default instantiation for DeepSeek V4 config shim
devin-ai-integration[bot] Jun 5, 2026
9c1e43e
Make default DeepSeek run IDs retry-stable
devin-ai-integration[bot] Jun 5, 2026
55f668b
Set DeepSeek MoE router score for Megatron
devin-ai-integration[bot] Jun 5, 2026
4078b52
Pass DeepSeek router score through Megatron kwargs
devin-ai-integration[bot] Jun 5, 2026
7833fef
Preserve base Megatron while adding mcore bridge
devin-ai-integration[bot] Jun 5, 2026
387865e
Use Megatron Core dev for DSv4 hybrid attention
devin-ai-integration[bot] Jun 5, 2026
2bd3518
Avoid core attention recompute for DSv4 hybrid
devin-ai-integration[bot] Jun 5, 2026
5ffb4d4
Patch DSv4 rope fields for Megatron Core dev
devin-ai-integration[bot] Jun 5, 2026
f9b68fc
Set DSv4 YaRN original context default
devin-ai-integration[bot] Jun 5, 2026
fda1139
Make W&B training entrypoint optional
devin-ai-integration[bot] Jun 5, 2026
92c8590
Disable padding-free batches for DSv4 CSA
devin-ai-integration[bot] Jun 5, 2026
c1ae86e
Save DSv4 smoke checkpoint in Megatron format
devin-ai-integration[bot] Jun 5, 2026
a65d107
Format DeepSeek SFT entrypoint
devin-ai-integration[bot] Jun 5, 2026
ad411c9
Add export_and_eval: checkpoint export → vLLM deploy → GSM8K eval
devin-ai-integration[bot] Jun 8, 2026
c11d5aa
Fix: rewrite export_and_eval without heredoc corruption
devin-ai-integration[bot] Jun 8, 2026
8b54430
Fix export/eval checkpoint detection and server logging
devin-ai-integration[bot] Jun 8, 2026
376e740
Ensure export eval cleans up vLLM server on errors
devin-ai-integration[bot] Jun 8, 2026
faddb1f
Verify DeepSeek mcore bridge patch during image build
devin-ai-integration[bot] Jun 8, 2026
b31ffce
Register DeepSeek V4 CausalLM mapping for export
devin-ai-integration[bot] Jun 8, 2026
95c2dee
Fix DeepSeek V4 auto model patch registration
devin-ai-integration[bot] Jun 8, 2026
fd4388a
Allow DeepSeek V4 config default construction
devin-ai-integration[bot] Jun 8, 2026
bfb33a9
Use vLLM transformers fallback for DeepSeek V4 export
devin-ai-integration[bot] Jun 8, 2026
651b629
Improve DeepSeek V4 vLLM startup diagnostics
devin-ai-integration[bot] Jun 8, 2026
dd0feac
Compare GSM8K answers numerically
devin-ai-integration[bot] Jun 8, 2026
d8e361e
Retry DeepSeek V4 export eval on transient failures
devin-ai-integration[bot] Jun 8, 2026
0ca1474
Serve DeepSeek V4 export with latest vLLM
devin-ai-integration[bot] Jun 8, 2026
df2b481
Use python3 in vLLM image setup
devin-ai-integration[bot] Jun 8, 2026
d560e8e
Declare Python for vLLM serving image
devin-ai-integration[bot] Jun 8, 2026
a1d2e0e
Clear vLLM image entrypoint for Modal
devin-ai-integration[bot] Jun 8, 2026
1f7aa79
Preserve vLLM image Python environment
devin-ai-integration[bot] Jun 8, 2026
ae9e0d6
Update vLLM request logging flag
devin-ai-integration[bot] Jun 8, 2026
847512e
Sanitize DeepSeek V4 config for vLLM
devin-ai-integration[bot] Jun 8, 2026
ebf5b44
Add DeepSeek V4 compression ratios for vLLM
devin-ai-integration[bot] Jun 8, 2026
6f12c0d
Use Triton MoE backend for BF16 export
devin-ai-integration[bot] Jun 8, 2026
1e8c9f2
Restore DeepSeek V4 quantization config
devin-ai-integration[bot] Jun 8, 2026
1af434b
Use fp8 KV cache for DeepSeek V4 serving
devin-ai-integration[bot] Jun 8, 2026
0c2f9af
Backfill DeepSeek V4 Flash config fields
devin-ai-integration[bot] Jun 8, 2026
e1b4a16
Use MegaMoE expert-parallel serving
devin-ai-integration[bot] Jun 8, 2026
2768d08
Serve BF16 export with Transformers backend
devin-ai-integration[bot] Jun 8, 2026
9ed8209
Set pad token for DeepSeek V4 serving
devin-ai-integration[bot] Jun 8, 2026
62a716a
Add DeepSeek V4 config aliases for serving
devin-ai-integration[bot] Jun 8, 2026
0578668
Add missing DeepSeek V4 serving defaults
devin-ai-integration[bot] Jun 8, 2026
d36a1de
Use native vLLM for BF16 DeepSeek export
devin-ai-integration[bot] Jun 8, 2026
c062af8
Patch vLLM DeepSeek V4 BF16 serving
devin-ai-integration[bot] Jun 8, 2026
d7d5d97
Thread model parallel sizes through export
devin-ai-integration[bot] Jun 8, 2026
efd6215
Use BF16 attention path for merged DeepSeek export
devin-ai-integration[bot] Jun 8, 2026
a14fc3c
Fix DeepSeek vLLM deploy eval path
devin-ai-integration[bot] Jun 8, 2026
8033ccb
Align DeepSeek deploy image with validation run
devin-ai-integration[bot] Jun 8, 2026
26392b0
Wait for vLLM server cleanup
devin-ai-integration[bot] Jun 8, 2026
e1a61c8
Handle torch_dtype in vLLM config patch
devin-ai-integration[bot] Jun 8, 2026
6573ffe
Add long-context (60k) meeting summarization loop
devin-ai-integration[bot] Jun 9, 2026
eed8e9b
Avoid mutating cached base model config during eval
devin-ai-integration[bot] Jun 9, 2026
2859713
Use enough long-context examples for DP smoke runs
devin-ai-integration[bot] Jun 9, 2026
381303b
Enable sequence parallel for CP training
devin-ai-integration[bot] Jun 9, 2026
a2c4428
Fix long-context export and vLLM serving path
devin-ai-integration[bot] Jun 9, 2026
049e635
Disable sequence parallel for CP-only training
devin-ai-integration[bot] Jun 9, 2026
fa6336d
Fix multi-node export post-processing
devin-ai-integration[bot] Jun 9, 2026
5c9a88d
Add pipeline layout for PP training
devin-ai-integration[bot] Jun 9, 2026
d2ac38e
Patch RoPE length handling for CP smoke
devin-ai-integration[bot] Jun 9, 2026
1c03e85
Make RoPE patch match pinned Megatron
devin-ai-integration[bot] Jun 9, 2026
b84cf6e
Make RoPE CP patch robust
devin-ai-integration[bot] Jun 9, 2026
6a78e06
Serialize multi-node export volume commit
devin-ai-integration[bot] Jun 9, 2026
045ab44
Validate DeepSeek long-context SFT loop
devin-ai-integration[bot] Jun 10, 2026
0706497
Preserve gradients in long-context DeepSeek patches
devin-ai-integration[bot] Jun 10, 2026
e09ebbb
Reduce autograd-safe long-context memory
devin-ai-integration[bot] Jun 10, 2026
b1c5253
Stabilize DeepSeek long-context LoRA target
devin-ai-integration[bot] Jun 10, 2026
e77cd01
Extract DeepSeek patches into documented registry
devin-ai-integration[bot] Jun 10, 2026
19a1462
Split combined mcore_bridge patch and add ablation rationale
devin-ai-integration[bot] Jun 10, 2026
434e942
Disable W&B reporting explicitly by default
devin-ai-integration[bot] Jun 10, 2026
26a7526
Document DeepSeek patch ablation evidence
devin-ai-integration[bot] Jun 10, 2026
3ebaeb2
Add plan for 60k context testing without gradient-unsafe patches
devin-ai-integration[bot] Jun 11, 2026
8af9a0c
Guard DeepSeek SFT target modules
devin-ai-integration[bot] Jun 11, 2026
fbaae62
Expand DeepSeek target module guard
devin-ai-integration[bot] Jun 11, 2026
eb03fb6
DSv4-Flash 60k: drop the memory patches, commit to CP=4 default (#87)
devin-ai-integration[bot] Jun 11, 2026
a9cc673
Clean up DeepSeek long-context docs
devin-ai-integration[bot] Jun 11, 2026
68dd06c
Add cleanup and testing plan for handoff
devin-ai-integration[bot] Jun 12, 2026
a11043c
Drop redundant CUTLASS-DSL source patches
devin-ai-integration[bot] Jun 12, 2026
c6cbfd1
Upgrade transformers to 5.10.2, drop DSv4 registration patches
devin-ai-integration[bot] Jun 12, 2026
fec60df
Deduplicate vLLM serve/eval into _vllm_server context manager
devin-ai-integration[bot] Jun 12, 2026
d197292
Move DeepSeek planning notes into README
devin-ai-integration[bot] Jun 12, 2026
48085a9
Small config fixes: drop VLLM_USE_V1, torch pin, ablation scaffolding
devin-ai-integration[bot] Jun 12, 2026
b7c24c1
Fold PLAN_60K doc into README, delete the standalone file
devin-ai-integration[bot] Jun 12, 2026
e545f81
Remove CLEANUP_PLAN.md after executing the cleanup
devin-ai-integration[bot] Jun 12, 2026
5610c22
Merge parallel doc-folding commit d197292 into full cleanup
devin-ai-integration[bot] Jun 12, 2026
bd943cf
Bump huggingface_hub to 1.19.0 and fix base-model smoke check
devin-ai-integration[bot] Jun 12, 2026
0b23bd7
Pin peft==0.19.1 for transformers 5.10.2 compatibility
devin-ai-integration[bot] Jun 12, 2026
513a36a
Docs: smoke test tokenizes a prompt rather than checking chat template
devin-ai-integration[bot] Jun 12, 2026
4bd52f1
Pin peft==0.18.0 to keep transformers 5.x + torchao 0.9.0 compatible
devin-ai-integration[bot] Jun 12, 2026
33f34bc
Fix vLLM serving for transformers 5.x rope schema + harden startup
devin-ai-integration[bot] Jun 12, 2026
c199377
Document 60k patches-removed path as unvalidated (OOMs)
devin-ai-integration[bot] Jun 15, 2026
20b49d2
Validate 60k DeepSeek V4 Flash LoRA training
pawalt Jun 15, 2026
de4a7c7
Validate 60k DeepSeek V4 Flash LoRA serving
pawalt Jul 17, 2026
b60a893
Pin NCCL bootstrap interface for 60k training
pawalt Jul 17, 2026
4b97042
Keep validation incident details in PR
pawalt Jul 17, 2026
5fa70dc
Simplify and evaluate the validated 60k LoRA workflow
pawalt Jul 17, 2026
e363adb
Validate 60k LoRA training on 8 H200 nodes
pawalt Jul 18, 2026
777ade9
Clean up DeepSeek V4 training example
pawalt Jul 19, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ Use this repository to learn how to build distributed training jobs on Modal.
# Examples

- [**`benchmark/`**](/benchmark/) contains performance and reliability testing, using AWS EFA by default.
- [**`deepseek-v4-flash-sft/`**](/deepseek-v4-flash-sft/) 60k-context LoRA SFT and serving for DeepSeek-V4-Flash using NeMo AutoModel and vLLM.
- [**`lightning/`**](/lightning/) a simple lightning.ai Fabric example.
- [**`nanoGPT/`**](/nanoGPT/) training Karpathy's nanoGPT reproduction of OpenAI's GPT-2.
- [**`resnet50/`**](/resnet50/) training a ResNet50 model on the ImageNet dataset.
Expand Down
130 changes: 130 additions & 0 deletions deepseek-v4-flash-sft/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
# DeepSeek-V4-Flash 60k LoRA SFT and serving

Train a rank-64 attention LoRA for
[`deepseek-ai/DeepSeek-V4-Flash`](https://huggingface.co/deepseek-ai/DeepSeek-V4-Flash)
at a 60,000-token sequence length with NeMo AutoModel, finalize the
pipeline-parallel checkpoint as a PEFT adapter, and serve it with vLLM.

## Requirements

1. Modal multi-node cluster access and quota for 8 nodes of 8 H200 GPUs.
2. A Modal secret named `huggingface-secret` containing `HF_TOKEN`.
3. The repository's locked `uv` environment.

Create the Hugging Face secret once:

```bash
uv run --frozen modal secret create huggingface-secret HF_TOKEN=hf_xxxxx
```

## Topology

| Dimension | 8-node default | 16-node option |
| --- | ---: | ---: |
| Nodes / GPUs | 8 / 64 H200 | 16 / 128 H200 |
| TP / DP / PP / CP / EP | 1 / 1 / 4 / 16 / 16 | 1 / 2 / 4 / 16 / 32 |
| Sequence length | 60,000 | 60,000 |
| Global / local batch | 8 / 4 | 8 / 4 |
| Gradient accumulation | 2 | 1 |
| Attention / MoE dispatch | TileLang / UCCL-EP | TileLang / UCCL-EP |
| LoRA | rank 64, alpha 64 | rank 64, alpha 64 |
| AutoModel targets | `wq_a`, `wq_b`, `wkv` | `wq_a`, `wq_b`, `wkv` |
| Exported PEFT targets | `q_a_proj`, `q_b_proj`, `kv_proj` | `q_a_proj`, `q_b_proj`, `kv_proj` |
| Optimizer steps | 5 | 5 |
| Checkpoint step | 4 (zero-based) | 4 (zero-based) |
| Scheduler / cgroup memory | 128 MiB / 256 GiB per node | 128 MiB / 256 GiB per node |

The request enables EFA so Modal can schedule from the larger RDMA-capable
pool. The image contains UCCL extensions for both EFA and Mellanox/RoCE and
activates the extension that matches the scheduled nodes.

## Train

Run from the repository root with a unique run ID:

```bash
uv run --frozen modal run --detach \
deepseek-v4-flash-sft/modal_train.py::train \
--run-id dsv4-flash-60k-lora-$(date -u +%Y%m%d-%H%M%S)
```

Eight nodes is the default. Set `N_NODES=16` before the command to select the
DP=2, EP=32 layout. The launcher derives the topology from `N_NODES` and
rejects incompatible layouts before scheduling.

The training function writes a fixed-length synthetic chat dataset on each
node and renders [`train_recipe.yaml`](train_recipe.yaml) with the selected EP
size and checkpoint path. Replace `_write_synthetic_dataset` and the recipe's
`dataset` section to use a production dataset.

Each pipeline stage writes its adapter shard to the
`example-deepseek-v4-flash-sft-checkpoints` volume. The run ID is immutable:
the trainer refuses to overwrite an existing checkpoint directory.

## Finalize

After the detached training app finishes, merge the four pipeline-stage shards:

```bash
uv run --frozen modal run \
deepseek-v4-flash-sft/modal_train.py::finalize \
--run-id <run-id>
```

Finalization requires all 258 tensors across all 43 layers, verifies their
shapes and values, rewrites AutoModel projection names to the Transformers
names used by PEFT and vLLM, and loads the complete adapter through PEFT.

The finalized files are:

```text
/checkpoints/<run-id>/epoch_0_step_4/
|-- checkpoint_manifest.json
`-- model/
|-- adapter_config.json
`-- adapter_model.safetensors
```

The manifest records the adapter SHA-256 digest. Optimizer state is not saved,
so this output is a serving adapter rather than a training-resume checkpoint.

## Serve

Deploy the finalized run:

```bash
SERVE_RUN_ID=<run-id> \
uv run --frozen modal deploy \
deepseek-v4-flash-sft/modal_train.py
```

The `serve` endpoint is an OpenAI-compatible vLLM server protected by Modal
proxy authentication. It exposes the base model as
`deepseek-ai/DeepSeek-V4-Flash` and the adapter as
`deepseek-v4-flash-60k-lora`, with a maximum model length of 65,536 tokens.

Serving uses pipeline parallelism across four H200 GPUs. The launcher verifies
the finalized manifest and adapter digest before starting vLLM.

## Integration patches

The pinned AutoModel, UCCL, and vLLM images use six integration patches:

| Patch | Scope | Purpose |
| --- | --- | --- |
| [`patches/automodel_checkpoint_dequant.patch`](patches/automodel_checkpoint_dequant.patch) | AutoModel loading | Pass FP4 checkpoint dequantization through the recipe API. |
| [`patches/automodel_pp_peft_checkpoint.patch`](patches/automodel_pp_peft_checkpoint.patch) | AutoModel checkpointing | Save one PEFT shard per pipeline stage without optimizer state. |
| [`patches/automodel_composite_backend.patch`](patches/automodel_composite_backend.patch) | AutoModel control plane | Handle the `cpu:gloo,cuda:nccl` backend in signal handling. |
| [`patches/automodel_uccl_teardown.patch`](patches/automodel_uccl_teardown.patch) | AutoModel shutdown | Release UCCL before distributed and CUDA teardown. |
| [`patches/uccl_ipv6_oob.patch`](patches/uccl_ipv6_oob.patch) | UCCL transport | Use Modal's IPv6 inter-node interface for OOB coordination. |
| [`patches/vllm_deepseek_v4_lora.patch`](patches/vllm_deepseek_v4_lora.patch) | vLLM adapter loading | Register DeepSeek-V4 LoRA and map PEFT attention names to fused modules. |

These patches cover model loading, checkpoint export, transport, shutdown, and
adapter registration. They do not modify the model forward pass, attention
math, or autograd graph.

vLLM 0.25.1 provides DeepSeek-V4 serving and pipeline parallelism, while the
patch supplies the LoRA registration and packed Q/KV mapping for
`DeepseekV4ForCausalLM`. The serving image downloads the official model config
to an isolated directory so the FP8 quantization metadata comes directly from
the model repository.
Loading