Skip to content

[upstream #3137] [upstream_ut] RuntimeError: expected scalar type Half but found Float#24

Draft
Stonepia wants to merge 1 commit into
mainfrom
agent/issue-270
Draft

[upstream #3137] [upstream_ut] RuntimeError: expected scalar type Half but found Float#24
Stonepia wants to merge 1 commit into
mainfrom
agent/issue-270

Conversation

@Stonepia

@Stonepia Stonepia commented May 19, 2026

Copy link
Copy Markdown
Collaborator

[upstream pytorch#3137] [upstream_ut] RuntimeError: expected scalar type Half but found Float

Fixes https://github.com/intel-sandbox/torch-xpu-ops-exp/issues/270

Root Cause: torch.is_autocast_enabled() at transformer.py:865 (and :490) checks only the default device type (cuda) for autocast. When XPU autocast is active, this returns False, so the fastpath is not disabled. The fused _transformer_encoder_layer_fwd then receives fp16 src (cast by autocast) alongside fp32 weights, causing the dtype mismatch.

Failed Tests:

  • test_transformers_xpu.py::TestTransformersXPU::test_transformerencoder_fastpath_use_torchscript_False_enable_nested_tensor_True_use_autocast_True_d_model_12_xpu
  • test_transformers_xpu.py::TestTransformersXPU::test_transformerencoder_fastpath_use_torchscript_False_enable_nested_tensor_False_use_autocast_True_d_model_256_xpu
  • test_transformers_xpu.py::TestTransformersXPU::test_transformerencoder_fastpath_use_torchscript_False_enable_nested_tensor_False_use_autocast_True_d_model_12_xpu
  • test_transformers_xpu.py::TestTransformersXPU::test_transformerencoder_fastpath_use_torchscript_False_enable_nested_tensor_True_use_autocast_True_d_model_256_xpu

Diff stat:

torch/nn/modules/transformer.py | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

[upstream pytorch#3137] [upstream_ut]  RuntimeError: expected scalar type Half but found Float
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