Skip to content

fix(load): reject unknown kwargs and a dropped quantize_config on quantized loads (#4945) - #4972

Merged
Qubitium merged 1 commit into
mainfrom
root/load-strict-kwargs-4945
Nov 17, 2026
Merged

Qubitium merged 1 commit into
mainfrom
root/load-strict-kwargs-4945

Conversation

@Qubitium

@Qubitium Qubitium commented Nov 17, 2026 •

Copy link
Copy Markdown
Collaborator

Fixes #4945

Summary

GPTQModel.load() handled extra arguments differently on its two paths. An
unquantized load reaches the HF constructor, which raises for an unknown
keyword. A quantized load popped the options it knew and let the rest reach
QuantizeConfig.from_pretrained, which ignored them, so dtpye=,
attn_implmentation=, devcie_map= and bits= all "succeeded" and changed
nothing. GPTQModel.load(quantized_path, quantize_config) was dropped the same
way: the checkpoint's own config won with no message.

This is the load-side twin of #4686 (quantized save(**kwargs)), and it reuses
that fix's difflib close-match message style so both paths read the same.

What Changed

  • ModelLoader.from_quantized now wraps its keyword dict in _TrackedKwargs,
    which records every key consumed by pop. After the internal keys are
    normalised (INTERNAL_HF_GGUF_FILE_KWARG, device_map, backend, dtype,
    format, subfolder, revision, attn_implementation,
    tokenizer_trust_remote_code, the HF cache options, the checkpoint-offload
    options, max_memory, ...) any leftover key raises TypeError.
  • The accepted set is derived from the code, never hand-maintained:
    _accepted_quantized_load_kwargs() combines inspect.signature(cls.from_quantized)
    with the recorded pops and inspect.signature(snapshot_download) (the Hub
    staging options the loader forwards). A newly added parameter or a new
    pop() is accepted automatically; tests/test_load_strict_kwargs_4945.py
    pins this with a synthetic from_quantized that has a brand-new parameter
    and a brand-new popped key.
  • format= is popped once and passed explicitly to
    QuantizeConfig.from_pretrained, which is the only place that read it from
    **kwargs. QuantizeConfig.from_pretrained itself is unchanged.
  • GPTQModel.load(quantized_path, quantize_config=...) now raises ValueError
    (the preferred option in the issue) instead of ignoring the argument: a
    quantized checkpoint's bits/group_size/method/format come from the
    checkpoint. Forwarding was not provably safe (it would contradict the tensors
    on disk), so it is rejected with a message that says what to do instead.
  • VLLM/SGLang remain explicit passthrough engines: their runtime options
    (gpu_memory_utilization, max_model_len, enforce_eager, ...) are owned by
    the engine and are not rejected.
  • Dense/unquantized loads are unchanged (HF still raises).
  • Two loader tests that passed quantize_config= to from_quantized were
    relying on the silent drop; they now call it without that argument, which is
    what the loader actually accepted.
  • docs/config-serialization.md documents the new contract and the flow.

Exact error messages

LlamaQModel.from_quantized: unexpected keyword argument(s) for a quantized checkpoint: `dtpye` (did you mean `dtype`?). A quantized load accepts `_commit_hash`, `_gptqmodel_hf_gguf_file`, `adapter`, `adapter_revision`, `adapter_sha256`, `allow_patterns`, `allow_remote_adapter`, `attn_implementation`, `backend`, `cache_dir`, `device`, `device_map`, `dry_run`, `dtype`, `endpoint`, `etag_timeout`, `force_download`, `format`, `fuse`, `gguf_file`, `headers`, `ignore_patterns`, `kernel`, `library_name`, `library_version`, `local_dir`, `local_files_only`, `max_memory`, `max_workers`, `module_tree`, `p2p`, `proxies`, `repo_id`, `repo_type`, `resume_download`, `revision`, `runtime`, `subfolder`, `token`, `tokenizer_trust_remote_code`, `torch_dtype`, `tqdm_class`, `trust_remote_code`, `use_auth_token`, `user_agent`.
LlamaQModel.from_quantized: unexpected keyword argument(s) for a quantized checkpoint: `attn_implmentation` (did you mean `attn_implementation`?). A quantized load accepts ...
LlamaQModel.from_quantized: unexpected keyword argument(s) for a quantized checkpoint: `bits`. A quantized load accepts ...
GPTQModel.load: `quantize_config` cannot be applied to a quantized checkpoint; its quantization settings are read from the checkpoint. Load without `quantize_config` to use them, or pass an unquantized model to quantize.

Accepted kwargs

Derived at call time from the signature, the recorded pops, and the Hub
snapshot options:

adapter, adapter_revision, adapter_sha256, allow_patterns,
allow_remote_adapter, attn_implementation, backend, cache_dir,
device, device_map, dry_run, dtype, endpoint, etag_timeout,
force_download, format, fuse, gguf_file, headers, ignore_patterns,
kernel, library_name, library_version, local_dir, local_files_only,
max_memory, max_workers, module_tree, p2p, proxies, repo_id,
repo_type, resume_download, revision, runtime, subfolder, token,
tokenizer_trust_remote_code, torch_dtype, tqdm_class,
trust_remote_code, use_auth_token, user_agent, plus the internal
_commit_hash and _gptqmodel_hf_gguf_file and the checkpoint-offload options
offload_folder, offload_state_dict, offload_buffers when popped.

Note: tokenizer= is not a load option (the tokenizer is read from the
checkpoint); the accepted spelling is tokenizer_trust_remote_code=. A literal
tokenizer= now raises instead of being ignored.

Logic flow

flowchart TD
    A["GPTQModel.load(path, **kwargs)"] --> B{"checkpoint has a GPTQModel<br/>quantization config?"}
    B -- yes --> C{"quantize_config= also passed?"}
    C -- yes --> D["ValueError: config comes<br/>from the checkpoint"]
    C -- no --> E["ModelLoader.from_quantized<br/>(_TrackedKwargs records every pop)"]
    E --> F{"backend is VLLM or SGLang?"}
    F -- yes --> G["pass through: engine owns<br/>its runtime options"]
    F -- no --> H{"kwargs left after<br/>normalisation?"}
    H -- no --> I["continue the load"]
    H -- yes --> J["TypeError naming each key,<br/>difflib hint when close"]
    B -- no --> K["from_pretrained: HF constructor<br/>already raises for unknown keys"]
Loading

The same diagram is in docs/config-serialization.md (linked from
docs/README.md).

Tests

New tests/test_load_strict_kwargs_4945.py (7 tests, CPU): quantizes
HuggingFaceTB/SmolLM2-135M once (GPTQ 4-bit g128, 8 calibration rows), then

  • dtpye=torch.float16 -> TypeError, names dtpye, suggests dtype
  • attn_implmentation="eager" -> TypeError, suggests attn_implementation
  • bits=8 -> TypeError, no close match, still rejected
  • AWQConfig(bits=8, group_size=32) -> ValueError, config comes from the checkpoint
  • dtype=, attn_implementation=, device="cpu", backend=, format= still load
  • the unquantized path still raises TypeError for dtpye=
  • a synthetic new parameter / new popped key is accepted (no drift)

Red on unmodified origin/main (test copied into a detached worktree at
origin/main, source change absent):

$ pytest tests/test_load_strict_kwargs_4945.py -q
5 failed, 2 passed in 52.47s

The two passes are the "valid kwargs still work" and unquantized-path tests,
which must pass on main; the five assertions that describe the bug fail
(Failed: DID NOT RAISE TypeError / DID NOT RAISE ValueError, and the
missing helper).

Green on the branch:

$ pytest tests/test_load_strict_kwargs_4945.py -q
7 passed, 2 warnings in 45.81s

Same loader/save set on unmodified `origin/main` (new test file absent):
`77 passed in 11.01s`; on the branch: `84 passed`. Delta = the 7 new tests,
no regressions.

$ pytest tests/test_local_model_paths.py tests/test_gguf_load_policy_env_removal.py \
         tests/test_lazy_turtle_conversion_cache.py tests/test_loader.py \
         tests/test_loader_offload_staging_4385.py tests/test_loader_tokenizer_flag_4941.py \
         tests/test_moe_reload_meta_4400.py tests/test_save_kwargs_validation_4686.py \
         tests/test_load_strict_kwargs_4945.py -q
84 passed, 2 warnings in 46.13s

$ pytest tests/test_checkpoint_subfolder_resolution.py tests/test_trust_remote_code_isolation.py -q
23 passed, 2 warnings in 11.23s

$ pytest tests/test_docs_contract_refs.py tests/test_load_strict_kwargs_4945.py -q
27 passed, 2 warnings in 43.77s

$ pytest tests/test_save_kwargs_validation_4686.py tests/test_save_loaded_quantized_model.py \
         tests/test_save_loaded_quantized_model_dtype.py \
         tests/test_save_loaded_quantized_model_torch_fused.py \
         tests/test_save_state_dict_buffer_collection.py tests/test_quantize_call_signature_4868.py \
         tests/test_quantize_config_offload_tempdir.py tests/test_quantize_device_sequence_4875.py \
         tests/test_quantize_in_session_4381.py tests/test_quantize_run_summary.py \
         tests/test_quantized_embeddings.py -q
1 failed, 188 passed, 24 skipped in 188.72s

The one failure is test_save_loaded_quantized_model.py::TestSave::test_save_2_triton
(TritonV2Linear does not support device: cpu) on this CPU-only runner; it
fails identically on unmodified origin/main (verified in the base worktree).

Lint:

$ ruff check gptqmodel/models/loader.py gptqmodel/models/auto.py \
             tests/test_load_strict_kwargs_4945.py tests/test_local_model_paths.py \
             tests/test_loader_offload_staging_4385.py tests/test_moe_reload_meta_4400.py
All checks passed!

Model Support / Module Plan

Not applicable: no model, alias, or definition change.

AWQ onboarding safety

Not applicable: no model onboarding or AWQ grouping/search/replay/fold change.

Review Requirements

  • Reviewed this PR.
  • Checked that the code matches existing project structure, APIs, and conventions.
  • Avoided unnecessary monkeypatching and used the project's normal extension points where possible.
  • Minimized and compacted the impacted code surface.
  • Considered and eliminated potential regressions.

Kernel Accuracy Requirements

Not applicable: no kernel change.

Notes

  • CI unblock: docs/adapter-rank-pattern-matching.md now cites
    config.py::extract_adapter_rank_patterns in the symbol form instead of
    config.py:5595. fix(config): validate smoother parameters at construction (#4953) #4970 added ~137 lines above that definition, so the old
    line citation fails tests/test_docs_contract_refs.py on pristine origin/main
    (verified: 1 failed, 19 passed in a detached worktree at 55f9d9fc7), which
    fails the required AWQ CPU (unit) check for every PR. This is a two-line doc/test
    anchor change, not part of the load fix.
  • Behavior change: a quantized load with an unknown keyword now fails instead of
    loading with defaults. This is intentional and matches the unquantized path.
  • Behavior change: GPTQModel.load(quantized, quantize_config=...) now raises.
    The issue preferred rejection; forwarding was not provably safe.
  • use_auth_token and the Hub staging options remain accepted so existing
    remote loads are unaffected.

Comment thread gptqmodel/models/loader.py Fixed
Comment thread gptqmodel/models/loader.py Fixed
@Qubitium
Qubitium force-pushed the root/load-strict-kwargs-4945 branch from 737e193 to e3a551c Compare November 17, 2026 20:16
…ntized loads (#4945)

`ModelLoader.from_quantized` popped the options it knew and let every other
keyword reach `QuantizeConfig.from_pretrained`, which ignored it. A typo of a
real option (`dtpye=`, `attn_implmentation=`, `devcie_map=`) or an option that
does not apply (`bits=`) therefore "succeeded" and changed nothing, while the
unquantized path raises from the HF constructor. A passed `quantize_config`
was dropped the same way: the checkpoint's config won without a word.

Wrap the keyword dict in `_TrackedKwargs`, which records every key consumed by
`pop`, and raise `TypeError` for whatever is left after the internal keys are
normalised. The accepted set is derived from `inspect.signature(cls.from_quantized)`,
the recorded pops, and `inspect.signature(snapshot_download)` (the Hub staging
options), so a newly added parameter or pop is accepted without editing a
literal list. The message reuses the difflib close-match style of #4686:
`dtpye` now points at `dtype`. VLLM/SGLang keep their explicit passthrough
runtime options.

`GPTQModel.load(quantized, quantize_config=...)` now raises `ValueError`
instead of ignoring the argument: a quantized checkpoint's
bits/group_size/method/format come from the checkpoint, and forwarding a
different config was not provably safe.

Two loader tests passed `quantize_config=` to `from_quantized`, relying on the
silent drop; they now call it without that argument.

Closes #4945.

Also switch the `extract_adapter_rank_patterns` citation in
docs/adapter-rank-pattern-matching.md to the symbol form
(`config.py::extract_adapter_rank_patterns`). #4970 added ~137 lines above that
definition, so the old `config.py:5595` citation fails
`tests/test_docs_contract_refs.py` on pristine main and blocks the required
AWQ CPU (unit) check.
@Qubitium
Qubitium force-pushed the root/load-strict-kwargs-4945 branch from e3a551c to 30379bb Compare November 17, 2026 20:23
@Qubitium
Qubitium merged commit f28cfc9 into main Nov 17, 2026
9 checks passed
@Qubitium
Qubitium deleted the root/load-strict-kwargs-4945 branch November 17, 2026 20:27
sLaffey pushed a commit to sLaffey/GPTQModel that referenced this pull request Nov 18, 2026
…odelCloud#5007) (ModelCloud#5016)

ModelCloud#4972 rejected every keyword left in `kwargs_without_internal` after the
explicit pops, but the Hub staging options (`token`, `max_workers`, `local_dir`,
`endpoint`, `headers`, `etag_timeout`, `allow_patterns`, `ignore_patterns`,
`repo_type`, ...) are forwarded un-popped to `snapshot_download` while the
remote checkpoint is resolved. They were also listed as accepted in the error
message, so `GPTQModel.load(repo, token=...)` always failed with the
self-contradicting

    unexpected keyword argument(s) ...: `token` (did you mean `token`?) ...
    A quantized load accepts ..., `max_workers`, ..., `token`, ...

The leftover set is now compared against the same accepted set the message
prints, so a keyword that is forwarded is accepted and a real typo still
raises. `token` also joins `CONFIG_SELECTION_KWARGS`: model-type detection
reads the config before the loader stages the checkpoint, so a private or gated
repository needed the credential there too.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant