Skip to content

feat(quantization): support int8 with float8_e8m0fnu scales - #133

Open
dengqiaoyu wants to merge 2 commits into
apple:mainfrom
dengqiaoyu:feat/int8-e8m0-scale
Open

dengqiaoyu wants to merge 2 commits into
apple:mainfrom
dengqiaoyu:feat/int8-e8m0-scale

Conversation

@dengqiaoyu

Copy link
Copy Markdown
Contributor
  • 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.

- `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

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants