Repository navigation
feat(quantization): support int8 with float8_e8m0fnu scales - #133
Open
dengqiaoyu wants to merge 2 commits into
Open
dengqiaoyu wants to merge 2 commits into
dengqiaoyu wants to merge 2 commits into
Conversation
- `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.
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.
QuantizationSpecacceptsdtype=torch.int8withscale_dtype=torch.float8_e8m0fnuat any granularity (E8M0_TARGET_MAX_POW2[torch.int8] = 6), so int8 power-of-2 block scales work in torch fake quantization.zero_pointandminval = -max_abs, which the integer fake-quant path requires; FP4/FP8 still getNone.qscheme="symmetric"andqformulation="zp"(enforced by the existing FP qscheme/qformulation validators), and graph-mode op-intrinsic overrides such asreluno longer propose an asymmetric scheme for it.Quantizer.finalizerejects CoreAI/CoreML export of integer quantization with e8m0 scales unless a registered activation export handler covers the module;ExportBackend._TORCHis unaffected.lut_qspecrejects an e8m0 scale, keeping LUT behavior unchanged.