Conversation
The backend previously lowered tanh GELU to exact GELU. Use XNNPACK's existing approxgelu operation and add regression tests.
🔗 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.
|
|
Hi @sqliangx! Thank you for your pull request and welcome to our community. Action RequiredIn 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. ProcessIn 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 If you have received this in error or have any questions, please contact us at cla@meta.com. Thanks! |
|
|
|
@pytorchbot label "release notes: xnnpack" |
|
Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Meta Open Source project. Thanks! |
Summary
The XNNPACK backend currently ignores GELU's
approximateargument and serializes both modes asXNNGelu. 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 approximately4.73e-4, failing comparison atatol=rtol=1e-5.This PR serializes tanh GELU as
XNNApproxGeluand dispatches it to XNNPACK's existingxnn_unary_approxgeluoperation. 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 newtest_fp32_gelu_tanhregression inbackends/xnnpack/test/ops/test_gelu.pyfails before the fix and passes afterward atatol=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.