Skip to content

fix: enforce pack3 size contracts in release builds - #236

Merged
inureyes merged 2 commits into
mainfrom
fix/issue-234-pack3-release-asserts
Jun 12, 2026
Merged

inureyes merged 2 commits into
mainfrom
fix/issue-234-pack3-release-asserts

Conversation

@inureyes

Copy link
Copy Markdown
Member

Summary

Implements #234. 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 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_8 is a should_panic test whose panic only existed in debug builds, so every --release run of the core suite (the profile used for Metal-gated local runs) failed on it.

Validation

  • cargo test -p mlxcel-core --release --lib passes 872/872 including the should_panic test; this was the suite's only failure.
  • Turbo3 quant round-trip tests unchanged and green (no behavior change for valid dims).
  • Cold clippy clean, fmt clean.

Closes #234

inureyes added 2 commits June 12, 2026 16:54
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.
@inureyes
inureyes merged commit e6afc6d into main Jun 12, 2026
4 checks passed
@inureyes
inureyes deleted the fix/issue-234-pack3-release-asserts branch June 12, 2026 08:00
@inureyes inureyes added this to the 0.2 milestone Jun 21, 2026
@inureyes inureyes self-assigned this Aug 31, 2026
@inureyes inureyes added status:done Completed type:bug Bug fixes, error corrections, or issue resolutions priority:medium Medium priority labels Sep 6, 2026
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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

priority:medium Medium priority status:done Completed type:bug Bug fixes, error corrections, or issue resolutions

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix(core): pack3 size-contract asserts vanish in release builds and the should_panic test fails

1 participant