Skip to content

[PERF] Regression from #4915 (fix of #4863): FP8 checkpoints loaded on cuda:0 keep every packed weight on CPU (int ordinal 0 is falsy in _restore_checkpoint_buffers); decode 4x slower, VRAM 0.25 vs 0.59 GiB #4964

Closed

Description

@Qubitium

Found on main @ 3867c82, RTX 4090 (CUDA 13.2, torch 2.15) and AMD R9700 (ROCm 10.1).

What is wrong

Since #4915 (fix of #4863), every FP8 checkpoint loaded onto cuda:0 keeps its packed FP8 weight on the CPU. Only the scales and biases reach the GPU. TorchFP8Linear then copies the weight host-to-device on every forward (nn_modules/qlinear/fp8.py:599), so decode is about 4x slower and the reported VRAM is a fraction of the checkpoint size. The output is still correct, so nothing fails.

Root cause, gptqmodel/utils/model.py:

Bisect

Archive-based, loading the same saved Qwen2.5-0.5B-Instruct FP8 checkpoint with each commit:

Repro

import torch
from gptqmodel import GPTQModel
from gptqmodel.quantization.config import FP8Config, CalibrationConfig
m = GPTQModel.load("Qwen/Qwen2.5-0.5B-Instruct", FP8Config(), dtype=torch.bfloat16)
m.quantize(CalibrationConfig(dataset=c4_texts[:16])); m.save(out); del m
q = GPTQModel.load(out, dtype=torch.bfloat16)
mod = next(x for x in q.model.modules() if hasattr(x, "QUANT_TYPE"))
print(torch.cuda.memory_allocated() / 2**30, mod.weight.device, mod.weight_scale_inv.device)

Output (prefill: 10 forwards of 512 tokens; decode: 64-token greedy generate):

parent 3a5a5be main
VRAM after load 0.588 GiB 0.255 GiB
weight device cuda:0 cpu (weight_scale_inv on cuda:0)
prefill 512 tok 14.7 ms 52.2 ms (3.6x)
decode 73.8 tok/s 18.6 tok/s (4.0x slower)
generated text identical identical

At full size on the same build:

  • OLMoE-1B-7B (MoE, 6.66 GB FP8 checkpoint) reloads with 0.40 GiB allocated on the GPU, on ROCm and on CUDA.
  • Round 14 (b225a43) measured Llama-3.1-8B FP8 reload VRAM at 8.46 GB, the same as the checkpoint size.

Suggested fix

Test for None instead of truthiness:

mapped = mapped_device(name)
target_device = mapped if mapped is not None else target_device

Alternatively, normalize ints with torch.device("cuda", n) inside mapped_device. Audit any other device_map[...] or ... patterns that now see int ordinals.

Test that should have caught it

  • tests/test_load_device_context_4863.py checks only CUDA contexts, and only for cuda:1.
  • Add an FP8 save/reload test on cuda:0 that asserts every quantized module's weight.device == scale.device == cuda:0, and that memory_allocated() is at least the packed checkpoint size.

Severity

High for FP8 users: silent 3.6-4x inference slowdown on the default single-GPU path, the VRAM report is wrong, and the checkpoint stays pinned in host RAM.

🤖 Generated with Claude Code

Activity

  1. Qubitium commented on Nov 17, 2026

    @Qubitium
    CollaboratorAuthor

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

  2. Qubitium commented on Nov 17, 2026

    @Qubitium
    CollaboratorAuthor

    Fixed by #4983 (squash-merged, 56f87e9f5). _restore_checkpoint_buffers no longer tests the map value for truthiness: the resolver is a module-level _device_map_target() returning a torch.device (or None for absent/disk/meta), with an int ordinal normalized to torch.device("cuda", n). Ordinal 0 now places the packed FP8 weight on the GPU exactly like ordinal 1.

    Regression test: on unmodified main the behavioural node fails at assert model.weight.device == torch.device("cuda:0") with the actual device(type='cpu') — the packed weight stayed on the CPU slot; with the fix it lands on cuda:0. The resolver table also pins int 0/1, the string and torch.device forms, disk/meta/absent, and longest-prefix selection.

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