FastGeluFusion removes a half-x node that still has another consumer
Describe the issue
FastGeluFusion accepts the internal X * 0.5 node even when its output half_x has a consumer outside the pattern, and then removes that node. The external consumer is left with an input that has no producer, so session initialization at Extended/All rejects the optimized graph.
Expected: skip the fusion when an intermediate value has an external consumer.
Related: #32016 added validation of the scale Mul node, but it does not cover this fan-out case, which still reproduces on v1.30.0.
To reproduce
Requires Python 3.12, numpy==2.5.3 and an ONNX Runtime build with CPUExecutionProvider available. Attach minimal_model.onnx to the issue. Save the attached model beside the following code as repro.py, then run python repro.py from that directory. If the attachment is a ZIP archive, extract minimal_model.onnx first.
"""FastGeluFusion removes a half-x node that still has another consumer"""
from pathlib import Path
import numpy as np
import onnxruntime as ort
model = Path(__file__).with_name("minimal_model.onnx")
rng = np.random.default_rng(9419)
feed = {
'X': rng.standard_normal((1, 4)).astype(np.float32),
}
def session(providers, level, disabled_optimizers=None):
options = ort.SessionOptions()
options.graph_optimization_level = getattr(ort.GraphOptimizationLevel, level)
return ort.InferenceSession(str(model), options, providers=providers,
disabled_optimizers=disabled_optimizers or set())
reference = session(["CPUExecutionProvider"], "ORT_DISABLE_ALL").run(None, feed)[0]
print("reference shape:", reference.shape)
try:
actual = session(["CPUExecutionProvider"], "ORT_ENABLE_ALL").run(None, feed)[0]
except Exception as error:
print("target error:", error)
reproduced = 'half_x' in str(error)
print("REPRODUCED" if reproduced else "NOT REPRODUCED")
raise SystemExit(0 if reproduced else 1)
print("target shape:", actual.shape)
print("NOT REPRODUCED")
raise SystemExit(1)Observed result
On v1.30.0: ✅ reproduced — Invalid model. Node input 'half_x' is not a graph input, initializer, or output of a previous node..
Urgency
No deadline; this is a session creation or runtime failure on a valid model.
System information
- Platform: Mac
- OS Version: macOS 26.5.1 (25F80)
- ONNX Runtime Installation: Built from Source (Python wheel)
- ONNX Runtime Version or Commit ID: v1.30.0 (f2c39fe2f838cf35ce7da92824f5a5e3ee6e88a7)
- ONNX Runtime API: Python 3.12
- Architecture: ARM64
- Execution Provider: Default CPU
Source: microsoft/onnxruntime