Skip to content

XNNPACK: Route tanh GELU to approxgelu - #22851

Open
sqliangx wants to merge 1 commit into
pytorch:mainfrom
sqliangx:fix-xnnpack-gelu-tanh
Open

sqliangx wants to merge 1 commit into
pytorch:mainfrom
sqliangx:fix-xnnpack-gelu-tanh

Conversation

@sqliangx

Copy link
Copy Markdown

Summary

The XNNPACK backend currently ignores GELU's approximate argument and serializes both modes as XNNGelu. As a result, nn.GELU(approximate="tanh") executes exact GELU after delegation. For FP32 input [-2.7], the baseline differs from the tanh reference by approximately 4.73e-4, failing comparison at atol=rtol=1e-5.

This PR serializes tanh GELU as XNNApproxGelu and dispatches it to XNNPACK's existing xnn_unary_approxgelu operation. Default/exact GELU and FP16 fallback remain unchanged. The new node is appended to both FlatBuffer unions to preserve existing node IDs.

Affected XNNPACK models need to be re-exported, and the new node requires an updated runtime.

Test plan

I tested the fix on macOS arm64 using rebuilt runtimes based on 500849ba5b. The new test_fp32_gelu_tanh regression in backends/xnnpack/test/ops/test_gelu.py fails before the fix and passes afterward at atol=rtol=1e-5.

All 8 GELU tests passed, covering both approximation modes, static/dynamic shapes, and FP16 fallback. I also ran the selected neighboring unary tests: 23 passed in total, including those 8 GELU tests. Lintrunner passed.

Authored with assistance from OpenAI Codex.

The backend previously lowered tanh GELU to exact GELU. Use XNNPACK's existing approxgelu operation and add regression tests.
@pytorch-bot

pytorch-bot Bot commented Sep 15, 2026

Copy link
Copy Markdown

🔗 Helpful Links

🧪 See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/executorch/22851

Note: Links to docs will display an error until the docs builds have been completed.

⚠️ 14 Awaiting Approval

As of commit 688ac9c with merge base 500849b (image):

AWAITING APPROVAL - The following workflows need approval before CI can run:

This comment was automatically generated by Dr. CI and updates every 15 minutes.

@meta-cla

meta-cla Bot commented Sep 15, 2026

Copy link
Copy Markdown

Hi @sqliangx!

Thank you for your pull request and welcome to our community.

Action Required

In order to merge any pull request (code, docs, etc.), we require contributors to sign our Contributor License Agreement, and we don't seem to have one on file for you.

Process

In order for us to review and merge your suggested changes, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA.

Once the CLA is signed, our tooling will perform checks and validations. Afterwards, the pull request will be tagged with CLA signed. The tagging process may take up to 1 hour after signing. Please give it that time before contacting us about it.

If you have received this in error or have any questions, please contact us at cla@meta.com. Thanks!

@linux-foundation-easycla

linux-foundation-easycla Bot commented Sep 15, 2026

Copy link
Copy Markdown

CLA Signed
The committers listed above are authorized under a signed CLA.

  • ✅ login: sqliangx / name: Shiqi Liang (688ac9c)

@sqliangx

Copy link
Copy Markdown
Author

@pytorchbot label "release notes: xnnpack"

@pytorch-bot pytorch-bot Bot added the release notes: xnnpack Changes to the XNNPack backend delegate label Sep 15, 2026
@meta-cla

meta-cla Bot commented Sep 15, 2026

Copy link
Copy Markdown

Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Meta Open Source project. Thanks!

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Sep 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. release notes: xnnpack Changes to the XNNPack backend delegate

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants