Skip to content

refactor(fsdp)(4/5): per-parameter weight-precision control for FSDP2 - #91

Closed
Rockdu wants to merge 45 commits into
radixark:mainfrom
Rockdu:feat/fsdp-precision-control
Closed

refactor(fsdp)(4/5): per-parameter weight-precision control for FSDP2#91
Rockdu wants to merge 45 commits into
radixark:mainfrom
Rockdu:feat/fsdp-precision-control

Conversation

@Rockdu

@Rockdu Rockdu commented Aug 3, 2026

Copy link
Copy Markdown
Collaborator

Need to align the design before merging.


What

A configurable precision-control system for FSDP2 training. Each model family declares per-tensor dtype intent as PrecisionSpec rules in its TrainPipelineConfig (in-repo Python, always active); a compiler (precision.py) lowers the per-tensor plan onto what FSDP2 can express. See the flow diagram in the precision.py module docstring.

Two dtype axes per rule, last match wins per axis:

  • master: resident dtype of the param/buffer (optimizer precision), lowered to per-tensor load-time casts
  • gather: all-gather / forward dtype, lowered to nested fully_shard groups (one per gather dtype, reshard_after_forward=False) so overrides stay fully inside FSDP (DTensor params, FSDP grad reduction, DCP/offload unchanged)

Compute dtype is deliberately not strictly managed: the trainer wraps the DiT forward in torch.autocast(default dtype); op-level train/rollout gaps are left to the monkey-patch registry.

Changes

  • New miles/backends/fsdp_utils/precision.py: spec, compiler, lowering validation (whole-module coverage, single dtype per module, zero-hit rules rejected)
  • --precision-default-dtype: one knob filling every dtype left unset (training forward/gather + --sglang-dit-precision); defaults filled in set_default_diffusion_args, conflicts rejected in miles_validate_args
  • Forward input casts removed (cast_forward_inputs=False, cast_cond_to_dtype deleted); DiT forward runs under autocast; LTX's inner autocast folded into the shared one
  • Grad-ckpt buffer force-cast in apply_fsdp2 removed (autocast keeps recompute dtypes consistent)
  • All family specs ship empty: default behavior is unchanged except the autocast switch

Tests

10 CPU unit tests for the compiler in tests/fast/backends/fsdp_utils/test_precision_plan.py, registered to stage-a-cpu.

Pending GPU validation (why draft)

  • Wan2.2 grad-ckpt with fp32 RoPE buffers now that the buffer force-cast is gone
  • Autocast numerics vs sglang rollout (fp32-promoted ops like softmax/layer_norm)
  • A populated family spec (e.g. Wan norm fp32) end-to-end: sub-shard group all-gather, DCP save/resume

@Rockdu Rockdu changed the title feat(fsdp): per-parameter weight-precision control compiled onto FSDP2 refactor(fsdp)(4/5): per-parameter weight-precision control for FSDP2 Aug 3, 2026
Rockdu added a commit to Rockdu/miles_diffusion that referenced this pull request Aug 3, 2026
PR radixark#91 removed trainer-side forward input casts, so the LTX train forward
began receiving an fp32 trajectory latent. dtype derivation in
forward_velocity then sent fp32 positions into RoPE, while the sglang-d
rollout computes RoPE from bf16-quantized coordinates: the pe tables diverge
at rel ~0.5 in high-frequency bands (dump-verified on a paired LTX-2.3 run)
and every attention output degrades from block 0. Casting the latent back to
the autocast dtype at the model boundary restores the rollout-parity chain:
bit-exact latent (bf16(x_fp32) equals the tensor rollout consumed), bf16
positions/context, and the original e2e reconstruction rounding.

Verified on the same run that the fp32-sigma change works as intended:
AdaLN timestep input now pairs fp32/fp32 at rel 6.2e-8 (was 1.8e-3), and
blocks.0.attn1 input improves 17x (1.26e-2 -> 7.3e-4).

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@Rockdu
Rockdu force-pushed the feat/fsdp-precision-control branch from 9a4845b to 0ca24cf Compare August 3, 2026 21:34
@Rockdu
Rockdu force-pushed the feat/fsdp-precision-control branch from c89ef19 to b854a38 Compare August 4, 2026 05:39
@Rockdu
Rockdu marked this pull request as ready for review August 4, 2026 09:01
@Rockdu Rockdu changed the title refactor(fsdp)(4/5): per-parameter weight-precision control for FSDP2 [Do Not Merge] refactor(fsdp)(4/5): per-parameter weight-precision control for FSDP2 Aug 5, 2026
@Rockdu
Rockdu force-pushed the feat/fsdp-precision-control branch from 7e2c99f to d2b22a8 Compare August 7, 2026 17:38
@Rockdu Rockdu changed the title [Do Not Merge] refactor(fsdp)(4/5): per-parameter weight-precision control for FSDP2 [Do Not Merge] refactor(fsdp)(4.3/5): family-declared input dtype policy at the model boundary Aug 7, 2026
@Rockdu Rockdu changed the title [Do Not Merge] refactor(fsdp)(4.3/5): family-declared input dtype policy at the model boundary refactor(fsdp)(4.0/5): family-declared input dtype policy at the model boundary Aug 7, 2026
@Rockdu
Rockdu changed the base branch from main to refactor/fsdp-4.1-param-dtype-patch August 7, 2026 17:46
@Rockdu
Rockdu force-pushed the refactor/fsdp-4.1-param-dtype-patch branch from c2b7e3b to ed24796 Compare August 7, 2026 17:47
@Rockdu
Rockdu changed the base branch from refactor/fsdp-4.1-param-dtype-patch to main August 7, 2026 17:50
@Rockdu
Rockdu force-pushed the feat/fsdp-precision-control branch from d2b22a8 to 7e2c99f Compare August 7, 2026 17:55
@Rockdu Rockdu changed the title refactor(fsdp)(4.0/5): family-declared input dtype policy at the model boundary refactor(fsdp)(4/5): per-parameter weight-precision control for FSDP2 Aug 7, 2026
@Rockdu

Rockdu commented Aug 7, 2026

Copy link
Copy Markdown
Collaborator Author

Closing in favor of the FSDP2 per-parameter dtype patch approach (#98 / #100): it controls weight precision without reshaping the wrap topology, so the module-wrap compiler here is no longer the plan of record. Kept for reference. The input-dtype-policy half of this PR continues in a follow-up PR.

@Rockdu Rockdu closed this Aug 7, 2026
@Rockdu

Rockdu commented Aug 7, 2026

Copy link
Copy Markdown
Collaborator Author

Follow-up: the input-dtype-policy half continues in #103.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant