refactor(fsdp)(4.2/5): add per-parameter dtype patch - #100
Merged
Rockdu merged 22 commits intoAug 8, 2026
Conversation
Rockdu
marked this pull request as ready for review
August 7, 2026 08:27
Add a source-guarded PyTorch 2.11 FSDP extension while preserving standard mixed-precision behavior, with distributed regression coverage for dtype communication and accumulation paths. This PR was authored with Claude. Co-authored-by: Cursor <cursoragent@cursor.com>
Exercise unpatched, standard patched, and all-BF16 mapped policies on Wan2.2 and LTX2.3 blocks across fully and hybrid sharded layouts. Authored with Claude. Co-authored-by: Cursor <cursoragent@cursor.com>
Use production Wan2.2 and LTX2.3 block dimensions and exercise FQN ambiguity, wrap scoping, shared parameters, reduction requirements, and delegation behavior. Authored with Claude. Co-authored-by: Cursor <cursoragent@cursor.com>
Exercise supported FP8 and floating targets alongside ignored integral and complex parameters under fully and hybrid sharded multi-module layouts. Authored with Claude. Co-authored-by: Cursor <cursoragent@cursor.com>
Verify that one mapped FSDP group is bitwise equivalent to explicit FP32 child wrappers inside a BF16 root for full-size Wan2.2 and LTX2.3 blocks. Authored with Claude. Co-authored-by: Cursor <cursoragent@cursor.com>
Run selected PyTorch FSDP mixed-precision, collective, and frozen-parameter tests with the Miles patch under the dedicated run-ci-torch label. Authored with Claude. Co-authored-by: Cursor <cursoragent@cursor.com>
Allow tests gated by run-ci-torch to pass CI registry validation. Authored with Claude. Co-authored-by: Cursor <cursoragent@cursor.com>
Apply the configured Ruff, isort, and Black fixes to the new FSDP patch tests. Authored with Claude.
Defer 2.11-only collective symbols to static checking so unsupported environments reach the patch version guard, and make paired iteration invariants explicit. Authored with Claude. Co-authored-by: Cursor <cursoragent@cursor.com>
Keep bare CPU CI aligned with the production GPU image and make patch guard tests valid when collection begins under another Torch version. Authored with Claude. Co-authored-by: Cursor <cursoragent@cursor.com>
Make the supported upstream baseline explicit at the patch definition. Authored with Claude. Co-authored-by: Cursor <cursoragent@cursor.com>
Keep the public policy module independent of private Torch internals and load the source-guarded 2.11 implementation only after matching the installed base version. Authored with Claude. Co-authored-by: Cursor <cursoragent@cursor.com>
Apply the repository import ordering and formatting to the split patch modules. Authored with Claude. Co-authored-by: Cursor <cursoragent@cursor.com>
Require exact FQN rules to apply across grouped module roots while rejecting conflicting dtype aliases of one shared parameter. Authored with Claude. Co-authored-by: Cursor <cursoragent@cursor.com>
Apply an exact FQN rule to every matching parameter across grouped roots while rejecting conflicting aliases of a shared parameter. Authored with Claude. Co-authored-by: Cursor <cursoragent@cursor.com>
Wrap the grouped parameter modules beneath an FSDP root so the regression test follows the supported runtime topology. Authored with Claude. Co-authored-by: Cursor <cursoragent@cursor.com>
Enumerate duplicate parameter names so equal alias overrides resolve once and conflicting alias overrides remain detectable. Authored with Claude. Co-authored-by: Cursor <cursoragent@cursor.com>
Exercise one FSDP group spanning two LayerNorms beneath separately wrapped blocks and require bitwise parity with independent FP32 LayerNorm groups. Authored with Claude. Co-authored-by: Cursor <cursoragent@cursor.com>
Rockdu
force-pushed
the
refactor/fsdp-4.1-param-dtype-patch
branch
from
August 7, 2026 08:36
63d1d5a to
9bb2873
Compare
Split vendored changes into focused upstream/replacement hunks so reviewers can distinguish additions from unchanged PyTorch code.
Keep patch banners within their surrounding scopes so Black preserves the review layout.
Document each large worker's test matrix, execution flow, and invariants so reviewers can understand the distributed coverage before reading implementation details.
This was referenced Aug 7, 2026
Read each resolved parameter dtype from its effective policy instead of storing the same override on FSDPParam twice.
This was referenced Aug 8, 2026
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.
What
Adds a source-guarded PyTorch 2.11 monkeypatch for exact per-parameter FSDP2 mixed-precision policies. The public module dispatches by the installed Torch base version and lazily loads the version-specific implementation, so unsupported versions never import PyTorch 2.11 internals. This PR does not include Miles actor or parallel-plan integration.
The distributed suite covers real full-size Diffusers blocks, exact output/gradient parity, all-gathered dtype and shape checks, FQN validation, mixed-dtype communication, and adversarial dtype/shape combinations.
Most of the code changes are due to CI ported from torch to ensure FSDP functions normally.
API (PyTorch 2.11 only)
For a single FSDP wrap spanning multiple modules:
param_dtype_mapis a sparse mapping of exact FQNs, scoped to the modules managed by thatfully_shardcall. Unlisted parameters useparam_dtype. When one call groups multiple modules, an exact FQN is broadcast to every matching managed parameter (for example,weightacross multiple LayerNorms). Multiple aliases of one shared parameter may specify the same dtype; conflicting alias dtypes are rejected. Wildcards are intentionally not part of the patch API; Miles' model integration compiles patterns to exact FQNs separately. Mixed trainable parameter dtypes require an explicit commonreduce_dtype.Compatibility
_fsdp_param_dtype_patch_2_11.py, leaving room for separate 2.12/2.13 implementations.torch==2.11.0,torchaudio==2.11.0, andtorchvision==0.26.0so bare CPU CI matches the production GPU image.MixedPrecisionPolicyand empty-map paths.float8_e4m3fn,float8_e4m3fnuz,float8_e5m2,float8_e5m2fnuz,float16,bfloat16,float32, andfloat64.float8_e8m0fnuand packedfloat4_e2m1fn_x2are intentionally unsupported because PyTorch 2.11 does not implement the required_foreach_copy_cast path. The patch does not add a slow per-tensor fallback.nn.Parameterobjects because it reconstructs sharded parameters with gradients enabled.Performance guard
Wan2.2 was run with identical settings and no per-parameter dtype overrides, changing only whether the patch was installed:
Test plan
torch==2.11.0+cu129.run-ci-torch.