Repository navigation
ONNX export: fused GELU operator in the matcher - #6
Merged
Merged
Conversation
This was referenced Oct 28, 2026
sarlinpe
force-pushed
the
sarlinpe/onnx-fused-gelu
branch
from
October 28, 2026 23:56
61b653a to
7e6dd4b
Compare
sarlinpe
force-pushed
the
sarlinpe/onnx-fused-gelu
branch
from
October 29, 2026 00:10
7e6dd4b to
e2419e7
Compare
sarlinpe
force-pushed
the
sarlinpe/onnx-fused-gelu
branch
from
October 29, 2026 00:49
e2419e7 to
600a393
Compare
sarlinpe
force-pushed
the
sarlinpe/onnx-fused-gelu
branch
from
October 29, 2026 05:44
600a393 to
6f99534
Compare
Export the GELU activations of the matcher as ONNX Runtime's com.microsoft::Gelu operator instead of Div/Erf/Add/Mul/Mul, which ONNX Runtime does not fuse, by swapping the nn.GELU modules of the exported copy of the matcher. This saves about 0.9 ms of GPU time per pair with the float16 matcher. --no_fused_attention also disables it.
sarlinpe
force-pushed
the
sarlinpe/onnx-fused-gelu
branch
from
October 30, 2026 02:26
6f99534 to
212c0c8
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Stacked on #5. This PR exports the GELU activations of the matcher as ONNX Runtime's
com.microsoft::Geluoperator (exact, erf-based) instead ofDiv/Erf/Add/Mul/Mul.Why
Div(√2) → Erf → Add(1) → Mul(0.5) → Mul(x)). Each of the 36 GELUs per pair therefore runs as five element-wise kernels over a 4096×512 tensor.nn.GELUmodules of the exported copy of the matcher for a custom op, which the translation table maps to the fused operator (as for the attention).--no_fused_attentiondisables both, for standard ONNX operators.Results
GPU time per pair: ONNX Runtime 1.23, A100, N = 2048, CUPTI kernel profile, device-resident I/O.
Disabling ONNX Runtime's
MatMulAddFusionwould save another ~1.4 ms on this setup. That was not adopted, because it depends on cuBLAS's kernel choice; see colmap/colmap#4914.Parity:
python onnx/check.pypasses (N = 512 / 2048 / 4096,min_covisibility0 / 0.8):F.gelu.