Skip to content

feat(quantization): support float16 scale_dtype - #169

Open
dengqiaoyu wants to merge 1 commit into
apple:mainfrom
dengqiaoyu:feat/float16-scale-dtype
Open

dengqiaoyu wants to merge 1 commit into
apple:mainfrom
dengqiaoyu:feat/float16-scale-dtype

Conversation

@dengqiaoyu

Copy link
Copy Markdown
Contributor
  • Add scale_dtype=torch.float16: each scale is computed in at least fp32, clamped to the FP16 max and rounded to FP16 whatever the model dtype, and an asymmetric zero point is recomputed from the rounded scale
  • Accept it on integer and FP8 specs; FP4 still requires e8m0 scales, and palettization rejects it for lut_qspec
  • Raise NotImplementedError from Quantizer.finalize for CoreAI and CoreML, since export stores each scale at the model dtype instead of FP16
  • Raise RuntimeError when a cached scale buffer cannot hold FP16 values exactly: a bf16 torch.set_default_dtype during prepare, or a bf16 cast of the prepared model
  • Count FP16 scales at 16 bits in bits_per_weight

- Add `scale_dtype=torch.float16`: each scale is computed in at least fp32, clamped to the FP16 max and rounded to FP16 whatever the model dtype, and an asymmetric zero point is recomputed from the rounded scale
- Accept it on integer and FP8 specs; FP4 still requires e8m0 scales, and palettization rejects it for `lut_qspec`
- Raise `NotImplementedError` from `Quantizer.finalize` for CoreAI and CoreML, since export stores each scale at the model dtype instead of FP16
- Raise `RuntimeError` when a cached scale buffer cannot hold FP16 values exactly: a bf16 `torch.set_default_dtype` during `prepare`, or a bf16 cast of the prepared model
- Count FP16 scales at 16 bits in `bits_per_weight`
@dengqiaoyu
dengqiaoyu force-pushed the feat/float16-scale-dtype branch from 2fb91fa to 17a3233 Compare October 29, 2026 00:36

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