Skip to content

[BUG] Per-model kernel policy leaks across loads: bnb Triton dispatch and ParoQuant Triton fp32_accum read the process-global KernelConfig at forward, not the module snapshot #4555

Closed

Description

@Qubitium

Found on main @ 4b65923, RTX 4090 (sm89), torch 2.15 + CUDA 13.2, triton 3.9.

What is wrong

docs/kernel-config.md ("Lifetime and serialization") and docs/backend-selection.md say that each quantized linear owns a snapshot of its policy (BaseQuantLinear.kernel = snapshot_kernel_config(...)), and that "Later loads, configure_kernel calls ... do not change those modules." Two inference dispatch sites ignore the module snapshot and read the process-wide get_kernel_config() on every forward. That process-wide policy is replaced by every GPTQModel.load(...) / from_quantized(...) (_install_kernel_policy -> configure_kernel).

  1. bitsandbytes 4-bit Triton path. gptqmodel/nn_modules/qlinear/bitsandbytes_triton.py:109 (available_for): forced = get_kernel_config().bitsandbytes_triton. BitsAndBytesLinear.forward (bitsandbytes.py:901) calls should_use(...) without passing self.kernel. The typed BitsAndBytesConfig(triton=True) added in fix(backend): keep resolved policy out of QuantizeConfig.kernel; apply every pool setting (#4446, #4448, #4449) #4497 therefore only applies until the next load. On ROCm the opposite happens: a model loaded with triton=False is switched back to Triton.
  2. ParoQuant Triton fused GEMM accumulation. quantization/paroquant/modules/triton/gemm.py:476,501: paroquant_gemm_triton_decode/prefill pass fp32_accum=get_kernel_config().fp32_accum. ParoQuantTritonLinear._forward_triton_decode/_prefill (paroquant_triton.py:144-150) never forward the module's own self.fp32_accum / self.kernel.fp32_accum. So ParoQuantTritonConfig(fp32_accum=False) (or True) is ignored whenever the process policy differs. That is the case right after any other load, and also when the module is built with an explicit kernel=.

This is the per-model leak that #4446/#4448/#4497 set out to remove. These two sites were missed.

Repro 1: bnb, public API, two loads in one process

Checkpoint: Qwen2.5-0.5B-Instruct quantized with BitsAndBytesConfig(bits=4) and saved.

import torch
from gptqmodel import GPTQModel
from gptqmodel.utils.backend_config import BitsAndBytesConfig
from gptqmodel.nn_modules.qlinear import bitsandbytes_triton as bt
calls = {"n": 0}; orig = bt.matmul_4bit
def spy(*a, **k): calls["n"] += 1; return orig(*a, **k)
bt.matmul_4bit = spy

a = GPTQModel.load(ckpt, backend=BitsAndBytesConfig(triton=True), dtype=torch.float16)
x = torch.randint(100, 2000, (1, 64), device="cuda")
with torch.inference_mode(): la = a.model(x).logits.float()
print("model A, after its own load: triton calls =", calls["n"])
b = GPTQModel.load(ckpt, dtype=torch.float16)          # another model, default policy
calls["n"] = 0
with torch.inference_mode(): la2 = a.model(x).logits.float()
print("model A, after loading model B: triton calls =", calls["n"])
print("module A snapshot bitsandbytes_triton =",
      next(m for m in a.model.modules() if type(m).__name__ == "BitsAndBytesLinear").kernel.bitsandbytes_triton)
print("max |logits A before - after| =", (la - la2).abs().max().item())

Output:

model A, after its own load: triton calls = 168
model A, after loading model B: triton calls = 0
module A snapshot bitsandbytes_triton = True
max |logits A before - after| = 0.078125

Repro 2: ParoQuant Triton

import torch
from gptqmodel.utils.kernel import KernelConfig, configure_kernel
from gptqmodel.nn_modules.qlinear.paroquant_triton import ParoQuantTritonLinear
import gptqmodel.quantization.paroquant.modules.triton.gemm as g
seen = []; orig = g._paroquant_gemm_triton
def spy(*a, **k): seen.append(k.get("fp32_accum")); return orig(*a, **k)
g._paroquant_gemm_triton = spy

m = ParoQuantTritonLinear(bits=4, group_size=128, sym=True, desc_act=False, in_features=256, out_features=256,
                          bias=False, register_buffers=True, kernel=KernelConfig(fp32_accum=False)).cuda()
print(m.kernel.fp32_accum, m.fp32_accum)              # False False
configure_kernel(None)                                 # what any later GPTQModel.load() does
x = torch.randn(64, 256, device="cuda", dtype=torch.float16)
m._forward_triton_prefill(x); m._forward_triton_decode(x[:1])
print(seen)                                            # [True, True]  <- module asked for False

The reverse also happens: a module built with fp32_accum=True while the process policy is False gets fp32_accum=False.

Suggested fix

  • bitsandbytes_triton.available_for/should_use: take a kernel (or forced) argument. BitsAndBytesLinear.forward passes self.kernel.bitsandbytes_triton.
  • paroquant_gemm_triton_decode/prefill: add an fp32_accum parameter. ParoQuantTritonLinear passes self.fp32_accum, as ParoLinear already does at paroquant.py:479.
  • Add a guard test: grep nn_modules/qlinear/** and the GEMM helpers they call for get_kernel_config() reachable from forward. The remaining hits (gemm_awq_triton.py:86, utils/tt_blockfloat_cuda.py:226, utils/swordfish.py:361) are only fallbacks when the caller passes None. Today the module callers do pass their own values there, but nothing pins that.

Test that should have caught it

tests/test_backend_config_reuse_4446.py / tests/test_runtime_config_4448.py check module snapshots, not the value that reaches the dispatch site. A "load A with policy X, load B with defaults, forward A, assert the path/flag" test per kernel with a typed config would catch both.

Severity

Medium. A model silently changes kernel path and numerics (logit deltas up to 0.08 in the bnb repro) depending on what else was loaded in the process. This breaks the documented isolation contract and the new typed BitsAndBytesConfig(triton=...) / ParoQuantTritonConfig(fp32_accum=...) options.

🤖 Generated with Claude Code

Activity

  1. Qubitium commented on Nov 17, 2026

    @Qubitium
    CollaboratorAuthor

    Claimed. This issue is now owned by a dedicated worker; a fix PR referencing it will follow.

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