Skip to content

Promote int alpha/beta in torch.addmm and torch.baddbmm - #2779

Open
LeSingh1 wants to merge 1 commit into
apple:mainfrom
LeSingh1:fix-addmm-baddbmm-int-alpha-beta
Open

Promote int alpha/beta in torch.addmm and torch.baddbmm#2779
LeSingh1 wants to merge 1 commit into
apple:mainfrom
LeSingh1:fix-addmm-baddbmm-int-alpha-beta

Conversation

@LeSingh1

@LeSingh1 LeSingh1 commented Aug 5, 2026

Copy link
Copy Markdown
Contributor

torch.addmm and torch.baddbmm declare beta and alpha as Scalar, so an integer literal is legal even when the tensors are float. Both converters passed the scalar straight to mb.mul, which requires matching dtypes, so conversion failed:

torch.addmm(x, mat1, mat2, beta=2)   # x, mat1, mat2 are float
ValueError: In op, of type mul, named mul_0, the named input `y` must have the same data type
as the named input `x`. However, y has dtype int32 whereas x has dtype fp32.

Writing 2.0 works. The same happens for alpha in both ops.

baddbmm already casts beta for this reason (#1925) but never did the same for alpha, and addmm does neither. This routes all three scalars through promote_input_dtypes, the helper already used for this throughout ops.py.

Tests: test_addmm gains int values in its existing beta/alpha parameters; test_baddbmm gains an alpha parameter, which it previously never exercised. Reverting ops.py fails 32 of those tests with the dtype error above.

torch.addmm and torch.baddbmm take alpha and beta as Scalars, so an integer
literal is legal even when the tensors are float. The converters passed the
scalar straight to mb.mul, which rejects mixed dtypes, so
torch.addmm(x, m1, m2, beta=2) failed to convert with "the named input `y`
must have the same data type as the named input `x`. However, y has dtype
int32 whereas x has dtype fp32". Writing 2.0 instead worked.

baddbmm already cast beta for this reason but not alpha. Use
promote_input_dtypes for both scalars in addmm and for alpha in baddbmm.

Extended test_addmm's beta/alpha parameters with int values, and added an
alpha parameter to test_baddbmm.
@TobyRoseman

Copy link
Copy Markdown
Collaborator

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.

2 participants