Fix INT16 TABLE virtual endpoint (#21629) - #21629
Conversation
🔗 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 FailuresAs of commit 60a4eb0 with merge base 99924e4 ( This comment was automatically generated by Dr. CI and updates every 15 minutes. |
|
@WongJohnson has exported this pull request. If you are a Meta employee, you can view the originating Diff in D115076485. |
This PR needs a
|
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
88fcd23 to
3582d96
Compare
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
3582d96 to
60a4eb0
Compare
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:
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:
Differential Revision: D115076485