Skip to content

[BUG] AwqMarlinLinear (AUTO for AWQ on CUDA) is intermittently non-deterministic: same input gives different outputs (occasionally a whole 64x64 tile off by 0.25), PPL of one AWQ ckpt varies across processes; GPTQ MarlinLinear is stable #4683

Closed

Description

@Qubitium

Found on main @ 12c1273, RTX 4090 (sm_89, CUDA 13.2, torch 2.15). The same behaviour is already present at bd922cd and 597b39b, so this is not a recent regression.

What is wrong

AwqMarlinLinear (the AUTO kernel for AWQ checkpoints on CUDA) sometimes returns a different result for an identical input. The call path is nn_modules/qlinear/marlin_awq.py:393 -> utils/marlin.py:apply_awq_marlin_linear -> gptq_marlin_gemm, with use_fp32_reduce=True and no atomics.

Under the same conditions, GPTQ MarlinLinear, which uses the same extension and has no zero-points, stayed bitwise stable in every test below. So the cause looks specific to the AWQ (kU4 + zero-point) Marlin path. The cause may be a reduction/lock race in the kernel or a scheduling path only AWQ takes (for example the AWQ-only narrow_fp32_awq branch in gptqmodel_ext/marlin/gptq_marlin.cu:908). I have not pinned it down.

The visible effect: wikitext PPL and logits of the same checkpoint change from process to process, and occasionally an entire 64x64 output tile is off by far more than fp16 rounding.

Evidence

  1. Same checkpoint, separate processes. Llama-3.2-1B-Instruct AWQ 4-bit g128, AUTO = AwqMarlinLinear, wikitext-2 80x512:

    • main: 21.881656, 21.881501, 21.881340
    • 597b39b: 21.881382
    • bd922cd: 21.881390

    On a checkpoint quantized on main, Qwen2.5-0.5B-Instruct AWQ gives 24.5038982 three times and 24.5039085 once, and Llama gives 21.883863 vs 21.883737. Every tensor hash of the checkpoint is equal. The GPTQ/RTN checkpoints evaluated on MarlinLinear (gptq4, gptq4_desc, rtn4, foem4, gptaq4) give bitwise-equal PPL in every repeated process.

  2. Same process, same input. In 40 back-to-back full-model forwards of one 512-token window (Llama awq4), 3 logits differ. A forward hook that fingerprints each leaf module's input and output on the GPU (no host sync) puts the first divergence each time in an AwqMarlinLinear whose input was bit-identical: layers.4.mlp.up_proj, layers.5.mlp.down_proj, layers.9.mlp.down_proj. Running the same loop on the GPTQ MarlinLinear checkpoint of the same model gives 0/60.

  3. Module level, no sync between launches. I ran layer-4 q/k/v/o/gate/up/down back to back on fixed random inputs and compared each result to the first call:

    • main, M=512: 1/600 mismatching outputs
    • bd922cd, M=512: 5/3000
    • main, M=2048: 1/2800. That mismatch was in gate_proj, with 3929 elements in one 64x64 tile off by up to 0.247 (|out| max 12.6). The kernel's normal error against an fp32 dequant reference is ≤ 0.002, so this is a wrong tile, not rounding.
    • GPTQ MarlinLinear, same shapes and loop: 0/4500.

    It is intermittent: other 56k-call loops showed 0 mismatches. Full-model forwards hit it most reliably.

Minimal repro (full-model loop)

import torch, hashlib
from gptqmodel import GPTQModel
m = GPTQModel.load("<Llama-3.2-1B-Instruct AWQ 4-bit g128 ckpt>")   # AUTO -> AwqMarlinLinear
tok = m.tokenizer
x = tok(open("wikitext2_test.txt").read()[20000:26000], return_tensors="pt").input_ids[:, :512].cuda()
hs = set()
with torch.inference_mode():
    for _ in range(40):
        hs.add(hashlib.sha256(m.model(x).logits.cpu().numpy().tobytes()).hexdigest())
print(len(hs))   # AwqMarlin: 2 (sometimes 3); same loop on a GPTQ ckpt (MarlinLinear): 1

Suggested next steps

  • Run the AWQ Marlin GEMM under compute-sanitizer --tool racecheck/synccheck for the Llama-1B shapes (K=2048/8192, N=512..8192, M=512/2048).
  • Check the zero-point (has_zp) and AWQ-only scheduling paths in gptq_marlin.cu for a lock/barrier ordering problem in the fp32 global reduce.
  • Until it is fixed, a determinism test is worth adding (see below).

Test gap

