Repository navigation
MoE support for Qwen drafts (A1, A2, B) #993
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
48e8c6c
moe: registry and MoE config
sherlockwu 15369e3
moe: router, balance, expert and shared-expert contracts
sherlockwu e2bf91b
moe: MoELayer, build_ffn and hooks wired into DFlash layers and strat…
sherlockwu bdfb689
moe: checkpoint conversion boundary and warm-start planning
sherlockwu 8801285
docs: MoE design note and customization guide
sherlockwu d3e7e51
moe: balance controllers observe the full RoutingResult
sherlockwu 85b230d
moe: base types and config
yushengsu-thu ae6edd4
moe: grouped experts, SwiGLU shared expert and top-k router
yushengsu-thu 89a840e
moe: one TrainingState loop in MoELayer, hooks in layer.py
yushengsu-thu 97107e7
moe: checkpoint layouts at every file boundary
yushengsu-thu 99ee8b2
moe: finalize_step_output adds the MoE terms to every strategy
yushengsu-thu ef134da
docs: MoE design note and guides for the framework core
yushengsu-thu e7ea89b
moe: aux_loss balancing
yushengsu-thu 348569c
moe: the sigmoid shared-expert gate
yushengsu-thu eac199a
moe: router bias, sample router centering and its export fold
yushengsu-thu 4f007ba
moe: per-layout serving config and serving class
yushengsu-thu 08e9bd9
moe: Qwen3.5/3.8 MoE family and the Qwen3.8-27B draft config
yushengsu-thu c05ebc1
examples: Qwen3.8-27B DSpark MoE recipe on one 8x H200 node
yushengsu-thu 3bda0a9
moe: name the looked-up class before using it
yushengsu-thu c44212a
moe: the router adds the aux loss; balance only shifts selection
yushengsu-thu 15459cb
moe: turn the aux loss on by default
yushengsu-thu 64f2c61
moe: move the shared expert into experts.py
yushengsu-thu File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,77 @@ | ||
| { | ||
| "architectures": [ | ||
| "DSparkDraftModel" | ||
| ], | ||
| "attention_bias": false, | ||
| "attention_dropout": 0.0, | ||
| "auto_map": { | ||
| "AutoModel": "dspark.DSparkDraftModel" | ||
| }, | ||
| "block_size": 7, | ||
| "bos_token_id": null, | ||
| "dflash_config": { | ||
| "attention_mode": "gqa", | ||
| "confidence_head_alpha": 1.0, | ||
| "confidence_head_with_markov": true, | ||
| "enable_confidence_head": true, | ||
| "markov_head_type": "vanilla", | ||
| "markov_rank": 256, | ||
| "mask_token_id": 248070, | ||
| "moe_aux_loss_coeff": 0.001, | ||
| "moe_dispatch": "grouped_mm", | ||
| "moe_router_center": "sample", | ||
| "moe_router_center_momentum": 0.99, | ||
| "projector_type": "dspark", | ||
| "target_layer_ids": [ | ||
| 5, | ||
| 19, | ||
| 33, | ||
| 47, | ||
| 61 | ||
| ] | ||
| }, | ||
| "dtype": "bfloat16", | ||
| "eos_token_id": 248044, | ||
| "head_dim": 128, | ||
| "hidden_act": "silu", | ||
| "hidden_size": 5120, | ||
| "initializer_range": 0.02, | ||
| "intermediate_size": 17408, | ||
| "layer_types": [ | ||
| "full_attention", | ||
| "full_attention", | ||
| "full_attention", | ||
| "full_attention", | ||
| "full_attention" | ||
| ], | ||
| "max_position_embeddings": 262144, | ||
| "max_window_layers": 5, | ||
| "model_type": "qwen3", | ||
| "moe_intermediate_size": 512, | ||
| "moe_preset": "qwen3_5_moe", | ||
| "n_routed_experts": 512, | ||
| "n_shared_experts": 1, | ||
| "num_attention_heads": 32, | ||
| "num_experts_per_tok": 10, | ||
| "num_hidden_layers": 5, | ||
| "num_key_value_heads": 8, | ||
| "num_target_layers": 64, | ||
| "pad_token_id": 248044, | ||
| "rms_norm_eps": 1e-06, | ||
| "rope_parameters": { | ||
| "beta_fast": 32.0, | ||
| "beta_slow": 1.0, | ||
| "factor": 32.0, | ||
| "original_max_position_embeddings": 8192, | ||
| "rope_theta": 10000000, | ||
| "rope_type": "yarn" | ||
| }, | ||
| "rope_theta": 10000000, | ||
| "shared_expert_intermediate_size": 2048, | ||
| "sliding_window": null, | ||
| "target_hidden_size": null, | ||
| "tie_word_embeddings": false, | ||
| "use_cache": true, | ||
| "use_sliding_window": false, | ||
| "vocab_size": 248320 | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
112 changes: 112 additions & 0 deletions
112
...configs/online/disaggregated/managed-local/qwen3.8-27b-dspark-moe-h200-disaggregated.yaml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,112 @@ | ||
| # Qwen3.8-27B DSpark with a Qwen3.5-MoE FFN (512 experts x 512, top-10, one | ||
| # sigmoid-gated 2048-wide shared expert; configs/qwen3.8-27b-dspark-moe.json) | ||
| # on one 8x H200 node: four TP=1 FP8 capture servers on GPUs 0-3 and a 4-rank | ||
| # FSDP trainer on GPUs 4-7, all owned by `specforge train`. | ||
| # | ||
| # The drafter has about 21B parameters, 20B of them routed experts (about 1B | ||
| # are active per token), so the trainer shards everything (FULL_SHARD) and | ||
| # offloads optimizer state to the host. The draft trains from scratch: the target is dense. | ||
| # Router centering (moe_router_center: sample) and the aux loss (0.001) keep | ||
| # the router from collapsing onto a few experts; watch moe/experts_unused_frac | ||
| # and moe/route_entropy_frac. | ||
| # | ||
| # Launch with PYTORCH_CUDA_ALLOC_CONF=expandable_segments:True. The trainer | ||
| # ranks run at the H200 memory limit (each micro-step all-gathers a layer's | ||
| # 2.5 GiB stacked experts while no_sync() holds the 41.6 GB unsharded | ||
| # gradient), and without expandable segments the caching allocator fragments | ||
| # and retries failed allocations on every micro-step. | ||
| model: | ||
| target_model_path: Qwen/Qwen3.8-27B-FP8 | ||
| draft_model_config: configs/qwen3.8-27b-dspark-moe.json | ||
| target_backend: sglang | ||
| trust_remote_code: true | ||
| embedding_key: model.language_model.embed_tokens.weight | ||
| lm_head_key: lm_head.weight | ||
| load_target_embedding: true | ||
| torch_dtype: bfloat16 | ||
| mask_token_id: 248070 | ||
| # FA3 for the hybrid target's full-attention layers on Hopper; the GDN | ||
| # layers use SGLang's default linear-attention kernels. | ||
| sglang_attention_backend: fa3 | ||
| sglang_disable_radix_cache: true | ||
| # data.max_length + 7 tokens of request headroom for the capture endpoint. | ||
| sglang_context_length: 8199 | ||
| data: | ||
| train_data_path: ./cache/dataset/qwen3.8-27b-regen-train.jsonl | ||
| max_length: 8192 | ||
| chat_template: qwen3.5 | ||
| build_dataset_num_proc: 32 | ||
| dataloader_num_workers: 8 | ||
| cache_dir: cache/qwen3.8-27b-dspark-moe | ||
| training: | ||
| strategy: dspark | ||
| num_epochs: 1 | ||
| # 4 ranks x 2 x 64 = 512 samples per optimizer step. On B200 the same run | ||
| # used batch_size 4 x accumulation 32; H200 ranks have less memory, so this | ||
| # recipe halves the micro-batch and doubles the accumulation. | ||
| batch_size: 2 | ||
| accumulation_steps: 64 | ||
| fsdp_sharding: FULL_SHARD | ||
| optimizer_cpu_offload: true | ||
| learning_rate: 0.0005 | ||
| lr_scheduler: constant | ||
| warmup_ratio: 0.04 | ||
| max_grad_norm: 1.0 | ||
| attention_backend: flex_attention | ||
| num_anchors: 512 | ||
| loss_decay_gamma: 4.0 | ||
| objective_chunk_blocks: 128 | ||
| dspark_ce_loss_alpha: 0.1 | ||
| dspark_l1_loss_alpha: 0.9 | ||
| dspark_confidence_head_alpha: 1.0 | ||
| save_interval: 500 | ||
| max_checkpoints: 3 | ||
| log_interval: 10 | ||
| dist_timeout: 15 | ||
| seed: 42 | ||
| prompt_seed: 42 | ||
| tracking: | ||
| report_to: none | ||
| runtime: | ||
| producer_lease: 8 | ||
| producer_concurrency: 8 | ||
| in_flight_high_watermark: 768 | ||
| in_flight_low_watermark: 512 | ||
| run_id: qwen3.8-27b-dspark-moe-h200-disaggregated | ||
| output_dir: outputs/qwen3.8-27b-dspark-moe-h200-disaggregated | ||
| deployment: | ||
| mode: disaggregated | ||
| trainer: | ||
| nnodes: 1 | ||
| nproc_per_node: 4 | ||
| disaggregated: | ||
| control_dir: outputs/qwen3.8-27b-dspark-moe-h200-disaggregated/control | ||
| consumer_state_dir: outputs/qwen3.8-27b-dspark-moe-h200-disaggregated/consumer-state | ||
| backend: mooncake | ||
| client_buffer_size: 1073741824 | ||
| managed_local: | ||
| trainer_cuda_visible_devices: ["4", "5", "6", "7"] | ||
| mooncake: | ||
| # TCP works everywhere; RDMA loopback (protocol: rdma plus | ||
| # rdma_devices) removes the CPU copies of every captured byte. | ||
| protocol: tcp | ||
| global_segment_size_bytes: 107374182400 | ||
| local_buffer_size_bytes: 1073741824 | ||
| default_kv_lease_ttl_ms: 300000 | ||
| capture_servers: | ||
| - port: 30000 | ||
| cuda_visible_devices: ["0"] | ||
| tp_size: 1 | ||
| mem_fraction_static: 0.85 | ||
| - port: 30001 | ||
| cuda_visible_devices: ["1"] | ||
| tp_size: 1 | ||
| mem_fraction_static: 0.85 | ||
| - port: 30002 | ||
| cuda_visible_devices: ["2"] | ||
| tp_size: 1 | ||
| mem_fraction_static: 0.85 | ||
| - port: 30003 | ||
| cuda_visible_devices: ["3"] | ||
| tp_size: 1 | ||
| mem_fraction_static: 0.85 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it common to give this configs??
Refter to config and see how to provide the right config