feat(int4): add nibble_pack/unpack for true 0.5 B/elem int4 storage#329
Open
lokic233 wants to merge 1 commit into
Open
feat(int4): add nibble_pack/unpack for true 0.5 B/elem int4 storage#329lokic233 wants to merge 1 commit into
lokic233 wants to merge 1 commit into
Conversation
Currently, qwix int4 QArrays store values at 1.0 bytes/element because JAX's jnp.int4 byte-pads each value. This means int4 quantization pays the quality cost of 4-bit with zero memory benefit over int8. This adds nibble_pack() and nibble_unpack() utilities that store two 4-bit values per uint8 byte, achieving the true 0.5 B/elem (4x vs fp32, 2x vs int8) memory reduction that int4 is meant to provide. Measured: nibble_pack gives exactly 0.5 B/elem on both GPU (GB200) and TPU (v7x), roundtrip-exact, with the standard GPTQ/AWQ packing layout. Addresses: google#328
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.
Summary
Addresses #328. qwix int4 QArrays currently store at 1.0 bytes/element (JAX's
jnp.int4byte-pads). This PR addsnibble_pack()/nibble_unpack()utilities that store two 4-bit values per uint8 byte — achieving the true 0.5 B/elem (4× vs fp32, 2× vs int8) memory reduction that int4 is meant to provide.What's included
qwix/_src/core/nibble_pack.py:nibble_pack(q)[N,K]→[N,K/2] uint8 andnibble_unpack(packed)[N,K/2]→[N,K] int8 in [-8,7]tests/nibble_pack_test.py: roundtrip exactness, memory halving, boundary valuesMeasured
nibble_packachieves exactly 0.5 B/elem (vs 1.0 for rawjnp.int4)Note
We acknowledge the repo's policy on external contributions. This is offered as a concrete, tested implementation of the fix described in #328, ready to adapt/integrate however the maintainers prefer.
— via Navi on behalf of @lokic233