Repository navigation
Conversation
The function body uses signless integers, so the sum, sum.dim_IntList and prod payloads must take the signedness from the torch dtypes. They converted the input element without the original dtypes, which sign-extended uint8 values of 128 and above and crashed when the result is an 8-bit integer. Pass the input and result torch dtypes to convertScalarToDtype, and return a match failure when the conversion fails.
The init value of the full max/min reductions read the signedness from the builtin element type, which is signless, and skipped 8-bit integers, leaving a null init that crashed the pattern. Unsigned 16/32/64-bit reductions started from the signed limit. Read the signedness from the torch dtype for every integer width, and return a match failure when no init value can be created.
Integer compares widened operands without their torch dtypes, so uint8 values of 128 and above were sign-extended, and bool vs 8-bit compares crashed. - An int scalar, or a 0-d tensor compared with a dimensioned one, is cast to the dtype of the other integer operand, as PyTorch does. Out-of-range values now wrap, which also changes the result for signed tensors. - Mixed-width tensor compares extend each side with its own signedness and compare in the wider operand's dtype. - Integer to float conversions pass the source torch dtype. The TOSA and StableHLO backends promote the 0-d operand instead of casting it, so the new 0-d e2e tests are added to their xfail sets.
aten.cat converted operands whose dtype differs from the result with convertScalarToDtype and no original dtypes, so a uint8 operand concatenated with a float tensor went through sitofp. Let convertTensorToElementType take the original torch dtypes and pass them from the cat lowering.
remainder.Scalar and remainder.Tensor emitted remsi with the signed sign fix-up for uint8 and crashed on 8-bit results, because the operands were converted without the result torch dtype. Pass the torch dtypes to the conversions and let createRemainder emit remui without a sign fix-up for unsigned results.
threshold and threshold_backward compared with sle and crashed on 8-bit types, because the threshold and value scalars were converted without the torch dtype. Pass the torch dtypes to the conversions and compare with ule for unsigned inputs.
sahas3
marked this pull request as ready for review
November 23, 2026 14:13
Member
Author
This branch has not been deployed
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.
TorchToLinalg converts torch tensors to signless builtin tensors, so every integer conversion has to take its signedness from the torch dtype. Several lowerings converted values without the torch dtype. As a result, uint8 values of 128 and above were sign-extended, and some patterns crashed when the result had an 8-bit integer type. This PR passes the source and result torch dtypes to
convertScalarToDtypein these lowerings, and returns a match failure when a conversion fails, so a null value no longer crashes the pattern.Each commit fixes one group of ops, so it maybe easier to review each commit individually:
convertTensorToElementTypetakes the original torch dtypes, so a uint8 operand concatenated with a float tensor usesuitofpinstead ofsitofp.remuiwithout the signed sign fix-up.ule.Behavior change for compares. An int scalar is now cast to the dtype of the integer tensor it is compared with, as PyTorch does. The same goes for a 0-d tensor compared with a dimensioned one. Out-of-range values now wrap, and this also changes results for signed tensors. For example, an int8 tensor compared with 200 now compares against -56.
Assisted By: Claude