No test checks Marlin determinism. A test should loop an AwqMarlinLinear (or a 2-layer model) forward N times without host syncs and assert bitwise-equal outputs. The same test for MarlinLinear passes today.

Severity

Low-medium. The usual impact is ~1e-5 relative PPL noise and non-reproducible eval scores for AWQ checkpoints. The occasional wrong 64x64 tile (0.25 abs on outputs ~10) is a silent correctness error.

🤖 Generated with Claude Code

Activity

  1. Qubitium commented on Nov 17, 2026

    @Qubitium
    CollaboratorAuthor

    Agent claim released: agent-53ba17eb4d83 finished this issue.

    Pull request: #4726

    Reproducing AwqMarlinLinear non-determinism on GB10 (sm_121) and tracing the per-module workspace/stream

  2. Qubitium commented on Nov 17, 2026

    @Qubitium
    CollaboratorAuthor

    A correction and a more reliable repro.

    The trigger is another process running kernels on the same GPU. On an otherwise idle RTX 4090, the snippet in the issue gave 1 distinct logits hash in 2 x 40 forwards. My earlier numbers came from runs where other quantization jobs shared the GPU. With a plain fp16 GEMM loop running in a second process, it reproduces every time:

    # process A (background load)
    import torch, time
    a = torch.randn(4096, 4096, device="cuda", dtype=torch.float16); t = time.time()
    while time.time() - t < 400:
        for _ in range(50): b = a @ a
        torch.cuda.synchronize()
    # process B: the 40-forward loop from the issue body
    # distinct logits hashes over 40 identical forwards (main @ 12c1273c2, RTX 4090):
    #   Llama-3.2-1B-Instruct AWQ 4-bit g128, AwqMarlinLinear : 9   (second run: 9)
    #   Llama-3.2-1B-Instruct GPTQ 4-bit g128, MarlinLinear   : 1
    #   same AWQ ckpt, no second process                      : 1   (second run: 1)

    GPTQ Marlin stays bitwise stable under the same load. AWQ Marlin's output depends on how its thread blocks are scheduled, which points to an ordering assumption in the AWQ/zero-point path of the Marlin reduction that only holds when the kernel has the GPU to itself. In real use the GPU is often shared (eval harness plus server, several workers), so this explains AWQ eval scores that differ between otherwise identical runs.

    🤖 Generated with Claude Code

  3. Qubitium commented on Nov 17, 2026

    @Qubitium
    CollaboratorAuthor

    Narrowing it down, with the same 40-forward loop and the same background GEMM process on the GPU:

    checkpoint / backend distinct logits / 40
    Llama-3.2-1B AWQ, AWQ_GEMM (AwqGEMMLinear) 1
    Llama-3.2-1B AWQ, AWQ_GEMM_TRITON 1
    Llama-3.2-1B AWQ, AWQ_TORCH 1
    Llama-3.2-1B AWQ, AUTO (AwqMarlinLinear) 9, 9
    Qwen2.5-0.5B AWQ, AUTO (AwqMarlinLinear) 1

    So only the Marlin AWQ path is affected, and only for the Llama-1B shapes (K/N in {2048, 8192}, M=512). The Qwen-0.5B shapes (896/4864) stayed stable. In the per-module test, the first divergence was in mlp.up_proj / mlp.down_proj and the wrong 64x64 tile was in gate_proj (K=2048, N=8192). The shape-gated AWQ scheduling in gptq_marlin.cu (narrow_fp32_awq, prob_k >= 2048) and the split-K / global-reduce partitioning these shapes select are the places to check first.

    🤖 Generated with Claude Code

  4. Qubitium commented on Nov 17, 2026

    @Qubitium
    CollaboratorAuthor

    Taking this.

  5. Qubitium commented on Nov 17, 2026

    @Qubitium
    CollaboratorAuthor

    Agent claim: agent-root-4683 is working on this issue now.

  6. Qubitium commented on Nov 17, 2026

    @Qubitium
    CollaboratorAuthor

    Agent claim released: agent-53ba17eb4d83 finished this issue.

    Pull request: #4859

    Reproduce AwqMarlinLinear nondeterminism on GB10 sm_121 (same input, repeated forwards, per-tile error vs torch); audit the #4657 marlin tile/scale staging for the race; fix and add a determinism test.

  7. Qubitium commented on Nov 17, 2026

    @Qubitium
    CollaboratorAuthor

    Agent release: agent-root-4683 finished this issue — merged PR #4859 (squash). Root cause: the Marlin lock-counter workspace was per module, not per stream; two streams consumed each other’s counters (deadlock or a wrong tile). Each forward now borrows a zeroed copy keyed by the current CUDA stream.

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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions