Skip to content

fix(save): reject unknown save() keywords on the quantized path (#4686) - #4698

Merged
Qubitium merged 2 commits into
mainfrom
fix/issue-4686-save-kwargs
Nov 17, 2026
Merged

Qubitium merged 2 commits into
mainfrom
fix/issue-4686-save-kwargs

Conversation

@Qubitium

Copy link
Copy Markdown
Collaborator

Fixes #4686

Root cause

BaseQModel.save(save_dir, ..., **kwargs) forwarded **kwargs only on the
non-quantized branch (self.save_pretrained(save_dir=save_dir, **kwargs)).
For a quantized model — the normal case — every extra keyword was discarded
without an error or a log line. That covered both typos of real parameters and
HF-style options a caller reasonably expects to work.

The model-free weight-only replacement branch (save_quantized_embeddings) also
dropped two of save()'s own named parameters, eora_path and split_by.

Fix

Unknown keywords now raise TypeError on the quantized branch, with the same
difflib close-match hint QuantizeConfig uses for unknown kwargs (#4057):

GPTQModel.save: unexpected keyword argument(s) for a quantized model:
`max_shard_sise` (did you mean `max_shard_size`?). A quantized save accepts
`save_dir`, `safetensors_metadata`, `max_shard_size`, `meta_quantizer`,
`eora_path`, `split_by`.

safe_serialization and push_to_hub have no close match, but they still raise
instead of silently doing nothing — a CI job that "publishes" the checkpoint can
no longer report success without uploading.

eora_path/split_by are rejected explicitly on the module-replacement
path: save_quantized_embeddings writes a weight-only replacement checkpoint and
has no adapter or split support, so forwarding them would be a lie. The issue
allowed either forwarding or rejecting; rejecting is the honest option here.

The dense (save_pretrained) branch is unchanged and still forwards **kwargs.

Before / after

The issue's repro, quantized RTNConfig(bits=4, group_size=128) model:

=== BEFORE ===
{'max_shard_sise': '20MB'}                            OK  files: ['model.safetensors']
{'push_to_hub': True, 'repo_id': 'nonexistent/xyz'}   OK  files: ['model.safetensors']
{'safe_serialization': False}                         OK  files: ['model.safetensors']
{'max_shard_size': '20MB'}                            OK  files: [2 shards + index]

=== AFTER ===
{'max_shard_sise': '20MB'}   -> TypeError: ... `max_shard_sise` (did you mean `max_shard_size`?)
{'push_to_hub': ...}         -> TypeError: ... `push_to_hub`, `repo_id`
{'safe_serialization': ...}  -> TypeError: ... `safe_serialization`
{'max_shard_size': '20MB'}   -> OK  files: [2 shards + index]   (unchanged)

Tests

New tests/test_save_kwargs_validation_4686.py (5 tests). save() is driven
through a BaseQModel shell so the argument handling is checked without paying
for a real quantization run:

  • test_quantized_save_rejects_a_typo_with_a_close_match_hint
  • test_quantized_save_rejects_options_it_cannot_honor (parametrized:
    safe_serialization, push_to_hub+repo_id)
  • test_quantized_save_accepts_its_own_parameters — guard: the six documented
    parameters still reach save_quantized with their values intact
  • test_weight_only_replacement_save_rejects_eora_path_and_split_by

Fail-before, with the source change reverted and the tests kept:

$ pytest tests/test_save_kwargs_validation_4686.py -q
4 failed, 1 passed

Pass-after:

$ pytest tests/test_save_kwargs_validation_4686.py -q
5 passed

$ pytest tests/test_checkpoint_compat.py tests/test_checkpoint_extension.py \
         tests/test_checkpoint_metadata_contracts.py -q
36 passed, 1 failed

$ ruff check gptqmodel tests docs/eora setup.py
All checks passed!

The single failure, test_checkpoint_compat.py::test_untied_lm_head_quantizes_and_reloads,
is pre-existing on pristine origin/main (verified by stash + rerun) and
environmental:

ValueError: Quantized kernel selection does not support a device map spanning
different GPU compute capabilities: cuda:0=8.9, ..., cuda:4=12.0.

This host mixes four RTX 4090 (sm_89) with an RTX 5090 (sm_120) at cuda:4.

Scope / limits

  • Argument handling only. No change to what a valid quantized save writes.
  • eora_path/split_by are rejected rather than implemented for the
    module-replacement writer; adding adapter support to that path would be a
    separate feature, and the issue explicitly permits rejection.
  • The push_to_hub case is made loud, not working: it now raises instead of
    silently not uploading. Making it actually upload is a feature request, not
    this bug.

)

`BaseQModel.save(..., **kwargs)` forwarded `**kwargs` only on the non-quantized
branch. For a quantized model — the normal case — every extra keyword was
discarded without an error or a log line, so a typo of a real parameter and an
HF option such as `push_to_hub=True` both reported success and did nothing.

Raise `TypeError` for any leftover keyword on the quantized branch, with the
same difflib close-match hint `QuantizeConfig` uses for unknown kwargs (#4057):
`max_shard_sise` now points at `max_shard_size`.

The module-replacement writer (`save_quantized_embeddings`) also dropped two of
`save()`'s own named parameters. It writes a weight-only replacement checkpoint
and has no adapter or split support, so `eora_path`/`split_by` are now rejected
there explicitly instead of being ignored.

This is the save-side counterpart of #4052/#4057.

Closes #4686.
@Qubitium
Qubitium merged commit f0829b0 into main Nov 17, 2026
9 checks passed
@Qubitium
Qubitium deleted the fix/issue-4686-save-kwargs branch November 17, 2026 10:08
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