Skip to content

fix: default cast_forward_inputs to False (match FSDP2, avoid corrupting fp32 activations) - #15

Merged
StarrickLiu merged 1 commit into
mainfrom
fix/cast-forward-inputs-default-false
Jul 21, 2026
Merged

StarrickLiu merged 1 commit into
mainfrom
fix/cast-forward-inputs-default-false

Conversation

@StarrickLiu

Copy link
Copy Markdown
Collaborator

DedicatedState._pre_forward force-casts every floating-point tensor in a wrapped module's forward args/kwargs (recursing into tuple/list/dict) to the group's param_dtype when cast_forward_inputs is enabled. With the previous default of True, this silently downcast fp32 activations that must stay fp32 — e.g. a qwen2.5-VL model passes its rope cos/sin as an fp32 position_embeddings tuple through the decoder layers, which got cast to bf16 and then rejected by the rope CUDA kernel (cos.scalar_type() == at::kFloat), crashing pure-DMuon training. AdamW + FSDP2 was unaffected because torch FSDP2's MixedPrecisionPolicy.cast_forward_inputs defaults to False.

Flip the default to False everywhere (policy dataclass field, the getattr fallbacks in state/api/diagnostics, and the ddp/fsdp2 backend param defaults), matching FSDP2. Activation casting for mixed-precision compute is then handled by autocast, and callers that genuinely want input casting can still set cast_forward_inputs=True explicitly.

…ing fp32 activations)

DedicatedState._pre_forward force-casts every floating-point tensor in a wrapped
module's forward args/kwargs (recursing into tuple/list/dict) to the group's
param_dtype when cast_forward_inputs is enabled. With the previous default of
True, this silently downcast fp32 activations that must stay fp32 — e.g. a
qwen2.5-VL model passes its rope cos/sin as an fp32 `position_embeddings` tuple
through the decoder layers, which got cast to bf16 and then rejected by the
rope CUDA kernel (`cos.scalar_type() == at::kFloat`), crashing pure-DMuon
training. AdamW + FSDP2 was unaffected because torch FSDP2's
MixedPrecisionPolicy.cast_forward_inputs defaults to False.

Flip the default to False everywhere (policy dataclass field, the getattr
fallbacks in state/api/diagnostics, and the ddp/fsdp2 backend param defaults),
matching FSDP2. Activation casting for mixed-precision compute is then handled
by autocast, and callers that genuinely want input casting can still set
cast_forward_inputs=True explicitly.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@StarrickLiu
StarrickLiu merged commit 32e97c9 into main Jul 21, 2026
2 checks passed
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