Repository navigation
[Do not review] Enable spmd_types backend for Qwen3.5 dense - #3973
Closed
Jeremalloch wants to merge 1 commit into
Closed
Jeremalloch wants to merge 1 commit into
Jeremalloch wants to merge 1 commit into
Conversation
|
The following ciflow label(s) have been added but CI has not been triggered yet because the workflows are awaiting approval:
Once a maintainer approves the workflows (scroll to the bottom of the PR page), the corresponding CI jobs will be triggered automatically. Please ping one of the reviewers if you do not have access to approve and run workflows. |
This was referenced Jul 23, 2026
Wire the dense Qwen3.5 model for the spmd_types backend, which CI previously blocked (pytorch#3901: not wired for the spmd_types mesh axes). - parallelize.py: resolve the FSDP mesh via resolve_fsdp_mesh / resolve_sparse_fsdp_mesh under spmd_types (there is no flattened "fsdp" axis; FSDP shards the multi-axis dense storage mesh along DataParallelMeshDims), pass dp_mesh_dims through to the decoder and vision-encoder fully_shard calls, and run model.parallelize() even for pure-FSDP topologies since the SPMD parameter annotations are what fully_shard translates into DTensor params. - sharding.py: annotate vision params without explicit state shardings as Replicate (FLUX's annotate_dp_cp_params_as_r pattern); add the missing out_src/in_src shardings that spmd_types requires to be explicit; redistribute the first decoder block's input R -> SP at the module boundary (the layer-0 residual previously relied on implicit DTensor redistribution, which spmd_types local tensors cannot do); vision rotary inv_freq R instead of I (same Replicate DTensor placement, but I cannot mix with R under typechecking); scaled-bias rowwise config for the vision rowwise-with-bias linears. - __init__.py: vision attn.proj, mlp.fc2, and merger.fc2 become ScaledBiasRowwiseLinear (gpt_oss pattern) so the per-rank bias/tp contribution sums correctly through the TP all-reduce; addmm cannot type a Partial matmul plus Replicate bias. - model.py: run the depthwise deltanet conv with local groups under spmd_types (module groups is the global channel count); local-region head-split views with boundary re-typing (SeparateQKVLinear pattern); register the FLA kernel autograd Functions as local-only for typechecking; annotate multimodal extras (pixel values, grid dims, mrope positions) that the trainer's input annotation does not cover; keep vision position/scatter index bookkeeping out of typechecking. - vision_encoder.py: local-region head splits, position-embedding and block-mask construction outside typechecking with boundary re-typing. - rope.py: build the MRoPE interleaved cache in a local region and re-type at the boundary. Validated on 4x H100 (dp_shard=2, tp=2): spmd_types runs qwen35_debugmodel, spmd_types + --debug.spmd_typechecking runs with AC disabled, and seeded deterministic loss/grad_norm stays within float noise of the default backend. Default-backend numerics compared against unmodified main with the same seed. MoE (EP token dispatcher) and the qwen3.5 CI spmd_types exclusion are follow-ups.
Jeremalloch
force-pushed
the
jm/qwen35-spmd-types
branch
from
July 27, 2026 17:55
cc4ca56 to
47ab085
Compare
Jeremalloch
marked this pull request as ready for review
July 29, 2026 23:14
Jeremalloch
requested review from
fegin,
tianyu-l,
wconstab and
wwwjn
as code owners
July 29, 2026 23:14
Jeremalloch
marked this pull request as draft
July 29, 2026 23:18
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
This was my heavily Claude aided attempt at adding spmd_types to Qwen3.5, prompted by @tianyu-l 's comment on #3801
Opened as a reference / proof of concept alongside #3895.
Claude's PR Description
Wire the dense Qwen3.5 model for the spmd_types backend, which CI previously blocked (#3901: not wired for the spmd_types mesh axes).
Original (pre-rebase) validation on 4x H100 (dp_shard=2, tp=2): spmd_types runs qwen35_debugmodel, spmd_types + --debug.spmd_typechecking runs with AC disabled, and seeded deterministic loss/grad_norm stays within float noise of the default backend. Default-backend numerics compared against unmodified main with the same seed. (Superseded by the post-rebase validation below, which also covers MoE, MoE+PP, and the varlen path; lifting the qwen3.5 CI spmd_types exclusion remains a follow-up.)
Update (2026-07-27): rebased onto post-#3801 main
Rebased onto current main (
b3a13eed) now that #3801 (Qwen3.5 varlen attention) merged; still a single commit (47ab085). Reconciliation notes:in_src_shardingsand the layer-0 R -> SP boundary config now use the new keys (xq_BLNK/xk_BLNK/xv_BLNV/g_BLN/beta_BLN,x_BLD).GatedDeltaNet.forwardnow use Qwen 3.5 Varlen Attention #3801's varlen-aware(kernel_B, kernel_L)shapes, so the samelocal_head_splitcovers both the dense/flex path and the flattened(1, B*L)varlen layout._causal_conv, next to main'slocal_mapDTensor path.Revalidated on 4x H100 (dp_shard=2, tp=2; torch 2.14 nightly + public spmd_types), fresh checkout of
47ab085:--debug.spmd_typechecking(AC none), 3 stepsqwen3_5_moe_fsdp+tp+ep+ppCI shape) + spmd_types, 10 stepsNew data point: #3801's varlen path runs under spmd_types unchanged -- previously untested in any qwen3.5 spmd enablement.
Known gaps:
--debug.spmd_typecheckingfails: the varlen(B, L) -> (1, B*L)flatten drops the DP axis annotation, so the FLA conv input hitsSpmdTypeError: args[0] missing axis mesh_dp ... has axes {}in_causal_conv1d_varlen. Supporting typechecking there means treating the flattened varlen span as a local region with boundary re-typing; follow-up.