Repository navigation
test(qzeros): pin the symmetric-qzeros state machine invariants - #6432
Merged
Merged
Conversation
Six changes landed on the symmetric ``qzeros`` path in one day (#6388, #6392, #6391, #6395, #6409 and the pending #6157 normalization). Each was verified on its own; nothing pinned the combination, and a later edit can satisfy one fix while breaking another. The state machine has three markers (``_HF_LEGACY_QZEROS``, ``_HF_CHECKPOINT_SYM``, ``_HF_DEFER_SYM_QZEROS``) and two word encodings, selected by ``_load_target_qzeros_format()``. The tests assert: - a 32-aligned legacy projection never defers, and a real floor-width mismatch always does (#6409 / #6396); - an asymmetric floor-width checkpoint is refused, never silently wrong; - a deferred module materializes to the standard shape with a resolved layout that agrees with the one the kernel decodes; - materialization is idempotent across 2/3/4/8-bit; - the deferral marker and a materialized buffer are mutually exclusive; - a float ``qzeros`` buffer (int4pack affine offsets) is never filled with a packed word -- skipped until the #6157 normalizer exists; - a clean checkpoint's word survives the load, and every pre- and post-#2983 producer lands on the same decoded zero point. ``qzero_format()`` is deliberately not read as a decode answer before ``_qzeros_format_established``: every kernel is ``REQUIRES_FORMAT_V2``, so the constructor placeholder ``1`` disagrees with the decoded ``2`` until a load resolves it (#4377). That distinction is the whole reason the first #6157 draft corrupted clean checkpoints. Test-only. Verified 49 passed / 13 skipped on main (a4471c5) and 50 / 12 with #6419 applied; 68 passed / 17 skipped together with the four existing qzeros test files, so there is no global-state pollution. Every skip is a kernel-geometry or environment gate with a precise reason.
``_legacy_module_or_skip`` ended with a bare ``pytest.skip(...)`` call, which reads as an implicit ``return None`` to static analysis and made CodeQL flag the function for mixing explicit and implicit returns. ``pytest.skip`` raises, so the added return is unreachable; it exists only to make every non-exceptional path explicit, and the comment says so. Behaviour unchanged: 49 passed, 13 skipped, identical to before.
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.
Test-only guard for the symmetric-
qzerosstate machine. No product change and no bug fix — an end-to-end audit ofmain(a4471c53b) found no invariant violated, so this PR only pins the invariants so the next edit to this path cannot silently break one.Six changes landed here in one day:
#6388,#6392,#6391,#6395,#6409, and the pending#6157normalization. Each was verified individually; nothing covered the combination.What the state machine looks like
Three markers, two encodings:
_HF_LEGACY_QZEROSout_features // 32 * bits_HF_CHECKPOINT_SYMsymflag_HF_DEFER_SYM_QZEROSqzero_format()_qzeros_format— a placeholder1until_qzeros_format_established_load_target_qzeros_format()All five checkpoint kernels declare
REQUIRES_FORMAT_V2 = True, so the placeholder1disagrees with the decoded2until a load resolves it. That is#4377, and it is whyqzero_format()must not be used as a decode answer before the layout is established — the exact mistake the first#6157draft made.Invariants asserted
#6409/#6396), and a real floor-width mismatch always does;qzeros_standard_shape(...), with_qzeros_format_establishedset andqzero_format() == _load_target_qzeros_format();qzerosbuffer (int4pack affine offsets, which are0.0for a symmetric checkpoint) is never filled with a packed word — skipped until the#6157normalizer exists;Results
maina4471c53bmain+#6419(b481a9ffc)qzerostest filesEvery skip is a kernel-geometry or environment gate with a precise reason (e.g.
TorchCpuAvx512Linear does not support out_features=80: `out_features`: 80 must be divisible by [32]). None hides a failure.Real checkpoints, loaded on
mainand with#6419:Qwen2.5-0.5B-Instruct-gptq-4bit(168 layers),Llama-3.2-1B-…-vortex-v1(112),Llama-3.2-1B-Instruct-GPTQ-4bits-gp128(112) — all uniform0x88888888, no floatqzeros, no leftover deferral, layout established on every layer, identical on both trees.Audit notes (no action taken here)
_materialize_hf_sym_qzerosis unreachable. Planargptq_p— the only 3-bit layout any kernel accepts — requires 32-alignedin_features/out_features, and for those widthslegacy_qzeros_columns(out_features, 3) == qzeros_standard_shape(...)[1], so#6409never defers a 3-bit layer. Defensive dead code, not a defect.checkpoint_formatis a trusted label with no check against the bytes. A checkpoint declaringgptq(v1) while holding v2 words loads silently shifted: measured0x88888888→0x99999999(every nibble +1). Nothing detects it. Pre-existing contract, not a regression — but it is the one remaining way to get a silently wrong model from this path.#6419does not repair a disk-offloaded layer (if qzeros.device.type == "meta": continue), so the#6157fix covers resident loads only. Called out on that PR; verified by reading the guard rather than by measurement, since I could not force a disk-offload cell on a model small enough to load quickly here.TorchCpuAvx512Linear, which requiresout_features % 32 == 0and therefore can never hold a non-aligned width.TorchAtenLinearneeds% 16andTorchFusedLinear% 8, so both do reach it.Full report with the writer/reader table and the cell-by-cell matrix is in
/root/openai-audit/audit-qzeros-state-machine.mdin the session workspace; the summary above is self-contained.Commands
ruff check tests/test_qzeros_state_machine_audit.py→ clean.