Skip to content

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

Draft
Rockdu wants to merge 8 commits into
radixark:mainfrom
Rockdu:feat/fsdp-precision-control
Draft

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

Conversation

@Rockdu

@Rockdu Rockdu commented Aug 3, 2026

Copy link
Copy Markdown
Collaborator

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>
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