Skip to content

fix(load): default an absent require_load_tokenizer to the text path (#4941) - #4954

Merged
Qubitium merged 1 commit into
mainfrom
root/loader-doubles-4941
Nov 17, 2026
Merged

Qubitium merged 1 commit into
mainfrom
root/loader-doubles-4941

Conversation

@Qubitium

Copy link
Copy Markdown
Collaborator

Summary

#4894 added BaseQModel.require_load_tokenizer and made ModelLoader read it as cls.require_load_tokenizer at two call sites (gptqmodel/models/loader.py:2070, :2710). Only BaseQModel subclasses inherit the default, so every plain-class loader double — and any third-party definition that does not subclass BaseQModel — aborted the whole load:

AttributeError: type object 'DummyQModel' has no attribute 'require_load_tokenizer'

#4926 patched the nine doubles in tests/test_local_model_paths.py. Two more files were still red on main @ f160a408d:

FAILED tests/test_gguf_load_policy_env_removal.py::test_public_load_uses_the_kernel_policy_to_choose_the_gguf_parser
FAILED tests/test_lazy_turtle_conversion_cache.py::test_loader_converts_bin_under_configured_offload_path_not_tmpdir

so the GGUF parser-selection guard and the .bin conversion offload-path guard were not running.

What Changed

  • gptqmodel/models/loader.py: new _requires_tokenizer(cls) returning getattr(cls, "require_load_tokenizer", True), used at both call sites. An absent attribute means "text model" — the behaviour every definition had before feat(decision-transformer): tokenizer-optional load and tensor calibration inputs (#4755) #4894 — and an explicit False is the only way to skip the text path (Decision Transformer). This fixes both sites and every future double at once rather than one file per round.
  • tests/test_loader_tokenizer_flag_4941.py (new): drives the real ModelLoader.from_pretrained with the .bin source harness from test_lazy_turtle_conversion_cache.py.
    • a double with no require_load_tokenizer must still load its tokenizer (the red case)
    • require_load_tokenizer = False must skip it, True must keep it
    • the helper's table: True → True, False → False, absent → True

No change for any real definition: they all inherit BaseQModel.require_load_tokenizer = True (or declare False), so the value read is identical to before.

Tests

cd <worktree>
export CUDA_VISIBLE_DEVICES="" PYTHONPATH=<worktree> GPTQ_BYPASS_SAFETY_CHECKS=1 LOGBAR_ANIMATION=0
python -m pytest tests/test_gguf_load_policy_env_removal.py \
                 tests/test_lazy_turtle_conversion_cache.py \
                 tests/test_local_model_paths.py \
                 tests/test_decision_transformer_4755.py -q
# origin/main f160a408d: 2 failed, 52 passed
# with the fix:         54 passed

Red proof for the new file (behavioural tests only, helper-based rows removed so the run exercises the real path) on unmodified origin/main:

FAILED tests/test_loader_tokenizer_flag_4941.py::test_plain_class_double_without_the_attribute_still_loads
E   AttributeError: type object '_DummyQModel' has no attribute 'require_load_tokenizer'
gptqmodel/models/loader.py:2070: AttributeError
1 failed, 2 passed

With the fix: 7 passed.

The sweep the issue asked for — every test file that mentions ModelLoader:

python -m pytest tests/test_backend_config_reuse_4446.py tests/test_lazy_turtle_conversion_cache.py \
  tests/test_gguf_load_policy_env_removal.py tests/test_rocm_exl3_auto.py tests/test_local_model_paths.py \
  tests/test_loader_tokenizer_flag_4941.py tests/test_moe_reload_meta_4400.py tests/test_kernel_config.py \
  tests/test_loader_offload_staging_4385.py -q
# 112 passed

ruff check on both changed files: All checks passed.

  • Unit tests executed and passed (red on unmodified main, green here).
  • New targeted regression test added.

Model Support / Module Plan

Not applicable: no registry or definition change; decision_transformer's require_load_tokenizer = False keeps working and is asserted.

Logic Flow Documentation

Not applicable: no new decision. The same two branches read the same value through one accessor; the accessor's default is documented in its docstring and pinned by the table test.

Review Requirements

  • Reviewed this PR.
  • Matches existing project structure: one small accessor next to _get_tokenizer_load_kwargs, no new API surface.
  • No monkeypatching in product code.
  • Minimal surface: loader.py +20/−2, one test file.
  • Regression considered: real definitions read exactly the same value as before (BaseQModel default True), and the explicit opt-out is covered by its own test.

Kernel Accuracy Requirements

Not applicable: no kernel or numerics.

Closes #4941. Refs #4923, #4894.

…4941)

#4894 added `BaseQModel.require_load_tokenizer` and made `ModelLoader` read it
as `cls.require_load_tokenizer` at two call sites. Only `BaseQModel` subclasses
inherit the default, so every plain-class loader double (and any third-party
definition that does not subclass it) aborted the whole load with

  AttributeError: type object 'DummyQModel' has no attribute 'require_load_tokenizer'

#4926 patched the nine doubles in `tests/test_local_model_paths.py`; two more
files were still red on main (`test_gguf_load_policy_env_removal.py:321`,
`test_lazy_turtle_conversion_cache.py:238`), and the next double would have
broken it again.

The loader now resolves the flag through `_requires_tokenizer(cls)`, which
returns `getattr(cls, "require_load_tokenizer", True)`: an absent attribute means
"text model", which is what every definition did before #4894, and an explicit
`False` is the only way to skip the text path (Decision Transformer). This fixes
both call sites and every future double at once, instead of one file per round.

Tests: new `tests/test_loader_tokenizer_flag_4941.py` drives the real
`ModelLoader.from_pretrained` with the `.bin` harness from
`test_lazy_turtle_conversion_cache.py`:

  - a double with no `require_load_tokenizer` must still load its tokenizer
    (red on main: AttributeError at loader.py:2070)
  - `require_load_tokenizer = False` must skip it
  - `require_load_tokenizer = True` must keep it
  - the helper's table: True -> True, False -> False, absent -> True

main @ f160a40: 2 failed, 52 passed over the four loader files.
With the fix: 61 passed, and 112 passed over all nine `ModelLoader` test files
(the sweep the issue asked for).

Closes #4941. Refs #4923, #4894.
@Qubitium
Qubitium merged commit c9c2d7e into main Nov 17, 2026
9 checks passed
@Qubitium
Qubitium deleted the root/loader-doubles-4941 branch November 17, 2026 19:45
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