Skip to content

Add qpl.quantize_tile for quantizing tiles inside a Pallas kernel body, - #479

Open
copybara-service[bot] wants to merge 1 commit into
mainfrom
test_1023084916
Open

copybara-service[bot] wants to merge 1 commit into
mainfrom
test_1023084916

Conversation

@copybara-service

@copybara-service copybara-service Bot commented Nov 16, 2026 •

Copy link
Copy Markdown

Add qpl.quantize_tile for quantizing tiles inside a Pallas kernel body,
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.

@copybara-service copybara-service Bot changed the title Calling qpl.quantize inside a Pallas TPU kernel on bfloat16 inputs failed Quantizing bfloat16 arrays inside a Pallas TPU kernel failed Mosaic Nov 16, 2026
@copybara-service copybara-service Bot changed the title Quantizing bfloat16 arrays inside a Pallas TPU kernel failed Mosaic Add qpl.quantize_tile for quantizing tiles inside a Pallas kernel body, Nov 17, 2026
@copybara-service
copybara-service Bot force-pushed the test_1023084916 branch 11 times, most recently from 5148b33 to fd1fd6c Compare November 21, 2026 00:08
…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
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.

1 participant