Repository navigation
fix(marlin): seed g_idx with the canonical contiguous index (#4239) - #4250
Merged
Merged
Conversation
`MarlinLinear.__init__` registered `g_idx` with `torch.empty`. The #4053 contiguity guard in `post_init()` reads that tensor to decide whether a checkpoint stores a real activation-order index, so uninitialised memory was interpreted as a permutation: - a `desc_act=False` checkpoint that omits `g_idx` silently flipped to the activation-order path and decoded with an index built from garbage; - tile-misaligned shapes (e.g. K=288/N=200) raised NotImplementedError; - `test_inference_fp16_overflow` hit "For act_order, num_groups must be > 1". Seed the placeholder with `arange(K) // group_size`, the same canonical mapping the base class stores for `desc_act=False`. It is the identity ordering, it keeps `load_state_dict()` shape-compatible, and it keeps a checkpoint without `g_idx` on the contiguous fast path. A checkpoint that really stores a permutation still takes the activation-order path, so #4053 is preserved. Tests use an independent FP64 oracle for the dequantized matmul.
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.
Fixes #4239
Root cause
MarlinLinear.__init__registeredg_idxwithtorch.empty(K, dtype=int32). The#4053 contiguity guard in
post_init()readsg_idxto tell a realactivation-order checkpoint from a plain
desc_act=Falselayer, so it consumeduninitialised memory:
desc_act=Falsecheckpoints that omitg_idxflipped todesc_act=Trueanddecoded with a permutation built from garbage (e.g.
[-1151343613, 5, 0, 0]),or read out of bounds;
NotImplementedError(K=288/N=200);test_inference_fp16_overflowhitRuntimeError: For act_order, num_groups must be > 1.Fix
Seed the placeholder with
arange(K) // group_size— the same canonical mappingGPTQQuantLinearstores fordesc_act=False. It is the identity ordering, keepsload_state_dict()shape-compatible, and leaves a checkpoint withoutg_idxonthe contiguous fast path. A checkpoint that really stores a permutation still
takes the activation-order path, so #4053 is preserved (covered by a dedicated
test).
Diff is 2 files touched minimally (
marlin.pyplaceholder only, plus a shortdocs/checkpoint-interop.mdnote) and 1 new test file.Fail-before / pass-after (real output)
New suite on
origin/main(7c7d704) with the test file copied in:Representative failures on main:
Same suite on this branch:
The one test that passes on both is
test_noncontiguous_checkpoint_g_idx_still_selects_the_act_order_path, whichpins the #4053 behaviour.
Pre-existing tests named in the issue, on main:
On this branch:
End-to-end repro from the issue (K=N=256, checkpoint state dict without
g_idx):g_idx[:4]after ctor[-1151343613, 5, 0, 0][0, 0, 0, 0]desc_actafterpost_init()True(warn + act-order)False0.0209960.000244Numerics
The new tests do not use any gptqmodel kernel as their own reference. They build
GPTQ int32 words and scales directly, then compare the module output with an
FP64 oracle computed in the test:
x @ (scales[g_idx] * (codes - 8)).T.Relative error is ~2.8e-4 (fp16 scale resolution) for the contiguous, identity
act-order, and permuted act-order paths.
Validation
Marlin regression surface on this branch (
test_marlin_jit,test_inference_fp16_overflow,test_marlin_permute,test_marlin_cpu_offload_post_init,test_marlin_device_profile,test_marlin_import_min,test_marlin_scratch_interface,test_marlin_scratch_regressions, the new file):143 passed, 1 skipped, 5 failed. The 5 failures reproduce identically onorigin/mainin thisenvironment (
test_marlin_cuda_smoke_build_and_forward: "already loaded in thisPython process"; 4x
test_marlin_cpu_offload_refreshes_packed_weights:unexpected
qzeros_formatkey).tests/test_marlin_scratch_cuda.pyalso has 4pre-existing AWQ-8bit failures on main.
test_q4_marlin.py/test_awq_marlin.pycannot be collected here (
ModuleNotFoundError: parameterized).Residual risk
g_idxverbatim. Acheckpoint whose index is out of range for the scale table (rather than
merely non-contiguous) would still be used to build the permutation; only the
placeholder is fixed here. Bounds validation for the act-order flip would be a
separate change.
desc_act=Truewith nog_idxin the checkpoint now deterministically meansthe identity ordering; the true permutation is unrecoverable in that case, but
the previous behaviour was uninitialised memory.