🧩

gptqmodel-lazy-load-smoke-testing

gptqmodel-lazy-load-smoke-testing · v
作者 ModelCloud 公开目录收录

简介

End-to-end smoke test for GPT-QModel's lazy checkpoint load (CheckpointSource) and first-layer materialization through StageInputsCapture.cache_inputs. Use when verifying lazy-load behavior, first-layer input capture, shell_module_materialize module_path propagation, or CPU-only GPTQ quantization from a tiny fixture.

通过你的 Agent 添加

安装目录:gptqmodel-lazy-load-smoke-testing/(目录名取自 SKILL.md 的 frontmatter name,不是 URL 里的 slug)。

点「快速安装」复制一段指令贴给你的 Agent:它会先下载到 /tmp、把文件清单和校验值给你看,你确认之后才解压安装。不会一步装完、也不改系统其它位置。

或者手动安装

Claude Code~/.claude/skills/gptqmodel-lazy-load-smoke-testing/
Codex CLI~/.codex/skills/gptqmodel-lazy-load-smoke-testing/
DeepSeek Harness~/.agents/skills/gptqmodel-lazy-load-smoke-testing/

包是「根级 SKILL.md + 作者附带的文件」,解压到上面的 <slug>/ 目录即可; 目录名不用换,也不要把包直接解压到 skills 根目录。 技能申请的权限由作者决定:装之前先看清单里有没有脚本、它会读写什么。

技能正文


SPDX-FileCopyrightText: 2026 ModelCloud.ai

SPDX-License-Identifier: Apache-2.0

name: gptqmodel-lazy-load-smoke-testing description: End-to-end smoke test for GPT-QModel's lazy checkpoint load (CheckpointSource) and first-layer materialization through StageInputsCapture.cache_inputs. Use when verifying lazy-load behavior, first-layer input capture, shell_module_materialize module_path propagation, or CPU-only GPTQ quantization from a tiny fixture.

GPT-QModel lazy-load smoke testing

At a glance

For changes to gptqmodel/looper/{module_looper,stage_inputs_capture}.py, gptqmodel/models/base.py or gptqmodel/weight_loader/{source,translate,plan,session}.py, run the snippets below in order from the repository root (no committed smoke script). The tiny CPU Llama must lazy-load, pass the dotted model.layers.0 path to shell_module_materialize, materialize real parameters/buffers rather than meta, quantize, save, reload and generate without NaNs or AttributeError. This smoke test does not replace a focused regression; extend tests/test_stage_inputs_capture.py for path-resolution bugs.

Environment prerequisites

No credentials are needed. For a GPU run, select the device explicitly and pass device="cuda:N" (see gptqmodel-device-families).

  1. Install the Python development headers for your interpreter (for example python3-dev on Debian/Ubuntu); otherwise JIT extension builds fail with Python.h: No such file or directory.
  2. On a fresh CPU-only machine, install a CPU torch build and the project:
    pip install -U pip
    pip install --index-url https://download.pytorch.org/whl/cpu torch torchvision
    pip install -r requirements.txt
    pip install -e . --no-build-isolation --no-deps
    
  3. Verify gptqmodel is importable from the repo root:
    python -c "import gptqmodel; print(gptqmodel.__version__)"
    

Minimal fixture

Build a tiny LlamaForCausalLM and save it to a temp directory. The fixture should be small enough to quantize in seconds on CPU:

from transformers import LlamaConfig, LlamaForCausalLM, PreTrainedTokenizerFast
from tokenizers import Tokenizer, models, pre_tokenizers, trainers
import torch, os, tempfile

config = LlamaConfig(
    vocab_size=128,
    hidden_size=64,
    intermediate_size=96,
    num_hidden_layers=1,
    num_attention_heads=4,
    max_position_embeddings=128,
)
model = LlamaForCausalLM(config)
tok = Tokenizer(models.WordLevel(unk_token="<unk>"))
tok.pre_tokenizer = pre_tokenizers.Whitespace()
tok.add_special_tokens(["<s>", "</s>", "<unk>", "<pad>"])
tok_trainer = trainers.WordLevelTrainer(
    special_tokens=["<s>", "</s>", "<unk>", "<pad>"], vocab_size=128
)
tok.train_from_iterator(
    ["the quick brown fox", "lorem ipsum dolor", "hello world"],
    trainer=tok_trainer,
)
hf_tokenizer = PreTrainedTokenizerFast(tokenizer_object=tok, pad_token="<pad>")

tmp = tempfile.mkdtemp()
model.save_pretrained(tmp)
hf_tokenizer.save_pretrained(tmp)

Lazy-load + input-capture test

from gptqmodel import BACKEND, CalibrationConfig, GPTQModel
from gptqmodel.quantization.config import QuantizeConfig

calibration = [
    {"text": "the quick brown fox jumps over the lazy dog"},
    {"text": "lorem ipsum dolor sit amet"},
    {"text": "hello world this is a test"},
]

qcfg = QuantizeConfig(
    bits=4,
    group_size=32,
    desc_act=False,
    device="cpu",
)
model = GPTQModel.load(
    tmp,
    quantize_config=qcfg,
    backend=BACKEND.TORCH,
)
assert model.checkpoint_source is not None

Capture the materialization path

Wrap model.shell_module_materialize to record the module_path passed during cache_inputs:

calls = []
orig = model.shell_module_materialize

def capture(*args, **kwargs):
    calls.append((args, kwargs))
    return orig(*args, **kwargs)

model.shell_module_materialize = capture
model.quantize(
    CalibrationConfig(dataset=calibration, batch_size=1, min_length=1),
    backend=BACKEND.GPTQ_TORCH,
)

first_call_args, first_call_kwargs = calls[0]
module_path = first_call_kwargs.get("module_path")
assert module_path == "model.layers.0", module_path

Verify first-layer materialization

After model.quantize reaches cache_inputs, inspect the first decoder layer:

first_layer = model.model.model.layers[0]
devs = {p.device.type for p in first_layer.parameters()}
assert "meta" not in devs, f"first layer still has meta parameters: {devs}"
assert not any(torch.isnan(p).any() for p in first_layer.parameters())

Save, reload, and generate

quantized_dir = os.path.join(tmp, "quantized")
model.save(quantized_dir)

qmodel = GPTQModel.load(
    quantized_dir,
    backend=BACKEND.GPTQ_TORCH,
    device="cpu",
)
in_ids = torch.tensor([[2, 5, 11]])
out = qmodel.generate(
    input_ids=in_ids,
    attention_mask=torch.ones_like(in_ids),
    max_new_tokens=4,
    do_sample=False,
)
assert out.shape == (1, in_ids.shape[1] + 4)
assert not torch.isnan(out).any()

Expected log signals

  • Loader: using checkpoint-backed source for /tmp/...
  • ModuleLooper: capturing layer inputs from N calibration batches

The assertions above, not log lines, are the pass criteria.

Common issues

  • torchao extension load warnings (_C_cutlass_90a.so, _C_mxfp8...so) are non-fatal on CPU.
  • Calibration dataset size should be more than 256 warnings are expected for tiny smoke fixtures.
  • If module_path is None, the new resolution logic in stage_inputs_capture.py was not reached or layer_names was not propagated from module_looper.py.

正文来自原始仓库, 版权归作者所有,许可:Apache-2.0。 权利人认为有不妥,可申请下架。

原始仓库

作者的项目地址:https://github.com/ModelCloud/GPTQModel

标签

没有标签

同类 Skill