Repository navigation
Description
Problem
packed_bytes_per_token_3bit (src/lib/mlxcel-core/src/cache/turbo/pack3.rs:87) validates its "head_dim must be a positive multiple of 8" contract with debug_assert!. In release builds the assert compiles out and the function silently returns a truncated byte count (7 * 3 / 8 = 2), which would mis-size every downstream packed buffer in the Turbo3 V-side quant pipeline (quant3.rs:224 and the packing/unpacking round trip). The sibling pack_3bit_indices guards its indices.len() multiple-of-8 contract the same way, with the same silent-corruption consequence.
Visible symptom: cache::turbo::pack3::tests::packed_bytes_rejects_non_multiple_of_8 is a #[should_panic] test, so the full core suite run with --release (the profile used for Metal-gated local runs) fails on every invocation. This failure predates the recent #224-#228 queue and shows up in every release-mode suite run as noise that can mask real failures.
Reachability today is low (supported Turbo3 head dims are 64/80/128/192/256, all multiples of 8, and the WHT constraint screens dims upstream), but the contract is buffer-sizing arithmetic: if an unvetted dim ever reaches the path in release, the result is silent memory corruption rather than a panic.
Proposed solution
Promote the size-contract checks from debug_assert! to always-on assert!:
packed_bytes_per_token_3bit:assert!(head_dim > 0 && (head_dim as usize).is_multiple_of(COORDS_PER_GROUP), ...). The function is called once per quantize call, not per element; two integer comparisons are negligible.pack_3bit_indices(and its unpack counterpart if symmetric): promote the length-contractdebug_assert!the same way. These run per packed row, still trivially cheap next to the packing loop itself.- Leave the deliberate masking behavior (out-of-range index values lose high bits, documented as defensive) unchanged; this issue is only about the size contracts that determine buffer lengths.
- Do NOT cfg-gate the test: with always-on asserts,
packed_bytes_rejects_non_multiple_of_8passes in both debug and release profiles unchanged.
Acceptance criteria
-
cargo test -p mlxcel-core --release --lib cache::turbo::pack3 -- --test-threads=1passes 100 percent, including the should_panic test. - Full release-mode core suite has zero failures (this was the only one).
- Size-contract violations panic in release builds instead of truncating.
- Existing Turbo3 quant round-trip tests stay green (no behavior change for valid dims).
Related
Follow-up from the #224-#228 memory-footprint queue (see #224 for the partial mitigation this replaces / see the queue for context). Filed together with #235.
Activity