Skip to content

[MEM] Paro on CPU (AUTO ParoLinear) keeps a second kernel-layout copy of every packed weight (bf16: _cpu_packed_* attrs; fp16: hidden TorchAtenAwqLinear) next to the checkpoint buffers: quantized linears 2.0x after the first forward #4814

Closed

Description

@Qubitium

Found on main @ dba142d, x86-64 AVX512-BF16 host (CPU only).

What is wrong

ParoLinear (AUTO for Paro checkpoints on CPU) builds a second, kernel-layout copy of the packed weight on its first CPU forward and keeps it for the life of the module. The checkpoint qweight/qzeros/scales buffers stay resident next to it. Both CPU paths do this:

  • bf16: paro.py:621 -> AwqTorchLinear._forward_cpu_avx512 -> _ensure_cpu_packed (nn_modules/qlinear/torch_awq.py:315-361) stores _cpu_packed_qweight, _cpu_packed_qzeros, _cpu_packed_scales (fp32) and _cpu_packed_bias (fp32) as plain attributes.
  • fp16: paro.py:500-560 _forward_cpu_aten builds a hidden TorchAtenAwqLinear (self._cpu_aten_layer), aliases the checkpoint tensors into it and calls transform_cpu. That rebinds the helper's qweight to a new int4pack tensor (plus scales_and_zeros) while the module keeps the original.

This is the same 2x residency that #4395/#4532 removed for the GPTQ/AWQ CPU int4 kernels, here on a separate code path (see also #4783 and #4805).

Measured: Qwen2.5-0.5B-Instruct Paro 4-bit g128 (ckpt 443 MiB), device=cpu, AUTO = ParoLinear x168, tensor bytes after 3 forwards

                     model tensors        quantized-linear tensors          new attributes
bf16 (AVX512 path)   443.2 -> 629.6 MiB   183.4 -> 369.8 MiB (2.02x)        _cpu_packed_qweight 170.6, _cpu_packed_scales 10.7 (fp32), _cpu_packed_qzeros 2.7, ...
fp16 (ATen path)     443.2 -> 635.1 MiB   ~2.05x                            _cpu_aten_layer: qweight 170.6, scales_and_zeros 21.3, qzeros 10.7

The ratio is per weight, so an 8B Paro model would carry about +3.5 GiB, as with #4805.

Minimal repro

import torch
from gptqmodel import GPTQModel
m = GPTQModel.load("<Paro 4-bit checkpoint>", dtype=torch.bfloat16, device="cpu")   # AUTO -> ParoLinear
mods = [x for x in m.model.modules() if type(x).__name__ == "ParoLinear"]
with torch.inference_mode():
    m.model(torch.randint(100, 1000, (1, 8)))
mib = lambda ts: sum(t.numel() * t.element_size() for t in ts if t is not None) / 2**20
print(mib(x.qweight for x in mods), mib(x._cpu_packed_qweight for x in mods))   # 170.62 170.62

Suggested fix

Keep one resident layout on CPU:

Keep the cached scales/bias in the checkpoint dtype, or widen them per call. Restoring them from fp32 to fp16/bf16 is exact, but storing them in fp32 doubles their size.

Test that should have caught it

The Paro CPU tests check numerics only. A parametrized CPU residency test over every kernel would have caught it: tensor bytes after the first forward at most 1.1x of the checkpoint's quantized bytes.

Severity

Medium: about 2x host RAM for the quantized linears on the default CPU path for Paro.

🤖 Generated with Claude Code

Activity

  1. Qubitium commented on Nov 17, 2026

    @Qubitium
    CollaboratorAuthor

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

    Pull request: #4832

    Fixing: reproduce, root-cause, add regression test, keep existing suites green.

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