Skip to content

[BUG][Marlin] MarlinLinear registers g_idx with torch.empty; the #4053 contiguity guard then treats uninitialised memory as an act-order index #4239

Closed

Description

@Qubitium

Severity: medium. It hits checkpoints that omit g_idx for desc_act=False, and directly constructed modules.
Version: 7.11.0 @ 9dad249

Summary

nn_modules/qlinear/marlin.py:203-210 registers g_idx as torch.empty(in_features, dtype=int32). The base class uses arange(K) // group_size.

When a checkpoint doesn't provide g_idx, the guard added for #4053 (_g_idx_is_contiguous, marlin.py:~371-393) sees garbage. It then either:

  • raises NotImplementedError("checkpoint g_idx is non-contiguous…") for non-tile-aligned shapes; or
  • silently flips desc_act=True and decodes with a permutation built from uninitialised memory (values like -1.7e9, which can also read out of bounds).

Reproduce (CUDA)

import torch
from gptqmodel.nn_modules.qlinear.marlin import MarlinLinear
from gptqmodel.nn_modules.qlinear.torch import TorchLinear
from gptqmodel.utils.backend import BACKEND
K = N = 256; lin = torch.nn.Linear(K, N, bias=False).half()
s = (lin.weight.float().abs().reshape(N, K//32, 32).amax(-1) / 7).half()
ref = TorchLinear(bits=4, group_size=32, sym=True, desc_act=False, in_features=K, out_features=N, bias=False, backend=BACKEND.TORCH)
ref.pack_original(lin, s, torch.full_like(s, 8), torch.arange(K, dtype=torch.int32) // 32); ref.qzero_format(2)
sd = {k: v for k, v in ref.state_dict().items() if k != "g_idx"}          # checkpoint without g_idx (desc_act=False)
m = MarlinLinear(bits=4, group_size=32, desc_act=False, sym=True, in_features=K, out_features=N, bias=False, dtype=torch.float16).cuda()
m.load_state_dict(sd, strict=False); print(m.g_idx[:4]); m.post_init(); print(m.desc_act)

Actual:

  • Prints garbage g_idx (e.g. [-1726948057, 5, 0, 0]).
  • Warns "decoding with the Marlin activation-order path" and sets desc_act to True.
  • Output differs from the Torch reference by 0.049 (max |y| ≈ 2.1).
  • With K=288, N=200 it raises NotImplementedError instead.

Failing repo tests:

  • tests/test_marlin_jit.py::test_marlin_quant_linear_post_init_pads_weight_scales_and_bias
  • tests/test_marlin_jit.py::test_marlin_quant_linear_post_init_uses_compute_dtype_for_repack
  • tests/test_inference_fp16_overflow.py::test_marlin_bias_cancels_before_the_fp16_cast[gptq] (RuntimeError: For act_order, num_groups must be > 1)

Expected

Initialise g_idx to arange(K) // group_size, as the base class does, so a desc_act=False layer stays on the fast path.

Related: #4053 (closed; its fix added the guard).


Found during an AI-assisted review (Claude Code) of 9dad249; repros were run on RTX 4090/5090 (CUDA 13) and/or Radeon AI PRO R9700 (ROCm) unless marked static/suspected.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions