Repository navigation
Preserve small matrix weights during int8 export - #2176
sylvesterkaczmarek wants to merge 1 commit into
Conversation
Signed-off-by: Sylvester Kaczmarek <[email protected]>
|
Agree the 1/127 floor is surprising, but I think it's worth spelling out that it's a size/accuracy trade-off rather than a pure fix, because zlib was quietly profiting from it. Quick check on CPU,
So the floor only bites when a row's clipped peak is < 1 (roughly σ < 0.2 for Gaussian rows), and there it gives a much coarser grid that compresses far better. With the PR every matrix row costs ~0.92 B/param regardless of magnitude. For the current baseline this probably changes nothing. If I'm reading the 4h non-record log right ( (Gaussian rows are only a proxy for trained weights, so take the exact numbers with a grain of salt.) |
|
Good point, thanks for measuring it. The old floor does buy much better zlib compression for small matrices, at the cost of wiping out useful weight detail. I've added the size/accuracy trade-off and 16 MB cap risk to the PR description, and made clear that your Gaussian numbers aren't a measured effect on the trained baseline. I'd want an actual checkpoint export before claiming this helps a submission. |
Problem
Both matrix quantizers impose a minimum scale of
1/127, regardless of the row's magnitude. This forces a minimum effective range of one. In the actual state-dictionary export path, a 257-by-257 float32 matrix ranging from -0.003 to 0.003 is consequently exported as all zero int8 values.Change
Use each row's computed range, with only the smallest positive representable float16 scale as a floor. Round the stored scale upward when necessary so the clipped endpoints remain representable, then quantize against that stored scale. Apply the same correction in PyTorch and MLX.
The format identifier, int8 values, float16 row-scale storage, metadata, and decoder remain unchanged. Vector/scalar scaling is unchanged. This affects future baseline exports and does not modify archived submissions.
Size and accuracy trade-off
The previous
1/127minimum scale coarsely quantizes small-magnitude matrices. That can yield substantial reconstruction error, but creates repeated/zero int8 bytes which compress unusually well under zlib. Preserving those weights increases the entropy of the int8 payload and can increase serialized size under the 16 MB submission cap, even though the format itself is unchanged. A contributor's CPU experiment on synthetic 1024×1024 Gaussian matrices reported roughly 0.23 to 0.73 compressed bytes/parameter under the old floor for small standard deviations, versus about 0.92 after this patch, with much lower relative error. These are proxy inputs, not measured trained-weight or leaderboard results.The existing baseline uses the default quantizer and this PR does not show that a real submission becomes smaller, faster or more accurate. Any proposed use should check the exact compressed artifact size against the cap and validate task accuracy using representative checkpoint weights. The patch intentionally prioritizes preserving small weights; adaptive precision/compression is separate future work.
Validation
git diff --checkpassed.Python 3.12.14, PyTorch 2.14.1, MLX 0.32.3 and NumPy 2.5.3 on macOS arm64. MLX operations used its CPU stream. No pretrained weights, datasets, CUDA/Metal execution, full training, or benchmark improvement are claimed. No dependency changes.
Reproduced against
f5c079314c4877fbb0af378c0abade5a8ca33d3a.Maintenance validation on 6 November 2026
Revalidated both export paths and serialized scale rounding. The existing description retains the accuracy/compressed-size trade-off and the risk of exceeding the 16 MB cap; no trained-checkpoint or benchmark benefit is established.
Focused validation at
d2e65694f279: 20 CPU tests passed. The combined six-PR checkout passed 121 tests, including the actual PyTorch and MLX CPU implementations. The two baseline scripts remain below 1,500 lines; archived record scripts were not modified.Python 3.12.14, PyTorch 2.15.0 and SentencePiece 0.2.3 on macOS arm64. Tests used synthetic inputs with external sockets disabled. No pretrained checkpoint, external dataset, GPU training, full validation benchmark or leaderboard measurement was used. There are no hosted test runs on these PR heads. Earlier validation counts above are historical.