Skip to content

Preserve input dtype in FuseBiasInLinear - #2533

Open
gorkadabo1 wants to merge 1 commit into
huggingface:mainfrom
gorkadabo1:fix/fuse-bias-linear-dtype-2532
Open

gorkadabo1 wants to merge 1 commit into
huggingface:mainfrom
gorkadabo1:fix/fuse-bias-linear-dtype-2532

Conversation

@gorkadabo1

Copy link
Copy Markdown

What does this PR do?

Fixes #2532

FuseBiasInLinear creates the appended ones tensor with the default dtype, which promotes float16 and bfloat16 inputs to float32 and causes a dtype mismatch with the fused weights.

This change passes linear_input.dtype to the existing torch_ones call, preserving the input dtype. It also adds five focused regression cases covering float32, float16, bfloat16, and conversion to reduced precision after transformation.

Validation

  • All 5 regression cases passed on CPU. Without the fix, only the float32 case passed, while the other 4 failed with the expected dtype mismatch.
  • Black, Ruff, and git diff --check passed.
  • The existing FX test suite previously passed (17 tests) in a compatible Transformers 4.x environment.

Tests were run on Hyperion with PyTorch 2.14.1 and Transformers 4.57.6.

Before submitting

  • Added regression tests.
  • Documentation changes are not needed for this fix.

Who can review?

@IlyasMoutawwakil

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.

FuseBiasInLinear fails with float16 and bfloat16 inputs

1 participant