Skip to content

refactor(loader): one immutable checkpoint selection for every consumer (#5586) - #6272

Merged
Qubitium merged 1 commit into
mainfrom
fix/5586-issue
Nov 29, 2026
Merged

Qubitium merged 1 commit into
mainfrom
fix/5586-issue

Conversation

@Qubitium

Copy link
Copy Markdown
Collaborator

Fixes #5586.

Summary

A load with subfolder= selects one checkpoint. This change introduces one immutable CheckpointSelection at the public load entry and routes every consumer through one of its two explicit views:

  1. hub_kwargs: original source (Hub id or caller root) + normalized subfolder/revision/lookup policy for Hub/Transformers calls.
  2. local_path + local_kwargs: the selected directory once materialized, with subfolder removed, for filesystem-only readers.

The selection is frozen, deep-copies nested kwargs (proxies), and keeps token/use_auth_token only in memory: persisted_kwargs and repr() omit them.

No checkpoint format change.

API

gptqmodel.utils.hf.CheckpointSelection:

  • from_kwargs(source, kwargs, extra_kwargs=None) — validates/normalizes through the existing get_config_selection_kwargs.
  • from_selection_kwargs(source, kwargs) — for an already-merged config/GGUF selection.
  • subfolder, revision, lookup_policy, is_local.
  • hub_kwargs — view 1.
  • persisted_kwargs — wrapper-retained kwargs without transport credentials.
  • materialize(local_root) / local_path / local_kwargs / require_local_path() — view 2.
  • INTERNAL_CHECKPOINT_SELECTION_KWARG carries the record from the public entry point to the model definition.

get_config_selection_kwargs and resolve_checkpoint_subfolder keep their existing signatures and validation.

Migration completed

  • Public entry (GPTQModel.load, from_pretrained, from_quantized) builds the selection once and hands the same object to the definition.
  • Auto dense/quantized dispatch and the legacy sidecar probe use the selection. local_files_only=True now forces a cache-only sidecar probe; HF_HUB_OFFLINE still does. The probe forwards subfolder, pinned revision, cache_dir and token without listing the repo.
  • TT block-float detector/builder use selection.local_path; the wrapper keeps the selection for save.
  • Config, tokenizer, processor and trust probes use hub_kwargs.
  • Quantize-config read, weight discovery (get_checkpoints), embedding probe, adapter manifest, pre-load hooks, GGUF/floatx probes and the MLX converter use local_path with local_kwargs (no subfolder).
  • The wrapper stores the selection; save-time shell rebuild reopens the materialized directory (no moving-Hub re-resolution). Direct wrapper construction with config_load_kwargs keeps the legacy path.
  • Transport credentials are excluded from the wrapper's retained _config_load_kwargs.

Tests

Extended tests/test_checkpoint_subfolder_resolution.py with one shared distinguishable Gemma3 fixture (root marker 8 / width 16, child marker 4 / width 32) and these nodes:

  • test_checkpoint_selection_exposes_two_views_and_redacts_credentials
  • test_root_only_selection_keeps_the_root_as_both_views
  • test_local_files_only_sidecar_probe_never_lists_the_repository
  • test_remote_sidecar_probe_lists_the_pinned_revision
  • test_legacy_sidecar_dispatch_follows_the_selected_checkpoint
  • test_quantized_weight_reader_receives_the_selected_directory
  • test_native_floatx_probe_receives_the_selected_directory
  • test_direct_child_and_root_subfolder_load_the_same_dense_checkpoint
  • test_direct_child_and_root_subfolder_load_the_same_quantized_checkpoint

The dense/quantized tests compare backend/kernel type, processor marker, model_local_path, full state_dict, and re-save/reload for both spellings. Root-only load stays at the root.

Red evidence (source reverted to HEAD 2d3261d)

cd /root/openai-audit/issue-5586
git diff -- gptqmodel > /tmp/5586.patch
git checkout -- gptqmodel
cd tests
PYTHONPATH=/root/openai-audit/issue-5586:/root/openai-audit/issue-5586/tests \
CUDA_VISIBLE_DEVICES="" /root/venv/bin/python -m pytest \
  test_checkpoint_subfolder_resolution.py::test_local_files_only_sidecar_probe_never_lists_the_repository \
  test_checkpoint_subfolder_resolution.py::test_quantized_weight_reader_receives_the_selected_directory \
  test_checkpoint_subfolder_resolution.py::test_native_floatx_probe_receives_the_selected_directory \
  test_checkpoint_subfolder_resolution.py::test_checkpoint_selection_exposes_two_views_and_redacts_credentials \
  -q -rs -p no:cacheprovider --tb=line

Result: 4 failed

E   AssertionError: local_files_only probe must not list the repository
E   AssertionError: assert '.../repository' == '.../repository/nested'  # get_checkpoints
E   AssertionError: assert '.../repository' == '.../repository/nested'  # floatx probe
E   ImportError: cannot import name 'CheckpointSelection'

The two repository vs repository/nested failures are the intended root-vs-selected-directory defect; the sidecar failure is the offline probe listing the remote repo.

Green evidence

cd /root/openai-audit/issue-5586/tests
PYTHONPATH=/root/openai-audit/issue-5586:/root/openai-audit/issue-5586/tests \
CUDA_VISIBLE_DEVICES="" /root/venv/bin/python -m pytest \
  test_checkpoint_subfolder_resolution.py test_legacy_sidecar_selection_5379.py \
  -q -rs -p no:cacheprovider
# 43 passed

Broader checkpoint/subfolder/snapshot family:

cd /root/openai-audit/issue-5586/tests
PYTHONPATH=/root/openai-audit/issue-5586:/root/openai-audit/issue-5586/tests \
CUDA_VISIBLE_DEVICES="" /root/venv/bin/python -m pytest \
  $(ls test_checkpoint_*.py | grep -v test_checkpoint_quantization.py) \
  test_cpu_int4_snapshot_5013.py test_cpu_int4_snapshot_dedup_4395.py \
  test_packed_embedding_subfolder_5386.py test_nested_checkpoint_resave_5380.py \
  -q -rs -p no:cacheprovider --tb=line
# 378 passed, 125 skipped, 5 failed

The 5 failures are pre-existing/environmental AWQ-CUDA checks (ValueError: AWQ: CUDA is not available) in test_checkpoint_awq_scales_dtype_6153.py (3) and the CPU-AVX512 AWQ state-invariant cases (2). A representative node fails identically at HEAD, and the two state-invariant nodes pass in isolation both at HEAD and on this branch; the family-order failure is existing test-state pollution.

Additional green batch:

cd /root/openai-audit/issue-5586/tests
PYTHONPATH=/root/openai-audit/issue-5586:/root/openai-audit/issue-5586/tests \
CUDA_VISIBLE_DEVICES="" /root/venv/bin/python -m pytest \
  test_gguf_load_policy_env_removal.py test_load_strict_kwargs_4945.py \
  test_writer_instance_attrs.py test_local_model_paths.py \
  test_packed_embedding_subfolder_5386.py test_nested_checkpoint_resave_5380.py \
  test_local_model_loading.py test_local_processor_loading.py \
  test_local_tokenizer_loading.py test_trust_remote_code_isolation.py \
  test_checkpoint_processor_adapter.py test_model_load_lock_4204.py \
  test_vl_legacy_checkpoint_resave_4802.py -q -rs -p no:cacheprovider
# 229 passed, 3 skipped

Ruff:

/root/venv/bin/ruff check \
  gptqmodel/utils/hf.py gptqmodel/models/auto.py gptqmodel/models/loader.py \
  gptqmodel/models/base.py gptqmodel/models/writer.py \
  tests/test_checkpoint_subfolder_resolution.py
# All checks passed!

Deferred / unverified

  • tests/test_checkpoint_quantization.py was not run to completion (it quantizes real models and is long on this host); the selection paths it uses are covered by the subfolder/resave suites.
  • CUDA/GPU, TTNN hardware and external VLLM/SGLang paths are not exercised here (CPU-only fixtures).
  • tests/test_tenstorrent_support.py::test_tt_bf8_device_weight_rebuilds_when_the_source_changes fails on this host with TTNNUnavailable; unrelated to this diff.
  • No checkpoint format change.

@Qubitium
Qubitium marked this pull request as ready for review November 29, 2026 08:18
@Qubitium
Qubitium merged commit 968e74c into main Nov 29, 2026
6 checks passed
@Qubitium
Qubitium deleted the fix/5586-issue branch November 29, 2026 08:18
Qubitium added a commit that referenced this pull request Nov 29, 2026
…6385)

#6272 moved checkpoint selection into one immutable record passed to model
definitions under `_gptqmodel_checkpoint_selection`. DeepSeekV41FlashQModel is
the only definition that overrides from_quantized, and it treated the internal
kwarg as an unsupported user argument, so every V4.1 load raised TypeError
(7 failed + 9 errors in tests/module_tree/test_deepseek_v41_flash.py).

Pop the hand-off and reuse its hub_kwargs for the checkpoint, config, and
tokenizer reads. Add a regression test that loads a nested checkpoint through
GPTQModel.load and directly through the definition; a valid decoy checkpoint at
the root proves the handed-off record is reused, not merely accepted.

Fixes #6381

Co-authored-by: agent <agent@local>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Design: give checkpoint detection, loading and re-save one source selection

1 participant