EliminateDropout removes active training-mode Dropout
Describe the issue
At Basic optimization level, EliminateDropout removes a Dropout node whose mask output is unused without checking training_mode. The model uses training_mode=true and ratio=0.8. The unoptimized run drops and scales values, while the optimized output is exactly the input. On v1.30.0, 50 of 64 values were zero without optimization, versus none with Basic optimization.
Expected: an active training-mode Dropout is not eliminated.
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.
"""CPU EliminateDropout training-mode miscompilation"""
import numpy as np
import onnxruntime as ort
def session(providers, level, model="minimal_model.onnx"):
options = ort.SessionOptions()
options.graph_optimization_level = getattr(ort.GraphOptimizationLevel, level)
return ort.InferenceSession(str(model), options, providers=providers)
rng = np.random.default_rng(9419)
feed = {
"X": rng.standard_normal((1, 64)).astype(np.float32),
}
# Dropout(ratio=0.8, training_mode=True) must zero out elements; removing it returns X unchanged.
reference = session(['CPUExecutionProvider'], "ORT_DISABLE_ALL").run(None, feed)[0]
actual = session(['CPUExecutionProvider'], "ORT_ENABLE_BASIC").run(None, feed)[0]
print(f"onnxruntime {ort.__version__}: zeros disabled = {np.count_nonzero(reference == 0)}/64, "
f"zeros basic = {np.count_nonzero(actual == 0)}/64, basic output == X: {np.array_equal(actual, feed['X'])}")
reproduced = (reference == 0).any() and np.array_equal(actual, feed["X"])
print("REPRODUCED" if reproduced else "NOT REPRODUCED")
raise SystemExit(0 if reproduced else 1)Observed result
On v1.30.0: ✅ reproduced — 50/64 values were zero with optimizations disabled; 0/64 were zero and the output exactly matched the input with basic optimizations.
The zero count with optimizations disabled varies because Dropout is stochastic; the basic-optimization output matching the input is the failure condition.
Urgency
No deadline; this is a silent correctness issue.
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: 1.26.0; also reproduced on v1.30.0 (f2c39fe2f838cf35ce7da92824f5a5e3ee6e88a7)
- ONNX Runtime API: Python 3.12
- Architecture: ARM64
- Execution Provider: Default CPU
Source: microsoft/onnxruntime