Skip to content

Cortex-M backend: lower quantized GELU via the activation LUT#21025

Open
rascani wants to merge 1 commit into
pytorch:mainfrom
rascani:cortexm-gelu-lut
Open

Cortex-M backend: lower quantized GELU via the activation LUT#21025
rascani wants to merge 1 commit into
pytorch:mainfrom
rascani:cortexm-gelu-lut

Conversation

@rascani

@rascani rascani commented Jul 17, 2026

Copy link
Copy Markdown
Contributor

Summary

Extend the existing sigmoid/tanh/silu activation-LUT path to GELU: add an exact (erf) _gelu to _ACTIVATION_FNS, register aten.gelu in the quantizer's ACTIVATION_OP_PATTERNS (the generic CortexMActivationCheck needs no change), and add aten.gelu to the quantized_activation dialect substitution. Unlike silu, aten.gelu is a core-aten op that survives to_edge unchanged, so no to_edge preservation is required. build_activation_lut only sees the op target, so the table is always the exact/erf GELU regardless of the approximate kwarg.

Test plan

Verified test-first (RED->GREEN) with five nn.GELU() dialect cases (ramp / saturating / asymmetric-zp / zero) whose numerics are validated against the reference (qtol=1); the full cortex_m op dialect suite still passes (177 passed).

Authored with Claude Code.

Extend the existing sigmoid/tanh/silu activation-LUT path to GELU: add an exact (erf) _gelu to _ACTIVATION_FNS, register aten.gelu in the quantizer's ACTIVATION_OP_PATTERNS (the generic CortexMActivationCheck needs no change), and add aten.gelu to the quantized_activation dialect substitution. Unlike silu, aten.gelu is a core-aten op that survives to_edge unchanged, so no to_edge preservation is required. build_activation_lut only sees the op target, so the table is always the exact/erf GELU regardless of the approximate kwarg -- fine for an int8 LUT.

Verified test-first (RED->GREEN) with five nn.GELU() dialect cases (ramp / saturating / asymmetric-zp / zero) whose numerics are validated against the reference (qtol=1); the full cortex_m op dialect suite still passes (177 passed). This removes the last non-normalization fp32 activation from a SAM mask decoder's two-way transformer.

Authored with Claude Code.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@pytorch-bot

pytorch-bot Bot commented Jul 17, 2026

Copy link
Copy Markdown

🔗 Helpful Links

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

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

❗ 2 Merge Blocking SEVs

There is 2 active merge blocking SEVs. Please view them below:

If you must merge, use @pytorchbot merge -f.

❌ You can merge normally! (1 Unrelated Failure), 1 Unclassified Failure

As of commit f9d4f41 with merge base 7013c8d (image):

UNCLASSIFIED FAILURE - DrCI could not classify the following job because the workflow did not run on the merge base. The failure may be pre-existing on trunk or introduced by this PR:

BROKEN TRUNK - The following job failed but were present on the merge base:

👉 Rebase onto the `viable/strict` branch to avoid these failures

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

@rascani
rascani requested a review from AdrianLundell July 17, 2026 20:33
@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 Jul 17, 2026
@github-actions

Copy link
Copy Markdown

This PR needs a release notes: label

If your change should be included in the release notes (i.e. would users of this library care about this change?), please use a label starting with release notes:. This helps us keep track and include your important work in the next release notes.

To add a label, you can comment to pytorchbot, for example
@pytorchbot label "release notes: none"

For more information, see
https://github.com/pytorch/pytorch/wiki/PyTorch-AutoLabel-Bot#why-categorize-for-release-notes-and-how-does-it-work.

@rascani
rascani requested a review from psiddh July 17, 2026 21:38
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.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant