﻿# ONNX Runtime Gemm fusion: a transpose can be internal input and public output at once

The 1.32 GemmTransposeFusion repair preserves public output producers; internal algebraic equivalence cannot replace the model’s full output contract.

Author: Retrivium team
Updated: 2026-11-15
Canonical URL: https://retrivium.ai/journal/week46-engine-ort-gemm-transpose-public-output-producer/
Language: en

ONNX Runtime 1.32.0 includes a Gemm transpose-fusion repair that preserves public graph outputs. The PR describes a transpose feeding Gemm while also producing a declared model output. Folding it solely because Gemm can absorb its effect removes an externally visible producer, even if the final matrix result would otherwise be equivalent.

## Consumers are not only downstream nodes

A graph value can be consumed by another node and by the caller as a model output. A transformation that examines only internal consumers misses the second relationship. The PR repeats the public-output safety check when processing each input transpose. This protects the complete output interface rather than only the Gemm value. A test that requests only the final matrix can therefore miss a broken public intermediate.

## One safe input does not make the other safe

Gemm can have transpose-related opportunities on both inputs. The PR explains how admission based on one safe case was followed by processing that did not preserve the same condition for the other. A proposed regression should make either input public in separate cases, then make both public. This checks the per-input condition and prevents a broad “some match exists” result from authorizing every nearby rewrite.

## Validate the graph interface before timing

Compare output names and producers as well as numerical tensors. If the optimized session cannot resolve a declared output, there is no valid performance result to compare with the unoptimized graph. Keep transA and transB combinations in coverage because attribute folding changes the remaining operation. A smaller node count is not an acceptance criterion when the model interface has lost a value promised to callers.

## The release preserves selective optimization

The correction allows a separate safe internal transpose to be folded while retaining a public one. It is not a blanket removal of Gemm fusion. This article reports the release repair and a regression structure, without claiming a new benchmark or suggesting that callers should delete public outputs to recover optimization. The correct reference is the original model’s full externally observable function and interface.

## Sources

- [ONNX Runtime v1.32.0 release](https://github.com/microsoft/onnxruntime/releases/tag/v1.32.0)
- [ONNX Runtime pull request #33484](https://github.com/microsoft/onnxruntime/pull/33484)

## Related reading

- [ONNX optional inputs: preserve positions when a middle argument is absent](/journal/fg2-onnx-optional-input-empty-placeholder-position/)
- [ONNX Runtime offline optimization: a saved optimized graph inherits a target contract](/journal/fg2-onnxruntime-offline-graph-target-compatibility/)
