Skip to content

[xmc] Keep constant payload type in PushTransposeThroughBinaryWithConst - #1083

Merged
sambanerxilinxamd merged 3 commits into
Xilinx:feature/onnx-to-tosafrom
nvunnam57128:nvunnam.fix-transpose-binary-const-float-payload
Oct 21, 2026
Merged

sambanerxilinxamd merged 3 commits into
Xilinx:feature/onnx-to-tosafrom
nvunnam57128:nvunnam.fix-transpose-binary-const-float-payload

Conversation

@nvunnam57128

Copy link
Copy Markdown

The pattern rebuilt the transposed constant using the storage type of the constant's result type. When the payload has a different element type (e.g. f32 data behind a !quant.uniformi8:f32 result), the splat path asserted in DenseElementsAttr::get ("expected float attribute type to equal element type") and the non-splat path reinterpreted the f32 bytes as i8, silently producing wrong values.

Rebuild the payload in its own element type and iterate it as mlir::Attribute; the result type (including per-axis quant remapping) is unchanged.

Comment thread src/Dialect/ONNX/Transforms/xmc/ONNXTransposeOptimizationPass.cpp Outdated
@rachgupt93

Copy link
Copy Markdown

Better can we just add transpose into constant and let constant folding take care instead of we doing it while moving tranpose down

@nvunnam57128
nvunnam57128 force-pushed the nvunnam.fix-transpose-binary-const-float-payload branch from be29ce4 to ca3b4bb Compare October 20, 2026 06:58
The pattern rebuilt the transposed constant using the storage type of the
constant's result type. When the payload has a different element type
(e.g. f32 data behind a !quant.uniform<i8:f32> result), the splat path
asserted in DenseElementsAttr::get ("expected float attribute type to equal
element type") and the non-splat path reinterpreted the f32 bytes as i8,
silently producing wrong values.

Rebuild the payload in its own element type and iterate it as
mlir::Attribute; the result type (including per-axis quant remapping) is
unchanged.
Allow non-splat f16 constants through the payload-type check and add a lit test that checks the transposed f16 values.
…BinaryWithConst

Instead of transposing the constant's data in the pattern, feed the binary
op Transpose(const, invPerm) and let ConstPropONNXToONNXPass, which runs
right after this pass in the XMC pipeline, fold it. Folding uses
OnnxElementsAttrBuilder::transpose, which works on the payload's own element
type, so the per-type handling is no longer needed.

Value tests move to onnx_transpose_optimization_const_fold.mlir, which runs
both passes; the pass-only test checks the inserted Transpose.
@nvunnam57128
nvunnam57128 force-pushed the nvunnam.fix-transpose-binary-const-float-payload branch from ca3b4bb to e96ff21 Compare October 21, 2026 08:13
@sambanerxilinxamd
sambanerxilinxamd merged commit 2e4f873 into Xilinx:feature/onnx-to-tosa Oct 21, 2026
3 checks passed
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.

3 participants