Repository navigation
Add qpl.quantize_tile for quantizing tiles inside a Pallas kernel body, - #479
Open
copybara-service[bot] wants to merge 1 commit into
Open
copybara-service[bot] wants to merge 1 commit into
copybara-service[bot] wants to merge 1 commit into
Conversation
copybara-service
Bot
force-pushed
the
test_1023084916
branch
from
November 16, 2026 23:07
f03a11d to
b32076f
Compare
qpl.quantize inside a Pallas TPU kernel on bfloat16 inputs failedbfloat16 arrays inside a Pallas TPU kernel failed Mosaic
copybara-service
Bot
force-pushed
the
test_1023084916
branch
from
November 17, 2026 21:17
b32076f to
0c505f0
Compare
bfloat16 arrays inside a Pallas TPU kernel failed Mosaicqpl.quantize_tile for quantizing tiles inside a Pallas kernel body,
copybara-service
Bot
force-pushed
the
test_1023084916
branch
11 times, most recently
from
November 21, 2026 00:08
5148b33 to
fd1fd6c
Compare
…ody, complementing launcher-side `qpl.quantize` (full arrays). It uses the same formula as `qwix.quantize`: on TPU it is bit-identical to `qwix.quantize` run op by op, but under `jax.jit` XLA rounds bfloat16 division less exactly, so some values can differ by one quantization step, and `channelwise_axes` has the same meaning (a separate scale per index along each listed axis). Negative axes count from the end (`qwix.quantize` currently ignores them). It takes no `tiled_axes` and automatically tiles the sole non-channelwise axis for microscaled qtypes. TPU tests also run `qpl.quantize_tile` and `qpl.dot_general` together in one kernel, in both `pl.pallas_call` and `pl.kernel` + `pltpu.emit_pipeline`, and check that the compiled program is a single kernel with no quantized copy of the activations. Mosaic-specific handling stays isolated to `quantize_tile`: `calibrate` gains an opt-in `reduce_dtype` keyword argument (`None` by default), and `quantize_tile` reduces in `float32` only when a tile reduces to a single value (Mosaic can't reduce a 16-bit tile to one value; other reductions stay in the input dtype, as in XLA), and expands singleton non-lane axes in `float32` before dividing, returning unexpanded scales. The shared path keeps only the Python `math.sqrt` constant in `compute_scale_zero_point`, leaving host `qwix.quantize` behavior and HLO unchanged. Also replace the stale deprecation comment on `qpl.QArray`, `qpl.quantize` and `qpl.dequantize`: they are re-exports of the `qwix.*` objects, so kernel code can depend on `qwix.pallas` alone. PiperOrigin-RevId: 1023084916
copybara-service
Bot
force-pushed
the
test_1023084916
branch
from
November 23, 2026 19:22
fd1fd6c to
c956136
Compare
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.
Add
qpl.quantize_tilefor quantizing tiles inside a Pallas kernel body,complementing launcher-side
qpl.quantize(full arrays). It uses the sameformula as
qwix.quantize: on TPU it is bit-identical toqwix.quantizerunop by op, but under
jax.jitXLA rounds bfloat16 division less exactly, sosome values can differ by one quantization step, and
channelwise_axeshas thesame meaning (a separate scale per index along each listed axis). Negative axes
count from the end (
qwix.quantizecurrently ignores them). It takes notiled_axesand automatically tiles the sole non-channelwise axis formicroscaled qtypes. TPU tests also run
qpl.quantize_tileandqpl.dot_generaltogether in one kernel, in both
pl.pallas_callandpl.kernel+pltpu.emit_pipeline, and check that the compiled program is a single kernelwith no quantized copy of the activations.
Mosaic-specific handling stays isolated to
quantize_tile:calibrategains anopt-in
reduce_dtypekeyword argument (Noneby default), andquantize_tilereduces in
float32only when a tile reduces to a single value (Mosaic can'treduce a 16-bit tile to one value; other reductions stay in the input dtype, as
in XLA), and expands singleton non-lane axes in
float32before dividing,returning unexpanded scales. The shared path keeps only the Python
math.sqrtconstant in
compute_scale_zero_point, leaving hostqwix.quantizebehaviorand HLO unchanged.
Also replace the stale deprecation comment on
qpl.QArray,qpl.quantizeandqpl.dequantize: they are re-exports of theqwix.*objects, so kernel codecan depend on
qwix.pallasalone.