Repository navigation
fix: enforce pack3 size contracts in release builds - #236
Merged
Merged
Conversation
packed_bytes_per_token_3bit validated its positive-multiple-of-8 head_dim contract with debug_assert, so release builds compiled the check out and returned a silently truncated byte count (7 * 3 / 8 = 2) that would mis-size every downstream packed buffer in the Turbo3 V-side quant pipeline. The sibling pack/unpack length contracts had the same shape: slice bounds checks still caught under-sized buffers, but a non-multiple length silently dropped the tail group instead of failing. Promote all seven pack3 size-contract debug_asserts to always-on asserts. They are per-call or per-token integer comparisons next to the packing loops, so the cost is negligible, and the contracts size buffers, so violations must fail loudly in every profile. This also fixes the standing release-mode suite failure: the should_panic test packed_bytes_rejects_non_multiple_of_8 expected a panic that only debug builds produced. cargo test -p mlxcel-core --release --lib now passes 872/872 (this was the only failure); cold clippy and fmt clean.
…ct (review follow-up)
be-free-snowboy
pushed a commit
to freestylejs/snowbrain-mlxcel
that referenced
this pull request
Oct 27, 2026
* fix: enforce pack3 size contracts in release builds packed_bytes_per_token_3bit validated its positive-multiple-of-8 head_dim contract with debug_assert, so release builds compiled the check out and returned a silently truncated byte count (7 * 3 / 8 = 2) that would mis-size every downstream packed buffer in the Turbo3 V-side quant pipeline. The sibling pack/unpack length contracts had the same shape: slice bounds checks still caught under-sized buffers, but a non-multiple length silently dropped the tail group instead of failing. Promote all seven pack3 size-contract debug_asserts to always-on asserts. They are per-call or per-token integer comparisons next to the packing loops, so the cost is negligible, and the contracts size buffers, so violations must fail loudly in every profile. This also fixes the standing release-mode suite failure: the should_panic test packed_bytes_rejects_non_multiple_of_8 expected a panic that only debug builds produced. cargo test -p mlxcel-core --release --lib now passes 872/872 (this was the only failure); cold clippy and fmt clean. * docs: align packed_bytes_per_token_3bit doc with the always-on contract (review follow-up)
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
Implements #234.
packed_bytes_per_token_3bitvalidated its positive-multiple-of-8 head_dim contract withdebug_assert!, so release builds compiled the check out and returned a silently truncated byte count (7 * 3 / 8 = 2) that would mis-size every downstream packed buffer in the Turbo3 V-side quant pipeline. The sibling pack/unpack length contracts had the same shape: slice bounds checks still caught under-sized buffers, but a non-multiple input length silently dropped the tail group instead of failing.All seven pack3 size-contract
debug_asserts are promoted to always-on asserts (the masking of out-of-range index values stays as documented defensive behavior, unchanged). They are per-call or per-token integer comparisons next to the packing loops, so the cost is negligible against the packing work itself, and the contracts size buffers, so violations must fail loudly in every profile.This also fixes the standing release-mode suite failure:
packed_bytes_rejects_non_multiple_of_8is ashould_panictest whose panic only existed in debug builds, so every--releaserun of the core suite (the profile used for Metal-gated local runs) failed on it.Validation
cargo test -p mlxcel-core --release --libpasses 872/872 including the should_panic test; this was the suite's only failure.Closes #234