Skip to content

Fix INT16 TABLE virtual endpoint (#21629) - #21629

Open
WongJohnson wants to merge 1 commit into
pytorch:mainfrom
WongJohnson:export-D115076485
Open

Fix INT16 TABLE virtual endpoint (#21629)#21629
WongJohnson wants to merge 1 commit into
pytorch:mainfrom
WongJohnson:export-D115076485

Conversation

@WongJohnson

@WongJohnson WongJohnson commented Aug 7, 2026

Copy link
Copy Markdown
Contributor

Summary:

TOSA INT16 TABLE stores 513 values for 512 fixed 128-code interpolation intervals. The final value is a virtual sample at affine code 32768: valid input 32767 uses table[511] as its base and table[512] to calculate the final interval's slope.

The previous generator clamped the virtual coordinate to 32767, cast it to INT16, and then cleared the lower seven bits. This reduced the final sample to 32640, duplicating table[511] and creating a zero-slope plateau over inputs [32640, 32767]. Any activation expecting a change in value over this upper range will see an error (e.g. ReLU-like activations [expected slope == 1 vs 0] and exp [growing slope])

When the input uses the full INT16 upper range, evaluate table[512] directly as:

(32768 - input_zero_point) * input_scale

This preserves the virtual coordinate without attempting to store it in INT16. Restricted input ranges retain the existing clamp-then-align behavior and do not use the virtual full-range endpoint.

Add focused identity-LUT tests that make the expected affine behavior explicit:

  • equal zero-point-zero qparams produce an antisymmetric table;
  • changing only zero point offsets every table value by the zero-point delta;
  • changing only scale applies the input/output scale ratio, including at code 32768;
  • restricting qmax clamps the last value instead of injecting the full-range endpoint.

Differential Revision: D115076485

@pytorch-bot

pytorch-bot Bot commented Aug 7, 2026

Copy link
Copy Markdown

🔗 Helpful Links

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

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

✅ No Failures

As of commit 60a4eb0 with merge base 99924e4 (image):
💚 Looks good so far! There are no failures yet. 💚

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

@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 Aug 7, 2026
@meta-codesync

meta-codesync Bot commented Aug 7, 2026

Copy link
Copy Markdown
Contributor

@WongJohnson has exported this pull request. If you are a Meta employee, you can view the originating Diff in D115076485.

@github-actions

github-actions Bot commented Aug 7, 2026

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.

@meta-codesync meta-codesync Bot changed the title Fix INT16 TABLE virtual endpoint Fix INT16 TABLE virtual endpoint (#21629) Aug 7, 2026
WongJohnson added a commit to WongJohnson/executorch that referenced this pull request Aug 7, 2026
Summary:

TOSA INT16 TABLE stores 513 values for 512 fixed 128-code interpolation intervals. The final value is a virtual sample at affine code 32768: valid input 32767 uses table[511] as its base and table[512] to calculate the final interval's slope.

The previous generator clamped the virtual coordinate to 32767, cast it to INT16, and then cleared the lower seven bits. This reduced the final sample to 32640, duplicating table[511] and creating a zero-slope plateau over inputs [32640, 32767]. Any activation expecting a change in value over this upper range will see an error (e.g. ReLU-like activations [expected slope == 1 vs 0] and exp [growing slope])

When the input uses the full INT16 upper range, evaluate table[512] directly as:

```
(32768 - input_zero_point) * input_scale
```

This preserves the virtual coordinate without attempting to store it in INT16. Restricted input ranges retain the existing clamp-then-align behavior and do not use the virtual full-range endpoint.

Add focused identity-LUT tests that make the expected affine behavior explicit:
- equal zero-point-zero qparams produce an antisymmetric table;
- changing only zero point offsets every table value by the zero-point delta;
- changing only scale applies the input/output scale ratio, including at code 32768;
- restricting qmax clamps the last value instead of injecting the full-range endpoint.

Differential Revision: D115076485
Summary:

TOSA INT16 TABLE stores 513 values for 512 fixed 128-code interpolation intervals. The final value is a virtual sample at affine code 32768: valid input 32767 uses table[511] as its base and table[512] to calculate the final interval's slope.

The previous generator clamped the virtual coordinate to 32767, cast it to INT16, and then cleared the lower seven bits. This reduced the final sample to 32640, duplicating table[511] and creating a zero-slope plateau over inputs [32640, 32767]. Any activation expecting a change in value over this upper range will see an error (e.g. ReLU-like activations [expected slope == 1 vs 0] and exp [growing slope])

When the input uses the full INT16 upper range, evaluate table[512] directly as:

```
(32768 - input_zero_point) * input_scale
```

This preserves the virtual coordinate without attempting to store it in INT16. Restricted input ranges retain the existing clamp-then-align behavior and do not use the virtual full-range endpoint.

Add focused identity-LUT tests that make the expected affine behavior explicit:
- equal zero-point-zero qparams produce an antisymmetric table;
- changing only zero point offsets every table value by the zero-point delta;
- changing only scale applies the input/output scale ratio, including at code 32768;
- restricting qmax clamps the last value instead of injecting the full-range endpoint.

Differential Revision: D115076485
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ciflow/trunk CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. meta-exported module: arm Issues related to arm backend

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant