Skip to content

test(protocol): assert the exclusion contract, not the emitted dynamic key - #6442

Merged
Qubitium merged 1 commit into
mainfrom
fix/llama32-protocol
Nov 29, 2026
Merged

Qubitium merged 1 commit into
mainfrom
fix/llama32-protocol

Conversation

@Qubitium

Copy link
Copy Markdown
Collaborator

Three Llama-3.2 protocol integration test files have been red on every GPU host, failing at the first assertion before any model is loaded. They only skip on a CPU host, so the breakage was invisible outside a GPU run. No issue tracks this; it surfaced during a sweep of main = a4471c53b.

Root cause — the test asserts a string the compiler no longer emits

gptqmodel/quantization/protocol.py::_compile_negative_match_dynamic:

# Protocol selectors are evaluated with `pcre.search` (see
# `_pattern_matches`), while `dynamic` rules are start-anchored
# (`pcre.match`). Prefix `.*` so a selector such as `down_proj` excludes
# the same modules in the compiled config as it does in the protocol.
pattern = ".*" if selector.pattern == "*" else f".*(?:{selector.pattern})"
dynamic[f"-:{pattern}"] = {}

That prefix is deliberate and is the fix for #4197. The compiled key is therefore not textually equal to the raw selector.

All three tests still compared the whole dict against the raw pattern:

assert cfg.dynamic == {f"-:{LAYER0_ONLY_NEGATIVE_MATCH}": {}}
LAYER0_ONLY_NEGATIVE_MATCH = r".*layers\.(?:[1-9]|[12][0-9]|3[0-2])\..*"

emitted : '-:.*(?:.*layers\\.(?:[1-9]|[12][0-9]|3[0-2])\\..*)'
asserted: '-:.*layers\\.(?:[1-9]|[12][0-9]|3[0-2])\\..*'

For this particular pattern the two are semantically identical — it already starts with .*, so pcre.match and pcre.search agree on every module name. Only the string differs. That is why this is a stale expectation and not a product bug.

Affected nodes — 6, across 3 files

file subclasses
tests/models/test_llama3_2_gptq_protocol.py TestLlama3_2_GPTQProtocol{Python,YAML}
tests/models/awq/test_llama3_2_awq_protocol.py TestLlama3_2_AWQProtocol{Python,YAML}
tests/models/test_llama3_2_gguf_protocol.py TestLlama3_2_GGUFProtocol{Python,YAML}

All six fail identically. Reproduce without a GPU, since the assertion is pure config logic:

cd tests
CUDA_VISIBLE_DEVICES="" PYTHONPATH=<clone>:<clone>/tests:<clone>/tests/models /root/venv/bin/python - <<'PY'
from models.test_llama3_2_gptq_protocol import TestLlama3_2_GPTQProtocolPython
inst = TestLlama3_2_GPTQProtocolPython.__new__(TestLlama3_2_GPTQProtocolPython)
cfg = inst._build_quantize_config()
print(cfg.dynamic)
inst._assert_layer0_only_dynamic(cfg)   # AssertionError on main
PY

Fix — assert the exclusion contract

assert len(cfg.dynamic) == 1
(exclusion,) = cfg.dynamic
assert exclusion.startswith("-:"), exclusion
assert cfg.dynamic_get("model.layers.1.self_attn.q_proj") is False
assert cfg.dynamic_get("model.layers.32.mlp.up_proj") is False
assert cfg.dynamic_get("model.layers.0.self_attn.q_proj") is not False
assert cfg.dynamic_get("model.layers.33.mlp.up_proj") is not False

This mirrors the two places that already pin this contract and are green:

  • tests/test_protocol_negative_search_4197.py — asserts (config.dynamic_get(name) is False) == protocol_excludes for four parametrized selectors, including -:*.
  • tests/protocol/test_protocol.py:372-416 — asserts the wrapped form {r"-:.*(?:.*layers\.2.*)": {}} for both Python and YAML sources.

Nothing was widened. The test still pins "one negative selector produces exactly one exclusion rule", still requires the -: prefix, and now additionally pins which layers are excluded (1–32) and which are not (0, 33) — which the string comparison never did.

Non-vacuity

The new assertion was checked against three deliberate regressions:

injected regression result
exclusion pattern that matches nothing FAILED
a second, bogus dynamic rule FAILED (len(cfg.dynamic) == 1)
-: prefix dropped FAILED
correct shape (control) passed

Verification — full integration runs on an RTX 4090

Baselines were recorded on SM 8.9, so all runs were pinned to an idle 4090 (CUDA_DEVICE_ORDER=PCI_BUS_ID CUDA_VISIBLE_DEVICES=<n>), never the SM 12.0 card.

node before after
TestLlama3_2_GPTQProtocolPython AssertionError 1 passed, 231.9s
TestLlama3_2_GPTQProtocolYAML AssertionError 1 passed, 173.6s
TestLlama3_2_GGUFProtocolPython AssertionError 1 passed, 220.4s
TestLlama3_2_GGUFProtocolYAML AssertionError 1 passed, 210.9s

Each run quantized only layer 0 (_assert_only_first_layer_quantized passed; kernel histograms were {MarlinLinear} / {GGUFTorchLinear}), and every eval landed inside its band. The GPTQ and GGUF pairs each produced identical numbers across their Python and YAML variants, which is the expected determinism:

gsm8k_platinum_cot:acc,num  0.45905707  vs 0.469   →  97.88%  (allowed 95-200%)
mmlu_stem:acc               0.39803362  vs 0.3999  →  99.53%  (allowed 97-200%)
arc_challenge:acc           0.31911263  vs 0.3221  →  99.07%  (allowed 95-200%)
arc_challenge:acc_norm      0.34982935  vs 0.3528  →  99.16%  (allowed 97-200%)

The AWQ pair cannot run on this host — its gate requires Hopper or newer and the available cards are Ada (SM 8.9). That is a pre-existing environment gate, unrelated to this change. Its config assertion, which is the part this PR touches, was verified green on CPU.

Other checks:

  • tests/test_protocol_negative_search_4197.py + tests/protocol/ → 73 passed, 4 skipped (confirms the wrapping contract is intact and my reading of it is right).
  • Collection of all 20 test_llama3_2* files → 51 tests collected, 0 errors.
  • The three touched files on CPU → 7 skipped, 0 errors (the gates still work).
  • ruff check on all three files → clean.

Scope

Tests only; no product code changed. LAYER0_ONLY_NEGATIVE_MATCH is still used to build the protocol in each file, so no dead constant.

Why this went unnoticed

test_gc.py-style CPU-only nodes are cheap, but these are GPU integration nodes that skip on a CPU host — so a CPU sweep sees green, and CI runs only 8 curated files, none of which is a protocol integration test. A lane that runs the CPU-visible subset would still not catch it; catching this class needs either the GPU lane or a CPU-reachable assertion. The config assertion in these tests is CPU-reachable (as the repro above shows), which is the cheapest way to make the next occurrence visible.

…c key

`_compile_negative_match_dynamic` prefixes every `-:` selector with
`.*(?:...)` because protocol selectors are evaluated with `pcre.search`
while `dynamic` rules are start-anchored (`pcre.match`); without the
prefix a selector such as `down_proj` excludes in the protocol and
quantizes in the compiled config (#4197). The compiled key is therefore
not textually equal to the raw selector.

The three Llama-3.2 protocol integration tests still compared the whole
`cfg.dynamic` dict against `{f"-:{LAYER0_ONLY_NEGATIVE_MATCH}": {}}`, so
all six nodes (GPTQ/AWQ/GGUF × Python/YAML) failed on the first assertion
and never reached the model. They only skip on a CPU host, which is why
the breakage was invisible outside a GPU run.

Assert the contract instead: exactly one `-:` rule, and
`dynamic_get()` reports `False` for layers 1..32 while leaving layer 0 and
layer 33 alone. This mirrors `tests/test_protocol_negative_search_4197.py`
and `tests/protocol/test_protocol.py`, which already pin the wrapped form.

Verified on an RTX 4090 (SM 8.9, matching the recorded baselines):
GPTQ Python 1 passed (231.9s), GPTQ YAML 1 passed (173.6s), GGUF Python
1 passed (220.4s), GGUF YAML 1 passed (210.9s), each with all four eval
deltas inside the allowed band. The AWQ pair cannot run here (its gate
needs Hopper or newer); its config assertion passes on CPU.

Non-vacuity: the new assertion still fails when the exclusion is replaced
by a pattern that matches nothing, when a second rule is added, and when
the `-:` prefix is dropped.
@Qubitium
Qubitium marked this pull request as ready for review November 29, 2026 20:04
@Qubitium
Qubitium merged commit 9fb990d into main Nov 29, 2026
6 checks passed
@Qubitium
Qubitium deleted the fix/llama32-protocol branch November 29, 2026 20:05
Qubitium added a commit that referenced this pull request Nov 30, 2026
- llama3.2 bitsandbytes: pin fast-layer prefix and assert 4-bit buffers
- cohere_compass: monkeypatch load_model_config; replay must keep None rotary
- base: honor rope_parameters[layer_type] = None in layer-type replay
- unlimited_ocr: read the legacy processor_config.json; add unit regression
- locateanything/minicpm_o: let the port own the processor
- ovis 1.6: pin FP16 for the Marlin kernel
- dream: gate the remote-only tokenizer on the documented bypass

Rebased onto 8d52eb9. The llama3.2 gptq/gguf protocol hunks were
dropped: #6442 (9fb990d) already fixes the same stale `cfg.dynamic`
assertion in both files by asserting the exclusion contract, so main's
version is kept.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Qubitium added a commit that referenced this pull request Nov 30, 2026
- llama3.2 bitsandbytes: pin fast-layer prefix and assert 4-bit buffers
- cohere_compass: monkeypatch load_model_config; replay must keep None rotary
- base: honor rope_parameters[layer_type] = None in layer-type replay
- unlimited_ocr: read the legacy processor_config.json; add unit regression
- locateanything/minicpm_o: let the port own the processor
- ovis 1.6: pin FP16 for the Marlin kernel
- dream: gate the remote-only tokenizer on the documented bypass

Rebased onto 47aa824. The llama3.2 gptq/gguf protocol hunks were
dropped: #6442 (9fb990d) already fixes the same stale `cfg.dynamic`
assertion in both files by asserting the exclusion contract, so main's
version is kept.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
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