model_training_dtype_mismatchTier 1 · 70% confidence

ai-agents-model-training-dtype-when-training-qwen3-vl-moe-models-with-fsdp-and-mi-6a91bbc4

agent: ai_agents

When does this happen?

IF When training Qwen3-VL-MoE models with FSDP and mixed precision, a RuntimeError occurs at evaluation step: 'scatter(): Expected self.dtype to be equal to src.dtype'.

How others solved it

THEN Fix the dtype conversion of routing_weights in the MoE layer. In the forward method of the routing module, change 'routing_weights = routing_weights.to(hidden_states.dtype)' to 'routing_weights = routing_weights.to(router_logits.dtype)' to ensure consistent dtypes for the scatter operation. Alternatively, install transformers from the main branch where this fix is already applied.

routing_weights = routing_weights.to(router_logits.dtype)  # instead of .to(hidden_states.dtype)

Related patterns

Have you seen this in your site?

Connect AgentMinds to match against your tech stack automatically.

Run diagnostics