Conversation
This branch has not been deployed
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.
Summary
The torch
geluconverter only readsapproximatewhen it arrives as a positional input, which is how TorchScript serializes it. torch.export and the ExecuTorch edge dialect keep it as a keyword argument (aten.gelu.default(x, approximate='tanh')), sonn.GELU(approximate="tanh")silently converts to the exact gelu on those frontends.This affects every model that uses the tanh variant, most visibly the Hugging Face
gelu_pytorch_tanhactivation (ACT2FN["gelu_pytorch_tanh"]wrapsnn.functional.gelu(approximate="tanh")), which is the default activation of the Gemma / Gemma 2 / Gemma 3 configs and of SigLIP and RecurrentGemma among others. The two gelu variants differ by up to ~5e-4 per activation, and the existingtest_geluruns withatol=1e-3, which is why the mismatch never showed up.Minimal reproduction on
main:Implementation
gelunow falls back to_get_kwinputs(context, node, "approximate")when the argument is not positional, unwraps aVar, and maps"tanh"toTANH_APPROXIMATION. Any value other than"none"/"tanh"raises aValueErrorinstead of tripping an assertion."none"and"tanh"are added toTORCH_STRING_ARGSso the export frontend binds them without the "neither a name of existing var nor a torch string argument" warning.TorchScript behaviour is unchanged.
Tests
test_gelukeeps its tolerance but now also asserts themodeof the emittedgeluop (EXACTvsTANH_APPROXIMATION) for every frontend. Onmainthe new assertion fails for the TORCHEXPORT and EXECUTORCHapproximate="tanh"cases and passes for TorchScript; with this change all 45test_gelucases pass, andTestActivationshows no new failures compared tomain.