Skip to content

[PERF] #5075 incomplete: ParoLinear declares CPU INDUCTOR, but every layer of a real (non-identity rotation) Paro checkpoint graph-breaks twice on tensor_cache_key is_inference() in the rotation runtime cache; CPU level test uses an identity rotation #5115

Closed

Description

@Qubitium

Found on main @ 7b8f127, CPU-only (x86-64 AVX512-BF16, torch 2.15.0, CUDA hidden).

What is wrong

#5075 ("make NF12, Paro and QQQ inductor-ready on CPU") declares ParoLinear.SUPPORTS_COMPILE_LEVEL_BY_DEVICE = {"cpu": COMPILE_LEVEL.INDUCTOR} (gptqmodel/nn_modules/qlinear/paro.py:120). docs/kernel-compile-matrix.md lists ParoLinear with CPU level INDUCTOR, and the README 7.11.2 notes say supported CPU kernels "compile with Inductor without graph breaks". That only holds for a Paro layer whose rotation is the identity.

For a real Paro checkpoint, which has learned rotations, every ParoLinear breaks the graph twice on CPU:

  • ParoLinear._rotate_inputs (paro.py:638-646) takes the CPU eval branch. It calls _ensure_rotation_runtime_dtype() (paro.py:594-617), which builds its cache key from tensor_cache_key(self.theta) and tensor_cache_key(self.channel_scales).
  • tensor_cache_key (nn_modules/qlinear/_runtime_cache.py:32) calls tensor.is_inference(), and Dynamo raises Unsupported: Encountered tensor.is_inference() during tracing.

#5075 put torch.compiler.is_compiling() guards on the CPU layout and transform-lock paths, but the rotation runtime-dtype cache has no such guard.

The CPU level test does not catch this. tests/kernels/test_kernel_compile_levels_cpu.py:317-321 builds the Paro case with _pack_awq(ParoLinear, bias=True). That layer has an identity rotation (_rotation_identity=True), so _rotate_inputs returns before it reaches the cache.

Repro

I quantized Qwen2.5-0.5B-Instruct truncated to 2 layers with ParoConfig(bits=4, group_size=128) (32 C4 samples), saved it, and reloaded it on CPU with backend="auto", which gives ParoLinear in bf16:

import torch, torch._dynamo as dynamo
from gptqmodel import GPTQModel
from gptqmodel.nn_modules.qlinear import BaseQuantLinear
m = GPTQModel.load(paro_ckpt, backend="auto")   # CPU
for name, mod in m.model.named_modules():
    if isinstance(mod, BaseQuantLinear) and ".0." in name:
        x = torch.randn(1, 8, mod.in_features, dtype=torch.bfloat16)
        with torch.inference_mode():
            mod(x)                                # eager warm-up first
            e = dynamo.explain(mod)(x)
        print(name, mod.bias is not None, mod._rotation_identity, e.graph_count, e.graph_break_count, e.break_reasons[0].reason.split("\n")[0])

Output (the same with torch.no_grad() instead of inference_mode):

model.layers.0.self_attn.q_proj True  False 3 2 Encountered tensor.is_inference() during tracing
model.layers.0.self_attn.o_proj False False 3 2 Encountered tensor.is_inference() during tracing
model.layers.0.mlp.gate_proj    False False 3 2 Encountered tensor.is_inference() during tracing
model.layers.0.mlp.down_proj    False False 3 2 Encountered tensor.is_inference() during tracing
... (all 7 projections)

torch.compile(mod, backend="inductor", fullgraph=True) raises Unsupported: Encountered tensor.is_inference() during tracing for every projection. Bias-free projections are affected too, so this is not the documented #4068 biased-ATen exception. At model level, dynamo.explain(model) gives 29 graphs / 28 breaks for 2 layers (2 per projection), and m.optimize() then records 26 graph breaks.

The same probe on the other CPU kernels in the table (TorchCpuAvx512Linear, TorchCpuAvx512AwqLinear, AwqGEMVTorchLinear, QQQTorchLinear, TorchFP8Linear, NF12Linear, BitsAndBytesLinear, VPTQLinear, TorchLinear 8-bit) gives 1 graph / 0 breaks, and inductor fullgraph=True compiles each of them.

Suggested fix

In _ensure_rotation_runtime_dtype, under torch.compiler.is_compiling(), return the eager-built _runtime_theta / _runtime_channel_scales without recomputing the key. _ensure_runtime_dtype already does the same for the layout. Alternatively, pre-build the rotation runtime tensors in post_init(). Then add a test case with a non-identity rotation (random theta, non-unit channel_scales) to test_kernel_compile_levels_cpu.py.

Severity

Low to medium (performance and documentation). Output stays correct: the eager fallback runs at the breaks. However, the declared INDUCTOR level and the "no graph breaks" claim are false for every real Paro checkpoint on CPU, and optimize() on a CPU Paro model is fragmented into 2 extra graphs per projection.

🤖 Generated with Claude Code

Activity

  1. Qubitium commented on Nov 18, 2026

    @Qubitium
    CollaboratorAuthor

    Agent claim released: agent-f60b36e15e6d finished this issue.

    Pull request: #5167

    Making the Paro rotation runtime-dtype cache traceable so a real (non-identity) rotation reaches the declared CPU INDUCTOR level

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