Repository navigation
[FIX][Relax] Handle PrimValue operands in binary layout inference - #20617
Open
Kaustubh1235 wants to merge 1 commit into
Open
Kaustubh1235 wants to merge 1 commit into
Kaustubh1235 wants to merge 1 commit into
Conversation
InferLayoutBinaryEwise casts both operands to TensorTypeNode and then dereferences the results. A PrimValue carries a PrimType, so the cast returns null for it and ConvertLayout segfaults on an expression such as add(x, float32(1)). GetNLayout falls through to InitUnknownDim() for a non-tensor argument rather than failing, and the dispatch guard in GetInferLayoutInfo only inspects arguments where IsNestedTensor holds, so such an argument reaches the function unnoticed. Keep both operands on the layouts they already have and let the result follow the tensor operand. Passing the PrimValue's existing layout through rather than an empty one matters, because RewriteExpr leaves an expression alone only when the source and target layouts agree.
Author
|
Rebased cleanly on main, all five CI jobs green. Small null-check in |
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.
ConvertLayoutsegfaults on a binary op whose operand is aPrimValue, as inadd(x, float32(1)). Reported in #20608.InferLayoutBinaryEwisecasts both operands withGetTypeAs<TensorTypeNode>and then dereferences the results. APrimValuecarries aPrimType, so the cast returns null for it. Nothing upstream stops that from reaching here:GetNLayoutfalls through toInitUnknownDim()for a non-tensor argument rather than failing, and the dispatch guard inGetInferLayoutInfoonly inspects arguments for whichIsNestedTensorholds, so aPrimValueargument passes it unnoticed.This keeps both operands on the layouts they already have and lets the result follow the tensor operand. Passing the
PrimValue's existing layout through is what avoids a second failure:RewriteExprreturns the expression unchanged only when the source and target layouts are equal, or when the source layout name is empty, so returningLayoutDecision("")for an operand whose current layout isInitUnknownDim()trades the segfault for anICHECKon "Cannot convert when exactly one of the layouts is unknown". Leaving the operand alone also keeps layout conversion propagating through a scalar add rather than falling back to the initial layout.Testing
test_binary_ewise_prim_value_scalaris thePrimValuetwin of the existingtest_binary_ewise_scalar, which covers the 0-dim tensor form of the same expression. It segfaults the interpreter (exit 139) without this change and passes with it.tests/python/relax/test_transform_convert_layout.py: 76 passed.tests/python/relax: 3028 passed, 221 failed, 256 skipped, 25 collection errors. Reverting just thebinary.ccchange and deselecting the new test gives a byte-identical set of 221 failures and 25 errors, so those are pre-existing CUDA/Metal/WebGPU/LLVM cases this build cannot run. The passing count moves 3027 -> 3028, the new test.clang-format(repo.clang-format) andruff 0.12.3checkandformat --check, as pinned in.pre-commit-config.yaml, are clean on both files.Built without LLVM, so the
relax.build(target="llvm")step in the report is not exercised here. The crash is in layout inference and reproduces fromConvertLayoutalone.