PTWM
transforms

ptwm_core::transforms::block_microscaling_repack

BlockMicroscalingRepack op — re-express a 16-bit float plane as a per-block shared scale (E8M0) plus a scale-relative element plane.

ptwm_core::transforms::block_microscaling_repack

BlockMicroscalingRepack op — re-express a 16-bit float plane as a per-block shared scale (E8M0) plus a scale-relative element plane.

rsmod

ptwm_core::transforms::block_microscaling_repack

crates/ptwm-core/src/transforms/block_microscaling_repack.rs:1
mod block_microscaling_repack

`BlockMicroscalingRepack` op — re-express a 16-bit float plane as a per-block shared scale (E8M0) plus a scale-relative element plane.

The OCP microscaling formats (MXFP4 / NVFP4) store one shared block scale alongside the elements, and PTWM already compresses that scale stream well (the E8M0 sequence is smooth and autocorrelated). BF16 weights that *aren't* in a microscaled container leave that headroom on the table. This op recovers it without any precision loss. ## Lossless construction Each element is a little-endian `u16` viewed in the BF16 layout `[ sign : 1 | exponent : 8 | mantissa : 7 ]`. For a block of `block_size` consecutive elements: - the **scale** is the maximum 8-bit exponent field in the block (an E8M0 value); - each element's exponent field is replaced by the non-negative residual `scale - exponent`, with sign and mantissa untouched. Because the scale is the block maximum, every residual is in `0..=255` and reconstruction (`exponent = scale - residual`) is exact. The op is therefore a pure, reversible re-encoding — it is lossless for *any* `u16` data, not only well-formed BF16 — and the compression benefit comes from the residual exponent field concentrating near zero (so the downstream `bit_reorder` + `byte_split` exponent plane is far more compressible) while the small per-block scale plane carries the rest. ## Outputs 1. **element plane** — same shape / width (`Word2`) as the input, with exponent fields rebased to residuals. 2. **scale plane** — one `E8M0` byte per block (`Role::Scale`).
rstype

ptwm_core::transforms::block_microscaling_repack::BlockMicroscalingRepack

crates/ptwm-core/src/transforms/block_microscaling_repack.rs:49
pub struct BlockMicroscalingRepack

Re-express a 16-bit-float plane as (scale-relative element plane, E8M0 per-block scale plane).