[RFC] FSDPTurbo as an opt-in Swift SFT backend for DeepSeek V4.1
Maintainers usually reply within 1 day
Nobody has claimed this yet.
Assessment
- Difficulty
- 5/5
- Estimated time
- Over a week
- Newbie friendliness
- 8/100
- Issue type
- Feature
- Clarity
- Mostly clear
- Activity status
- Active
- Domain
- distributed-systems, machine-learning
Research direction
This is a design RFC for a new opt-in FSDPTurbo backend, so there is no single change to make yet. Read swift/dev/recipe/sft/assembly.py (build_supervised_objects) and swift/dev/config/distributed_config.py to see where a backend is selected, then swift/dev/recipe/sft/run_sft.py. Done means a maintainer confirms the extension point, and the issue does not yet define a patch to submit.
Written by the indexing model from the issue text.
Description
Checklist
- I have searched existing issues, and this is a new feature request.
Feature Request Description
I propose an optional FSDPTurbo backend for long-context SFT on MoE models, starting with DeepSeek V4.1.
Prototype branches
| Repository | Minimal branch | Scope |
|---|---|---|
| ms-swift | fsdpturbo-minimal |
SFT entry point, model plans, and Swift integration |
| FSDPTurbo | swift-compat-minimal |
Parallel runtime, model adapters, kernels, and sharded loading |
1. Design and fit with Swift main
The prototype exposes swift fsdpturbo sft as a separate entry point alongside the existing HF and Megatron paths. It reuses SwiftSft for arguments, model metadata, processors, templates, and dataset preparation. A small adapter maps those inputs to FSDPTurbo, which owns the distributed meshes, parameter wrapping, optimizer steps, and sharded weight I/O. Swift-facing PEFT options and checkpoint metadata stay in the adapter. Swift SFT pipeline
flowchart TB
subgraph SW[ms-swift]
direction LR
Config["SFT arguments and model registry"] --> Data["Processor, template, and dataset"]
Config --> Adapter["FSDPTurbo SFT adapter"]
Data -->|Encoded inputs and labels| Adapter
end
subgraph FT[FSDPTurbo]
direction LR
Shard["Model factory and distributed meshes"] --> Train["Forward, backward, optimizer"]
Load["Sharded checkpoint I/O"] -->|Owner-local weights| Shard
Train --> Ops["Eager operators and device kernels"]
end
Adapter -->|Config and model spec| Shard
Adapter -->|Encoded batches| Train
Train -.->|Metrics and checkpoint state| Adapter
The Swift boundary carries the model spec, training settings, and encoded batches. The model spec identifies the loader, the modules used for sharding and recomputation, and the supported parallel layouts. This lets the same entry point use a native V4.1 builder or a registered Hugging Face model.
2. Integration with dev-swift-v5
Start with local causal-LM SFT. Add fsdpturbo as an explicit backend in DistributedConfig and select it in build_supervised_objects. Reuse the v5 processor, template, and dataset builders. Translate parallel_spec, tuner, and checkpoint settings into a backend plan, then implement the step, evaluation, and checkpoint operations expected by run_supervised. Use a single launcher and verify encoded batches and one optimizer update across the legacy and v5 entry points. v5 configuration · v5 SFT recipe
flowchart TB
CLI["v5 SFT CLI and typed Configs"] --> Assembly["build_supervised_objects"]
Assembly --> Data["Shared processor, template, and dataset builders"]
Assembly --> Choice{"DistributedConfig.backend"}
Choice -->|HF or Megatron| Existing["Existing model builder"]
Choice -->|fsdpturbo, proposed| Turbo["Local FSDPTurbo model and runtime adapter"]
Data --> Cluster["SupervisedCluster"]
Existing --> Cluster
Turbo --> Cluster
Cluster --> Loop["run_supervised"]
Select the backend before model construction so it owns process groups and parameter wrapping. Validate the requested mesh layout against the model's TP, EP, and CP capabilities before allocating weights. v5 SFT assembly
3. GPU and NPU compatibility
Use FSDPTurbo's torch.accelerator abstraction with NCCL on CUDA and HCCL on Ascend. Start with eager PyTorch operators and enable fused kernels per device after parity tests. With matching checkpoints, tokenized batches, and parallel layouts, compare loss, gradients, and optimizer updates for LoRA and full SFT on both platforms.
Run these checks on one node before scaling out. Match the effective target-token count and accumulation window. After eager parity passes, report fused-path accuracy, throughput, and peak device memory with the hardware and topology.
4. DeepSeek V4.1
Reuse Swift's deepseek_v41 metadata and prompt template, and port its prompt contract to the v5 template registry with token and label parity tests. Keep the native model factory in FSDPTurbo. Build on meta, apply EP/FSDP, then materialize and load each rank's shards from a dequantized BF16 checkpoint in Hugging Face format. The backend handles Host Engram and KV-AllGather context parallelism. Start with text-only LoRA on explicit attention projections. Swift V4.1 template
sequenceDiagram
participant S as Swift adapter
participant R as FSDPTurbo runtime
participant W as BF16 checkpoint
S->>R: Native meta model, LoRA config, and parallel plan
R->>R: Warm process groups and apply EP/FSDP
R->>R: Materialize local shards and Host Engram storage
R->>W: Read locally owned weight shards
W-->>R: Load BF16 weights
R->>R: Initialize or restore LoRA and sync replicas
loop Training updates
S->>R: Aligned inputs, masks, and complete labels
R->>R: KV-AllGather CP, backward, and optimizer update
R-->>S: Loss and training metrics
end
S->>R: Save adapter and training state
For context parallelism, right-pad text to the CP and compression alignment and split token IDs, masks, and positions once. Keep labels complete and unshifted for the model-owned loss. The LoRA path synchronizes replicated adapter gradients and preserves the expert requires_grad flags after sharding.
An earlier prototype completed 1,000 LoRA updates with all 40 language layers at 32K context on four nodes with 32 Ascend NPUs. The proposed merge checks also cover token-weighted accumulation with uneven labels, CP=1 recomputation, and adapter save/resume.
5. Additional model support
| Stage | Model family | Acceptance scope |
|---|---|---|
| 1 | DeepSeek V4.1 | Validate the native long-context LoRA path, then qualify full-parameter SFT separately. |
| 2 | Qwen3.5-MoE | Qualify the existing qwen3_5_moe plan with the HF loader, FSDP and EP, and explicit LoRA and full-SFT checks on CUDA and Ascend. |
| 3 | Dense Hugging Face causal LM, starting with a candidate such as Qwen3-8B | Exercise generic HF loading, FSDP wrapping, and checkpoint round-trips for both full SFT and LoRA. |
Additional families should enter through a model spec with loader, layer-wrapping rules, LoRA targets, and supported parallelism. Native checkpoints or custom attention get a model adapter in FSDPTurbo. All families use the same Swift entry point and share the data, optimizer-update, and save/resume acceptance checks. Prototype model specs · Qwen3-8B backend example
Pull Request
I plan to start with the opt-in adapter and contract tests. Is the local SFT assembly in v5 the right extension point for this backend?
- Dominant language
- Python
- Stars
- 16.2k
- Forks
- 1.8k
- Avg merge
- 1d 14h
- Merged PRs (30d)
- 68
Getting set up
- No Dockerfile or Docker Compose file
- Has a pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from modelscope/ms-swift
-
get_multimodal_target_regex(..., exclude_router=True) does not exclude shared_expert_gatePossibly taken @KonnyakuMatcha claimed this 1 day ago. Open
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
modelscope/ms-swift#10696 ·
Maintainers usually reply within 1 day
-
[BUG] GRPO REAL loss crashes with beta>0 and kl_in_reward=True (NoneType * Tensor)Possibly taken @newcloud123 claimed this 1 day ago. Open
Difficulty 2/5 1-3 hours Newbie friendliness 85/100
modelscope/ms-swift#10690 ·
Maintainers usually reply within 1 day
-
[BUG] GRPO REAL loss divides by all groups instead of valid groups, silently scaling gradientsPossibly taken @newcloud123 claimed this 1 day ago. Open
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
modelscope/ms-swift#10688 ·
Maintainers usually reply within 1 day
-
enhancement
Difficulty 2/5 Half a day Newbie friendliness 62/100
modelscope/ms-swift#10621 ·
Maintainers usually reply within 1 day
-
[Bug] `get_seed` consumes a draw from the shared RandomState even when decision augmentation is disabled, changing the train/val split and dataset shufflePossibly taken @ryznren claimed this 38 days ago. Openbug
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
modelscope/ms-swift#10466 · 1 comment ·
Maintainers usually reply within 1 day
All issues in modelscope/ms-swift
Similar issues
-
Test: to_hijri() accepts datetime.datetime and uses only the date partPossibly taken A pull request linked to this issue is open or already merged. Opengood first issue
Difficulty 1/5 Under an hour Newbie friendliness 95/100
omarelshamy25x/shamy-hijri#63 · 3 comments ·
Maintainers usually reply within 1 day
-
polish
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
521xueweihan/HelloGitHub#4729 ·
-
[Bug]: Score parser reads parts of scientific notation as valid scoresPossibly taken @AshutoshSingh840 claimed this today. Open
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
UKGovernmentBEIS/control-arena#992 ·
Maintainers usually reply within 3 days
-
Difficulty 1/5 Under an hour Newbie friendliness 92/100
mvalentsev/awesome-free-ai-coding#70 ·
Maintainers usually reply within 1 day