Repository navigation
feat(quantization): support int8 with float8_e8m0fnu scales - #133
Open
dengqiaoyu wants to merge 3 commits into
Open
dengqiaoyu wants to merge 3 commits into
dengqiaoyu wants to merge 3 commits into
Conversation
dengqiaoyu
added a commit
to dengqiaoyu/coreai-optimization
that referenced
this pull request
Oct 23, 2026
- Drop an op-intrinsic asymmetric qscheme in `_build_concrete_spec` when the reconciled group has a floating-point dtype or an e8m0 scale. The op-intrinsic gate only sees the producing op's own config, so `sigmoid -> Linear` with an e8m0 consumer reconciled to int8 + e8m0 + asymmetric and failed validation (FP8 hit the same crash). Settling it after reconciliation avoids a cycle with `InheritFields`, which copies the op's value verbatim. - Re-raise the original exception from `prepare_qat_pt2e` with a note instead of rebuilding it via `type(e)(msg)`, which raised a `TypeError` for exceptions such as pydantic's `ValidationError` and hid the real error. - Run `validate_scale_dtype` before the qscheme/qformulation validators so an unsupported dtype or scale dtype gets the scale_dtype error first, rather than a request to change a field that isn't the problem. - Document int8 with e8m0 scales in the `QuantizationSpec` docstring: `target_max_pow2 = 6`, with OCP MXINT8's `2^-6` element factor folded into `scale`. - Add the changelog fragment for apple#133.
vineet-g
reviewed
Oct 30, 2026
| ) | ||
|
|
||
|
|
||
| @pytest.mark.parametrize("qparam_calculator_cls", ["default", "dynamic"]) |
Contributor
There was a problem hiding this comment.
add one more test for checking the clamping of MXINT8. Use x as torch.Tensor([[-3.99, 3.99]]).
scale = 2^(floor(log2(3.99)) - 6) = 2^-5; 3.99 / 2^-5 = 127.68
+127.68 rounds to 128 and clamps to 127; -127.68 rounds to -128, which int8 holds
dengqiaoyu
added a commit
to dengqiaoyu/coreai-optimization
that referenced
this pull request
Oct 30, 2026
- Drop an op-intrinsic asymmetric qscheme in `_build_concrete_spec` when the reconciled group has a floating-point dtype or an e8m0 scale. The op-intrinsic gate only sees the producing op's own config, so `sigmoid -> Linear` with an e8m0 consumer reconciled to int8 + e8m0 + asymmetric and failed validation (FP8 hit the same crash). Settling it after reconciliation avoids a cycle with `InheritFields`, which copies the op's value verbatim. - Re-raise the original exception from `prepare_qat_pt2e` with a note instead of rebuilding it via `type(e)(msg)`, which raised a `TypeError` for exceptions such as pydantic's `ValidationError` and hid the real error. - Run `validate_scale_dtype` before the qscheme/qformulation validators so an unsupported dtype or scale dtype gets the scale_dtype error first, rather than a request to change a field that isn't the problem. - Document int8 with e8m0 scales in the `QuantizationSpec` docstring: `target_max_pow2 = 6`, with OCP MXINT8's `2^-6` element factor folded into `scale`. - Add the changelog fragment for apple#133.
dengqiaoyu
force-pushed
the
feat/int8-e8m0-scale
branch
from
October 30, 2026 21:22
c5d2a00 to
d8f07e5
Compare
vineet-g
approved these changes
Oct 30, 2026
dengqiaoyu
enabled auto-merge (squash)
October 30, 2026 21:59
dengqiaoyu
added a commit
to dengqiaoyu/coreai-optimization
that referenced
this pull request
Nov 3, 2026
- Drop an op-intrinsic asymmetric qscheme in `_build_concrete_spec` when the reconciled group has a floating-point dtype or an e8m0 scale. The op-intrinsic gate only sees the producing op's own config, so `sigmoid -> Linear` with an e8m0 consumer reconciled to int8 + e8m0 + asymmetric and failed validation (FP8 hit the same crash). Settling it after reconciliation avoids a cycle with `InheritFields`, which copies the op's value verbatim. - Re-raise the original exception from `prepare_qat_pt2e` with a note instead of rebuilding it via `type(e)(msg)`, which raised a `TypeError` for exceptions such as pydantic's `ValidationError` and hid the real error. - Run `validate_scale_dtype` before the qscheme/qformulation validators so an unsupported dtype or scale dtype gets the scale_dtype error first, rather than a request to change a field that isn't the problem. - Document int8 with e8m0 scales in the `QuantizationSpec` docstring: `target_max_pow2 = 6`, with OCP MXINT8's `2^-6` element factor folded into `scale`. - Add the changelog fragment for apple#133.
dengqiaoyu
force-pushed
the
feat/int8-e8m0-scale
branch
from
November 3, 2026 17:47
d8f07e5 to
7c0540d
Compare
- `QuantizationSpec` accepts `dtype=torch.int8` with `scale_dtype=torch.float8_e8m0fnu` at any granularity (`E8M0_TARGET_MAX_POW2[torch.int8] = 6`), so int8 power-of-2 block scales work in torch fake quantization. - For integer dtypes the e8m0 qparams path returns a zero `zero_point` and `minval = -max_abs`, which the integer fake-quant path requires; FP4/FP8 still get `None`. - An e8m0 scale requires `qscheme="symmetric"` and `qformulation="zp"` (enforced by the existing FP qscheme/qformulation validators), and graph-mode op-intrinsic overrides such as `relu` no longer propose an asymmetric scheme for it. - `Quantizer.finalize` rejects CoreAI/CoreML export of integer quantization with e8m0 scales unless a registered activation export handler covers the module; `ExportBackend._TORCH` is unaffected. - Integer palettization `lut_qspec` rejects an e8m0 scale, keeping LUT behavior unchanged.
- Drop an op-intrinsic asymmetric qscheme in `_build_concrete_spec` when the reconciled group has a floating-point dtype or an e8m0 scale. The op-intrinsic gate only sees the producing op's own config, so `sigmoid -> Linear` with an e8m0 consumer reconciled to int8 + e8m0 + asymmetric and failed validation (FP8 hit the same crash). Settling it after reconciliation avoids a cycle with `InheritFields`, which copies the op's value verbatim. - Re-raise the original exception from `prepare_qat_pt2e` with a note instead of rebuilding it via `type(e)(msg)`, which raised a `TypeError` for exceptions such as pydantic's `ValidationError` and hid the real error. - Run `validate_scale_dtype` before the qscheme/qformulation validators so an unsupported dtype or scale dtype gets the scale_dtype error first, rather than a request to change a field that isn't the problem. - Document int8 with e8m0 scales in the `QuantizationSpec` docstring: `target_max_pow2 = 6`, with OCP MXINT8's `2^-6` element factor folded into `scale`. - Add the changelog fragment for apple#133.
… clamping - Rename `validate_qscheme_for_fp_quant` to `validate_symmetric_qscheme` and `validate_qformulation_for_fp_quant` to `validate_zp_qformulation`: both also guard int8 with an e8m0 scale, not just FP quantization. - Comment why the int8 e8m0 qparams path returns a zero point and a minval: the integer fake-quant path needs both, and e8m0 allows only symmetric ZP. - Add a test that an e8m0 scale can push the int8 block max past 127, which clamps, while -128 stays representable.
dengqiaoyu
force-pushed
the
feat/int8-e8m0-scale
branch
from
November 3, 2026 22:07
7c0540d to
760f7bf
Compare
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Support int8 with
float8_e8m0fnuscales (MXINT8) inQuantizationSpec.scale = 2^(floor(log2(max_abs)) - 6).validate_symmetric_qscheme,validate_zp_qformulation).reluorsigmoidwould propose asymmetric.finalizerejects CoreAI/CoreML export of int8 + e8m0 unless an activation export handler covers it.