Promote int alpha/beta in torch.addmm and torch.baddbmm - #2779
Open
LeSingh1 wants to merge 1 commit into
Open
Conversation
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.
Collaborator
|
This looks good. CI: https://gitlab.com/coremltools1/coremltools/-/pipelines/2735363140 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
torch.addmmandtorch.baddbmmdeclarebetaandalphaasScalar, so an integer literal is legal even when the tensors are float. Both converters passed the scalar straight tomb.mul, which requires matching dtypes, so conversion failed:Writing
2.0works. The same happens foralphain both ops.baddbmmalready castsbetafor this reason (#1925) but never did the same foralpha, andaddmmdoes neither. This routes all three scalars throughpromote_input_dtypes, the helper already used for this throughoutops.py.Tests:
test_addmmgains int values in its existingbeta/alphaparameters;test_baddbmmgains analphaparameter, which it previously never exercised. Revertingops.pyfails 32 of those tests with the dtype error above.