Skip to content

Support ONNX opset 20 and faithful tanh GELU lowering - #23

Open
matthargett wants to merge 2 commits into
rustnn:mainfrom
rebeckerspecialties:fix/onnx-gelu-approximation
Open

matthargett wants to merge 2 commits into
rustnn:mainfrom
rebeckerspecialties:fix/onnx-gelu-approximation

Conversation

@matthargett

@matthargett matthargett commented Sep 27, 2026 •

Copy link
Copy Markdown

Support standard ONNX opsets 19/20 for implemented operators, including both GELU formulas. This replaces the initial fail-closed patch with tested tanh support.

  • Keep default/none GELU mapped to exact WebNN gelu; lower approximate="tanh" to the specified mul/add/tanh composition. Promote FP16 intermediates to FP32, then cast the result back. Reject malformed attributes and unsupported types.
  • Preserve scalar inputs, avoid generated-name collisions, and emit WebNN's positional cast signature. Validate unsupported types before file/CLI constant folding.
  • Audit opset changes: preserve AveragePool dilation and constant reduction axes, keepdims=0 and empty-axis semantics. Unsupported operators and dynamic axes remain explicit errors; accepting opset 20 does not imply complete ONNX coverage.

Validation:

  • 216 tests, formatting and strict all-target Clippy pass on Rust 1.97 and 1.98. Tests exercise actual file import with optimization on/off and generated JavaScript calls through a numerical builder double.
  • M4 CoreML: 72/72 tanh predictions pass against ONNX Runtime references through file import, graph conversion and typed dispatch. FP16/FP32, scalars, seeded tensors, 10,001-point sweeps, large tails and special values; CPU/GPU/NPU hints tested separately, without claiming hardware placement. Maximum finite absolute errors: FP32 9.54e-7, FP16 6.11e-5.

ONNX CTS already defines both formulas; WebNN WPT does not import ONNX. These regressions cover the missing importer boundary. Separately, native exact FP16 GELU under the NPU hint fails upstream ULP limits on this M4/macOS beta; that existing CoreML/harness issue is not a failure of the tanh decomposition and remains tracked in #257.

@matthargett matthargett changed the title Reject unsupported ONNX GELU approximations Support ONNX opset 20 and faithful tanh GELU lowering Sep 28, 2026

This branch has not been deployed

No deployments
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.

1 participant