Skip to content

weight_map: refuse a projection whose checkpoint shape disagrees with the config (no OOB device read) - #310

Merged
AzeezIsh merged 1 commit into
mainfrom
fix/weight-shape-guard
Nov 1, 2026
Merged

AzeezIsh merged 1 commit into
mainfrom
fix/weight-shape-guard

Conversation

@AzeezIsh

@AzeezIsh AzeezIsh commented Nov 1, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Refuse an attention projection whose checkpoint shape disagrees with the [n, k] the config implies, before upload and device quantization.

Why: a checkpoint q_proj with half the rows that attn_output_gate implies (q + gate fused) made quantize_to_nvfp4's nvfp4_global_absmax read about 63 MB past the uploaded buffer.

  • It surfaced only as a sticky CUDA_ERROR_ILLEGAL_ADDRESS with no tensor name, and destroyed the CUDA context. That's an out-of-bounds device read (CWE-125).
  • compute-sanitizer memcheck hid it (that boot succeeded), so it was easy to misread as a race.
  • Found with a synthetic Qwen4-27B-shaped checkpoint on GB10.

Change:

  • weight_map::ensure_checkpoint_shape(store, name, n, k, why) checks the safetensors header shape is exactly [n, k]. Otherwise it fails with "<tensor>: checkpoint shape [a, b] but the config implies [n, k] (<rule>)".
  • It's called at the four BF16 dense_auto → quantize/shard sites: two in qwen35/load_layers/attention_arms.rs (also used by qwen4_exp full attention), two in qwen35_dense.rs.
  • Pre-quantized (weight_packed) paths are untouched.
  • Well-formed checkpoints behave exactly as before.

Test plan

  • Unit test ensure_checkpoint_shape_rejects_a_short_q_proj: a short tensor errors, naming both shapes and the gate rule.
  • fmt, clippy (CI env), 500-LoC cap.
  • sparky GB10 job 72c, one variable vs a fresh build of base 88010ba: control.py outputs byte-identical on Flash-Next FP4-Local, Flash-Next NVFP4 and Qwen3.8-27B NVFP4 (--num-drafts 1, K=2 verify); 4/4 requests answered on each.

Generated with Devin

AzeezIsh added a commit that referenced this pull request Nov 1, 2026
Generated with [Devin](https://devin.ai)

Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
@AzeezIsh
AzeezIsh marked this pull request as ready for review November 1, 2026 20:49
@AzeezIsh
AzeezIsh merged commit 11972c1 into main Nov 1, 2026
25 of 26 checks passed
AzeezIsh added a commit that referenced this pull request Nov 1, 2026
Generated with [Devin](https://devin.ai)

Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
data-angel added a commit to Enntity/atlas that referenced this pull request Nov 1, 2026
Resolves the conflict with Atlas-Inf#310 in weight_map/quant_helpers_tests.rs by
keeping both sides: the block-scale tests from this series and Atlas-Inf#310's
ensure_checkpoint_shape test.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
AzeezIsh added a commit that referenced this pull request Nov 1, 2026
…series; data-angel)

Qwen-side KL + bench gate on reiner + spark2 (#220, receipts on the PR) at fa528fc: KL 0 vs main over 34,245 x2 + 36,765 positions incl. vision, BFCL 87.54/86.85 = main, greedy 8/8, tools 21/21, bench neutral. 354da21 = fa528fc + main (only the #310 conflict area changed). GLM-side results are data-angel's (see the PR). CI green except the PR benchmark gate.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant