简介
Construct regression tests for GPT-QModel bug fixes and behavior-changing refactors, especially checkpoint/offload round trips, partial-failure retries, concurrency and cache ownership, mutable config propagation, calibration replay, and numerical/layout boundaries. Require evidence that tests detect the broken behavior rather than merely exercising the fix.
通过你的 Agent 添加
安装目录:gptqmodel-regression-test-design/(目录名取自 SKILL.md 的 frontmatter name,不是 URL 里的 slug)。
点「快速安装」复制一段指令贴给你的 Agent:它会先下载到 /tmp、把文件清单和校验值给你看,你确认之后才解压安装。不会一步装完、也不改系统其它位置。
或者手动安装
包是「根级 SKILL.md + 作者附带的文件」,解压到上面的 <slug>/ 目录即可;
目录名不用换,也不要把包直接解压到 skills 根目录。
技能申请的权限由作者决定:装之前先看清单里有没有脚本、它会读写什么。
技能正文
SPDX-FileCopyrightText: 2026 ModelCloud.ai
SPDX-License-Identifier: Apache-2.0
name: gptqmodel-regression-test-design
description: Construct regression tests for GPT-QModel bug fixes and behavior-changing refactors, especially checkpoint/offload round trips, partial-failure retries, concurrency and cache ownership, mutable config propagation, calibration replay, and numerical/layout boundaries. Require evidence that tests detect the broken behavior rather than merely exercising the fix.
GPT-QModel regression-test design
Contracts first. Read and honour contracts/
before acting. In particular, read the
kernel forward dtype contract:
one activation dtype per module, and output dtype equals input dtype. A
different dtype on a later call is a bug. Contracts outrank this skill.
At a glance
name: gptqmodel-regression-test-design description: Construct regression tests for GPT-QModel bug fixes and behavior-changing refactors, especially checkpoint/offload round trips, partial-failure retries, concurrency and cache ownership, mutable config propagation, calibration replay, and numerical/layout boundaries. Require evidence that tests detect the broken behavior rather than merely exercising the fix.
Contracts first. Read and honour
contracts/before acting. In particular, read the kernel forward dtype contract: one activation dtype per module, and output dtype equals input dtype. A different dtype on a later call is a bug. Contracts outrank this skill.
At a glance
For each bug fix or behaviour-changing refactor, add a red/green regression to the existing test family. Exercise the risky transition and its next consumer, not just the helper or first successful call. Select the applicable cases below and record the evidence in the PR.
1. Write the invariant before the patch
Record the public entry point, broken observable result, trigger, owning state, and the transition that invalidates the old assumption. Inspect recent fixes and tests for the same mechanism, not only the same filename or issue number. An issue and the PR that fixes it are one event, not two recurrences.
Choose the applicable rows below; justify omissions rather than multiplying every backend, dtype, and model into an impractical full Cartesian product. Add a tiny deterministic unit regression and a consumer-level test when the bug crosses a loader, looper, writer, or dispatch boundary. Prefer extending an existing family suite to another disconnected issue-number-only test file.
2. Prove the test can detect the defect
- Run the new test against the broken implementation in an isolated worktree,
or temporarily reintroduce only the defective operation in a disposable
checkout. Do not discard unrelated work or rewrite shared history.
- Verify it fails at the intended behavioral assertion. Import errors, a
missing newly added symbol, collection failures, timeouts unrelated to the
defect, and skips are not red evidence. If a pre-fix run is infeasible,
report why and mark detection evidence unverified.
- Assert the trigger actually occurred: a nonzero off-block update, a second
replay pass, a native dispatch, a partial tile, an injected failure, or
overlapping owners. A test that never reaches its branch can pass forever.
- Apply the fix and run the regression plus the affected family suite. Keep
the negative/control case proving that valid behavior still works and that
unrelated errors are not swallowed.
Build expected results independently: checkpoint tensors before transformation, a fresh reference run, native model execution, explicit token rows, or a Torch oracle. Never derive the expected answer using the same converter, normalizer, cache, or quantizer under test. Random data supplements adversarial fixtures; all-zero weights, identity scales, diagonal Hessians, and uniform masks can remove the very effect being tested.
Mocks may isolate an external dependency or inject a failure at its boundary. Do not mock away the mutation, conversion, replay, or dispatch under test. Call-count/source-text assertions are supporting evidence, not substitutes for observable tensor values, selected policy, restored state, or released owners.
Test what importing a fixture does to the next caller. A module-level kernel
double can enter discovery during pytest collection. Give stand-ins that declare
kernel formats SUPPORTS_BACKEND_SELECTION = False. In a fresh interpreter,
resolve a known backend/method/format triple, import the fixture, then resolve
it again and assert the same concrete class. Check explicit lookup as well as
the AUTO map when both consume discovery. For a CPU model oracle, set the
device on load and reload. If an optional accelerator package can change a
CPU forward, scope the existing eager reference fixture to that call and let
the following caller see the original binding.
Prove the guard runs where it belongs. When adding or moving a regression,
check both the CI path filter and the job's pytest selection. Run the affected
nodes with pytest -rs in the intended dependency profile. Keep a CPU policy
test runnable without optional native dependencies: scope integration imports,
fixtures and skips to the nodes that need them. For a native-path guard, use
the backend's actual runtime/build prerequisite and assert which implementation
served the call. Collection, a skipped node, or a passing fallback is not a
pass for the target path.
3. Test the relevant transition, not only construction
Checkpoint layout, dtype, and model ownership
For changed serialization/load/offload paths, exercise the applicable sequence:
pack -> forward -> save -> load -> forward -> re-save -> reload -> forward.
Also test direct state_dict() copies into fresh and already initialized
modules, load_state_dict(assign=False/True), and offload/restore where used.
For quantization resume, capture a module after packing has changed a constructor default. Vary one property independently (scale width, bias width or populated escape-table length). Restore into a fresh target and materialize through the offload hook. Compare every persistent key, shape, dtype and value with the pre-capture module. Pair the default-layout case with a bundle whose one changed field contradicts the saved metadata and assert rejection before module replacement.
When a packer is split or its decorators move, run each affected public
pack_impl inside an outer torch.inference_mode(). Construct the destination
before entering that context. After leaving it, load a second, distinguishable
checkpoint with assign=False before the first forward and compare the packed
buffers. An assign=True control exercises replacement and can pass even when
the existing buffers reject an in-place copy.
For weight-only finalize, materialize a source Parameter under inference mode
and rebind its data outside that context, as the lazy layer's CPU move does.
Prove the trigger: is_inference() is false but reading _version raises.
Use a tiny biased checkpoint with default disk offload. Exercise both a packer
that transposes the source weight (AWQ GEMM export) and the file-backed writer
that views the bias as bytes (GPTQ export). After quantization, check that the
live parameters have readable counters and compare in-session and reloaded
logits on fixed IDs. See the counterless fixture
and RTN round trip.
- Assert the complete owned tensor-key set, storage dtype, packed values, and layout markers, plus forward parity. A matching marker alone cannot prove the words were converted; a finite output cannot prove the right weights were loaded. Repeated loads/saves must not double-convert qzeros.
- For a deferred checkpoint tensor, hold producer metadata fixed and vary whether the on-disk width actually differs. Inspect expected keys before dispatch. Force a kernel replacement with resident weights and a deferred placeholder, then check the final kernel's registration, decoded values and first forward.
- Deliberately mismatch model compute dtype and stored tensor dtype. Include packed floating weights, scales, biases, other buffers, and dense Parameters where supported; a buffer-only fixture misses Parameter casts. Use values that would change on narrowing. Compare tensor contents, not container-file byte identity (headers/sharding may legitimately differ).
- Include mixed quantized/dense or pruned MoE entries and a real tiny model requiring Defuser when changing shell reconstruction. Assert all experts' payloads survive and nonzero fixtures stay nonzero. Removing a required destination must fail before publishing a successful checkpoint.
- Prove the in-session model still forwards, saves again, and moves when those operations are supported. Cleanup may reclaim a resource only after its last live consumer releases it; assert both continued usability and eventual cleanup, including a failed save followed by retry.
- When changing a kernel's required checkpoint tensors or their consumers,
pair a truncated checkpoint with a complete one from the same family.
Remove one required key and assert the loader names it. Load the complete
checkpoint through
GPTQModel.load, check a family-specificpost_initeffect, then run a forward. Include a family withoutqweightand a GPTQ control. For offload changes also exercise the supported meta-backed layer. - For checkpoint selection, put different valid artifacts at the repo root
and in the selected subfolder. Load the child directly and via
subfolder=; compare dispatch, processor or tensor markers, and re-save/reload as applicable. Move a legacy sidecar between root and child: only the selected copy may affect dispatch. A missing root is a weaker decoy than a plausible wrong one. - For resumable exports, start with a completed export in the same output directory. Change source or dtype with filenames unchanged; then change single-file ↔ sharded layout. Compare what a normal reader loads with a clean export. Assert obsolete owned files disappear, an unrelated file survives, and an unchanged compatible export still reuses its shards.
- For export to another runtime, vary a source-valid option whose meaning differs between target architectures. Check the accepted artifact with the target loader and a forward. For an unrepresentable option, assert that the public exporter identifies it and preserves the destination. A header check against the writer's own tensor plan can pass with a wrong plan.
Exercise each supported writer entry point after runtime initialization,
including a bridge-loaded instance's save_pretrained. For reversible layouts,
reload and compare packed tensors and outputs. For irreversible runtime layouts,
assert the documented save rejection. Keep a read-only state_dict() control
and verify runtime-only markers stay out of published checkpoint payloads.
Build port-load fixtures from released configs, shrinking only model geometry. Preserve serialized attention hints, rope options, explicit head dimensions, tokenizer declarations and architecture-owned FP32 parameters. Pair inherited hints with explicit caller overrides and supported text variants with rejected vision variants. Check config-only and quantized re-save metadata against the files actually published, then exercise the supported reload entry point.
When a sidecar and a tokenizer both supply a generation setting, make their values disagree. Test an explicit null, a pinned value and a missing sidecar on ordinary and quantization-config loads. Supply a different explicit tokenizer as the override control and inspect the saved generation policy.
Follow checkpoint serialization, model plans, and lazy loading as applicable.
Failure, cancellation, and retry after partial progress
For a retryable prefill, test the entire public call. Shorten and lengthen one aligned input at a time. For windowed state, start one token before a flush, let the first token cross it, and fail a later token with valid input shapes. Compare the packed checkpoint, pending records and counters with their pre-call values, then retry the whole prompt against an uninterrupted reference.
Inject failures before mutation, after a completed mutating block, and at publication/cleanup boundaries relevant to the change. Assert the injection fired. For Hessian/error-feedback retries use correlated inputs, a non-diagonal Hessian (positive definite after damping), multiple blocks, nontrivial activation order, and dead columns/static groups when applicable; confirm off-block updates are nonzero. A diagonal Hessian plus failure at the first allocation cannot expose reusing a partly updated weight.
Compare retry results and discrete quantization outputs with an independent fresh run under the numerical skill's rules. Check all coupled state follows the retry device: weights, Hessians, permutations, group quantizers, and scales. Test a non-memory exception separately: it must propagate, not trigger an OOM fallback. Bound retries, require monotonic progress (for example shrinking the effective batch), and reset retry state between top-level calls.
For numerical solver fallback, inject factorization failure, nonfinite spectrum, iterate and final loss separately. Compare the returned weight/grid metadata with an independent fresh fallback and assert the recorded reason and completed iteration count. Exercise a fallback that also fails and an unrelated error. For adaptive schedules, assert the fixture's condition number crosses each threshold and the chosen schedule reaches a later iteration. Check diagnostics through the public quantization result as well as on the solver object.
If a solver can delegate to its parent when calibration statistics are absent, install the variant's statistics and inject the fault inside its own block update. Pair a configured recovery with the same fault and recovery disabled. Exercise missing statistics separately through the public entry point. A G2PTQ fixture that always delegates can pass without ever running grouped compensation.
After cancellation/error, assert hook removal, weight/device restoration, released temporary references, completed/failed futures, and the absence of partially published artifacts as applicable. Then run an ordinary forward or same-key retry: checking an empty hook/cache dictionary alone misses unusable models and waiters that remain blocked.
For the cancelled-run contract, test both calibrated (e.g. GPTQ) and weight-only (e.g. RTN) loops when the guarantee is shared. Leave one layer completed, one in flight, and one unreached; inject a one-shot fault at the changed phase, including the final restore if affected. Assert the original error, then forward in ordinary grad mode: an inference-mode probe can hide unrepaired tensors. Check the three layers' placement or live offload backing, not a blanket “no meta tensors” rule. A runnable model is required; re-quantizing that partially processed model is not.
Concurrency, caches, and temporary storage
State the ownership scope explicitly: module, run, process, device, stream, or caller lease. Test cold first use, warm reuse, clear/invalidate, and rebuild. Use barriers/events to force contention; do not rely on sleeps or a loop that merely submits work sequentially. Count builds/releases and inspect retained references/storage after work completes, not just peak allocator reservations.
When a compiled model promises release on last reference, run generation
(and a retrace if affected), then drop all strong owners. Check that a weak
reference is dead and compare live allocated device bytes with baseline before
the test calls gc.collect() or clears caches. Disable automatic cyclic GC for
this probe and restore its prior state in finally. Installing a wrapper
alone cannot expose trace-owned references.
For disposable forward replicas, use a converted expert with an instance-bound method. Prove the copy owns that binding, drain the workers, and check its weak reference before cyclic GC on both success and worker error. Verify the source still owns its bound method and can forward after cleanup.
For shared writable scratch, two live streams must have exclusive storage or a proven lease lasting until asynchronous consumption completes. An allocation lock does not protect a buffer after the lock is released. Verify same-stream reuse, different-stream ownership, growth/invalidation, and numerical parity under overlapping native work. For immutable shared data, verify readiness and lifetime instead of requiring unnecessary copies.
Exercise owner failure after publishing a future/handle but before completion; all waiters must finish or receive the error, and a same-key retry must work. Use bounded joins and an outer subprocess timeout so a regression cannot hang the suite. Always clean up workers and process-global settings on test failure. Test overlapping global guards leaving in a different order from entry.
For background prewarm, test interpreter shutdown in a subprocess with an in-flight worker. Check both successful load-then-exit and caught-error exit status, plus bounded cleanup of a wedged worker. A direct call to the join helper only establishes part of the shutdown lifecycle.
CPU doubles establish ownership logic, not native stream or GIL=0 safety. Follow the GIL=0 skill and ledger for actual threaded qualification, and the numerical skill for persistent packed storage.
JIT disk caches. A writable temporary directory hides writes on a cache hit. Use separate install, home and configured cache directories. Seed valid generated sources or a compiled library, deny writes at the filesystem boundary (including lock creation), and load with a fresh caller. Assert it uses the seeded artifact with zero write attempts. Repeat with the artifact missing. Check the reported cache path and remedy, then allow writes and verify the artifact lands under the selected root. Exercise prerequisites such as Machete's CUTLASS checkout when they are resolved before the hit. See the read-only cache fixtures.
For compiler retries, make the launcher fail after Torch records the build attempt. Count compiler invocations and check the retry actually produces a loadable operation with the launcher disabled. For a persisted failure, start a fresh interpreter on the same cache and check it returns the recorded diagnostic without compiling. Change only the launcher policy or advance the clock past expiry, then verify a successful build clears the record. See the JIT loader tests.
Configuration reaches the actual consumer
Test non-default values through the public API, resolution, actual dispatch,
and serialization/reload, not only construction or to_dict(). Cover enum and
typed backend forms, inherited load policy versus explicit quantize override,
and the default/AUTO control where applicable. Reuse the same config for two
operations; derived runtime policy must not contaminate caller-owned settings.
Warm caches before mutating a nested typed leaf in place, replacing it, and clearing an override. A fresh resolution must see the new content while an already-issued immutable snapshot keeps its old value. Construct module A under policy P1, change the process policy to P2, construct B, then forward A again: assert each module uses its documented snapshot. Test every setting that participates in cache/pool identity, not only the most obvious field.
Unknown options, unsupported targets, and conflicting forms need explicit rejection tests before mutation. Do not silently accept an option the consumer ignores. Select runtime behavior through config/API arguments, never retired environment switches.
For public signature or config migrations, search for the retired spelling in scripts, README/docs and skill examples as well as Python callers. Exercise the replacement through the documented public import and call; parsing a snippet cannot catch a removed keyword. Check the old form against the stated compatibility policy. Extend the docs contract tests for affected examples.
For loader placement, feed the same checkpoint and explicit map through native
load and the supported Transformers bridge. Include integer ordinal 0 (valid
but falsey), a nonzero control, and an absent target when exercising map
resolution. For mixed CPU/accelerator maps, check AUTO selects an offload-safe
kernel without silently overriding an explicit backend. Inspect the packed
buffer's actual device and run a first forward against a reference; a
plausible device map or correct logits alone can hide a copy on every call.
For whole-model offload, run a root-only placement through both
WeightLoader.dispatch and the quantized load path (simple_dispatch_model).
Use a tiny multi-block model and a resident reference. With disk>cpu,
store a tied embedding and head under one key and read both in two successive
forwards. Check logits and the return to disk-backed meta slots between calls.
With cpu>accel:0, observe a middle block's execution device and the caller's
output device. Check live weight and packed-buffer residency after dispatch
and after each return, including the final block. A whole-model copy can give
correct logits twice. Compare synchronized live accelerator bytes with the
resident control when testing that leak. See the loader fixtures
and quantized residency check.
Optional dependency isolation. Import order and call scope are independent.
Run each order in a fresh interpreter with Accelerate installed. Load a tiny
local packed checkpoint through plain Transformers with device_map="cpu"
both after importing GPT-QModel and with Optimum importing it during the load.
Assert the packed layers survive and run a forward. Pair this with a native
GPTQModel.load using placement and check which loader owns placement.
For a lazy Transformers module, assert it is absent from sys.modules,
import it inside the isolated scope, then exercise its Accelerate binding
outside the scope. For hook changes, resize a hooked embedding and forward
through it. Check the replacement hook's owner and the new token's logits.
Run a Trainer step when training is affected. See the
scope contract and
subprocess fixtures.
For packer selection, vary supported global widths through the public quantize entry point and check the actual packed class. Pair shape-free backend selection with concrete per-layer validation. Carry an inference-only backend from a dense load into an AUTO quantize call, then repeat with that backend explicitly requested at quantize time. Assert the inherited choice permits a capable packer, the explicit unsupported choice raises before calibration, and a packable inherited choice survives. For replacement placement, give a packed module a CPU metadata buffer and accelerator payload, then inspect the payload after rehoming. Exercise resident dispatch hooks that own execution placement.
When multiple processors share a source module, drive their real sequence. A planning processor that performs no forward must leave the source dense. Check the temporary capture representation during the statistics forward and the restored dense source at quantizer preprocessing, followed by final packing. Use a fused expert fixture with distinct gate/up rows, scales and bias to check the checkpoint-to-defused-source handoff.
Calibration representations and repeated replay
Represent the same explicit token rows as each affected supported input form:
row lists, row/column mappings (including non-dict Mapping/column objects),
tensors, and one-shot generators. Compare exact prepared IDs, masks, row count,
and row order through the real consumer. A generator test must reach all passes
that consume it (native plus EoRA/GPTAQ when enabled); do not replace it with a
list in the test. Keep re-iterable streams lazy where that is the contract.
Include empty/malformed rows, left/right padding, concatenation, the final partial batch, and unequal per-sample masks/positions where relevant. Boolean keep masks and additive causal masks have different semantics: an all-zero additive mask is not an all-padding boolean mask. Test BOS-present and BOS-less tokenizers, not the assumption that position zero is always a special token. Run consecutive batches/layers/parallel branches with distinct context and assert no stale mask or KV state leaks between them.
Keep actual processor containers through capture and replay. Use BatchFeature
with mixed sliding/full attention layers, padding and unequal conversations at
batch size two. Compare every replay mask and layer output with a native forward.
For recurrent decoders, capture a native full forward with multiple core visits
and post-loop layers. Compare every invocation's hidden input, positional state,
mask and output. Assert later-visit inputs differ from the first visit. Include
the architecture's complete head-input transform. Replay distinguishable batches
in scheduler order (for example 0, 4, 1, 5, 2, 6, 3, 7) and repeat subset replay.
Require each batch's native head input and one final-state entry per batch.
Use both unequal lengths and equal-shaped distinct values. Verify a new run
releases old state.
When splitting a float mask into rows, put a 1.0 in one row and only zeros
in another: the second row is padding in that 0/1 column. As a control, an
entirely zero additive column keeps every token. Pass both fixtures through
each affected container, including an actual HF Dataset, without converting
it to a dict first. Assert hand-listed token IDs and masks after preparation.
For packed token replay, make row identity observable, not just row count.
For example, use a padded grid [[11, 12, PAD], [21, 22, 23]]: kept row 2
must carry token 21, not PAD. Give each hidden row a distinct marker and assert
its token-aligned kwargs at the replay consumer against hand-listed pairs.
Include excluded sinks when applicable and an all-kept control. Do not use the
production row-index helper to build the expected pairs.
For bounded AWQ capture, route one expert through a plan match, a routed mismatch, then another match with a partial quota (e.g. local rows 0 and 2). With spare capacity, enumerate every expected row and its replay position. At capacity, check which sources survive across early and late batches. Exercise both one-row and partial multi-row quotas across enough batches to observe a full sink-selection period. Assert which batches include position zero and its share of retained rows. Include empty and fully retained batches as controls. Test explicit sink exclusion separately with a sparse boolean mask and check the surviving rows.
Follow tokenizer ownership for reusable normalization and AWQ safety for native replay, routing, and source/consumer qualification. Do not duplicate those architecture gates with tree-generated fake models.
Measurement windows, batching and logit capture
- For PPL, label token positions and enumerate the original next-token pairs.
Count each scored target exactly once across overlapping windows, adjacent
windows and the short tail. Use a position-local model with unequal losses
to compare the public PPL against the unsliced-row calculation. Real models
can change their predictions when their available context changes.
- For sampled metrics, hold the input rows and sampling cap fixed. Put the
only changed prediction in a short row beside longer rows, then vary batch
size to include a partial final batch. Check the sampled position count
and calculate each metric over the concatenated sample. For normalized
RMSE, accumulate reference energy across the same elements before dividing.
- Exercise capture through
BaseQModel.measure. Swap two FP32 logits that
round to the same FP16 value and assert the top-1 flip and nonzero error.
On a separate BF16 model, compare a finite logit above 65504 with itself
and require exact zero divergence. These probes distinguish rounding away
a real change from introducing one during capture.
Arithmetic and tensor geometry
BaseQModel.measure. Swap two FP32 logits that
round to the same FP16 value and assert the top-1 flip and nonzero error.
On a separate BF16 model, compare a finite logit above 65504 with itself
and require exact zero divergence. These probes distinguish rounding away
a real change from introducing one during capture.Follow the numerical oracle skill; its tolerances, packed-code rules, and hardware requirements remain unchanged. Cross the changed mechanism with supported FP16/BF16/FP32 and dispatch paths, including outer autocast and inference mode when they affect it.
For changes to a GPTQ-family solve, identify which variants override the changed stage. Run the same invariant through each applicable solver, not just the shared helper. For a per-channel grid, vary only a dead column and compare live weights, scales and zeros. For a replay-to-pack change, choose a code the replay dtype cannot recover and inspect the integer lane after the processor actually packs it; a close replay tensor is not evidence.
- Finite grid endpoints. Identify the dtype used to fit the grid, store its scale and replay or decode its codes. Pick adjacent source values where the extreme code survives one reconstruction and overflows the next. Assert the exact surviving code in each packed lane and the replay values. This catches both an unchecked cast and an overzealous clamp. If the format requires rejection, test the first invalid stored field and the last valid payload. For a scale that rounds to zero, include a genuinely zero row alongside a tiny nonzero row and inspect both scales and codes.
- Refinement after fitting. Give a hard candidate a better wide objective than a finite initializer but a reconstruction that overflows on replay. Prove both properties in the fixture. Check the returned replay tensor and recompute the reported objective from the actual packed codes and stored scales. Include an initializer that would change if regenerated from its own code, and a legal move that must improve the export.
- Grid refresh order. When a refit reads weights with deferred updates, split a quantization group across two processing blocks. Compare grid parameters and discrete codes with a one-column-at-a-time solve. When convergence and an accepted refresh can coincide, force that iteration and compare the continued solve with a control capped there. Measure reconstruction error independently on both results.
- Packed field coverage. Inventory the fields the decoder reads for each supported layout. Derive byte and bit positions from the wire format. Corrupt one field in the second of two blocks and assert the field and block reported. Cover trailing and split fields. For source-dependent repair, pack a tiny nonzero block next to an ordinary one. Check the repaired decode and compare the neighbour's bytes with its standalone packing.
- Candidate ranking. For a search whose optimum should survive a common rescale, choose a row with a unique winner other than the first candidate. Rescale by powers of two within the encodable range, including any global scale that defines the units. Rank the actual representable candidates independently in FP64. Check the selected index or local scale and the decoded payload. Test ties and format floors separately, where the expected decision can change. Carry the same fixture into independently implemented paths. For replay and a deployed packer, compare packed codes and stored scales for the same recipe, then rank the candidates independently using the rounded inputs each path actually received. For affine fitting, exercise the main fit, shrink search and fallback wherever they compute their own span.
- Exact selections. For nearest-centroid search, place the exact match second beside a one-storage-ULP neighbour, then reverse them. Check the index and residual against direct FP64 differences. For one-hot mixing, select each candidate in turn and compare the forward with that candidate exactly. Large finite candidates of opposite signs expose a delta that overflows before the selection.
When a memory budget is meant to change only chunk size, force the same unequal rows into one chunk and separate chunks. Check both the export and the reported objective against hand-computed oracles; two budgets can agree on the same wrong answer.
When refactoring a dtype lock or a wide fallback, keep the input dtype fixed and toggle ambient autocast, not the module dtype. Choose a wide operand that overflows when narrowed but gives a finite output. Compute the reference outside autocast; assert the public value and dtype in both contexts.
For layers supporting activation gradients, pack or load under
torch.inference_mode(), leave that context and run the same layer with
x.requires_grad=True. For a linear layer compare x.grad after backward
against grad_output @ W using the fixture's reference weight. Repeat on
the affected device and dtype where inference selects a fused op, and verify
the no-grad control still takes that op. If full-graph compilation is
advertised, execute the compiled forward with fullgraph=True too.
- For bias changes, apply the linear bias contract. Use cancellation, range endpoints, underflow, and nonfinite inputs where supported. Check that the fixture reaches the intended epilogue.
- For scale folding, cross the storage dtype with the activation dtype. Choose a fold that fits on disk but overflows or rounds a nonzero to zero on the compute cast. Compare the first forward to an independently scaled product, and check an in-range fold still takes the fast path exactly once.
- For an AWQ fold, exercise an optional reader and a same-width projection that reads a different tensor. Compare the planned consumers with inputs observed during a native forward, then apply a nonuniform scale and check output neutrality. For SmoothQuant fold verification, pair distributed rounding drift with an isolated logit error that preserves argmax and passes global RMS. Run the acceptance and rejection controls per supported dtype.
- Test contiguous, row-strided, and column-strided inputs, batched prefill and
single-token calls. Assert fixture strides before calling the public wrapper;
.reshape()can preserve the bad stride, especially at batch size one. - Cover zero/one rows and dimensions immediately below/at/above the actual tile, group, or alignment boundary, plus ragged final tiles. Assert unsupported geometry is rejected or selects a supported fallback before native dispatch.
- Assert output shape/dtype, oracle error, native/fallback selection, and retained storage. Compare arithmetic error separately from required output rounding.
Audit sibling backends and all call sites of a changed primitive. A portable fix does not repair a fused kernel, and a default-path test does not qualify explicit selection. Add cases for affected siblings or record why they differ.
4. Make coverage executable and report it honestly
Put hardware-independent contract tests outside module-wide GPU skip markers; keep native-device tests separately marked with precise prerequisites. Ensure the intended CI job collects and runs the new node, not just that the file exists. No blanket exception-to-skip wrappers, unused test methods, opt-in env gates, or silently empty parameter sets. Do not widen tolerances or refresh expected outputs solely to make a failing regression green.
Run from tests/ when local helpers require it, for example:
cd tests
python -m pytest test_dynamic_config_invalidation_4475.py -q -ra
The PR's validation table must name: invariant/trigger, test node, red evidence, green command/result, and hardware/dependency skips. State which sibling paths remain unverified. Mocks, CPU runs, and skipped GPU tests must never be reported as native qualification. Documentation-only updates need link/frontmatter and evidence checks, not claims that these new runtime requirements already pass.
5. Separate test gaps from structural contract failures
Escalate beyond another isolated test when fixes repeatedly transfer ownership between consumers, duplicate representation conversion or retry preparation, or depend on undocumented ordering of mutation, publication, and cleanup. A missing stride case or boundary fixture alone does not justify a redesign.
Describe the violated invariant, current owner(s), and recurrence evidence. Propose one explicit ownership/transition contract, a bounded migration using existing extension points, and conformance tests for every affected consumer. Distinguish already-landed fixes from proposed architecture and unverified bug reports. Preserve storage, compatibility, memory, and concurrency constraints; do not substitute a broad rewrite or dense weight cache for a precise contract.
When the user requests an issue for structural findings, publish the proposal
with evidence links and acceptance criteria, and append @Qubitium. Otherwise
report the recommendation for approval rather than opening an unsolicited issue.
The 2026-11-17 contract proposal
illustrates persistence ownership, transactional attempts, asynchronous scratch
lifetime, and immutable execution policy; it is not implemented behavior.