Repository navigation
fix: repair the BaseQModel attr recursion and the transformers-5.22 cache shim, and realign the stale tests from #4358 - #4397
Merged
Conversation
Each item in #4358 was reproduced at def6e61 and classified before editing. Two are library defects rather than stale tests: - `BaseQModel.__getattr__` probed `hasattr(self, "_modules")`. During `__init__` and on fixtures built with `object.__new__`, that probe re-enters the hook forever, so any unrelated attribute lookup raised `RecursionError` and a test teardown spent minutes formatting the traceback. Read the container from `__dict__` instead. - `_patch_transformers_remote_code_compat` gated the legacy cache-length shim on `Cache.get_max_cache_shape`, which transformers 5.22 also removed (the query moved to `CacheLayerMixin.get_max_length`). Every remote decode that asks the cache for its limit still raised `AttributeError`. Install from the layer API, and fall back to `None` when no shape query exists. The remaining items are test-side: - Machete group-size test: mock `cached_validate_once` in a fixture that clears both caches on teardown, so the mocked Hopper answer no longer leaks into `test_selection.py`. - Machete JIT layout tests: treat the extension as built, and skip the build smoke test when `ninja` is missing. - MoE expert coverage: `bailing_hybrid` legitimately declares the alternate remote `attention.*` branch next to native `self_attn.*`; accept it only while the primary branch resolves on some layer. - `scales` keeps the loaded checkpoint dtype since #4178; the FP32 affine metadata lives in `scales_and_zeros`. Assert the packed tensor, not the checkpoint buffer, and compare the BF16 training fallback against a single FP32-rounded reference. - `state_dict()` emits the checkpoint snapshot layout (#4091), so the runtime-layout `load_assign` case is driven from the live packed buffers. - Add `qzeros_format` to the W4A-FP8 `state_dict()` expectation; checkpoint writes strip it. - EXL3 bias-refresh test: BF16 goes through `_torch_inner` by design, so assert against the handle the chosen path owns. - GGUF: skip formats this host cannot quantize (no `gguf`, no working ggml runtime) instead of failing, skip the C++ kernel when its shared library does not load, and compare the BF16/FP16 single-rounding paths against a one-ulp bound of the exact product. - `_DummyQuantizeConfig` gains `has_dynamic_exclusions`, and the subset-plan test stubs `layer_modules_for_prefix`. - `test_hf_config_compat` observes the warning through `caplog`: the library logger writes to a logbar sink, not to the captured stdout/stderr. - NF12 MLX manifest test: skip a claimed variant when MLX is not installed; the claim table itself is still asserted unconditionally. docs/transformers-5-compat.md records the cache-shim flow change.
Collaborator
|
@ZX-ModelCloud conflict |
…regressions # Conflicts: # tests/test_gguf_all_formats.py
Collaborator
Author
|
CI note: Everything else is green: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
TL;DR
Issue #4358 lists a batch of test-suite failures. I reproduced every item at
def6e61e3(currentmain) and classified each one. Two are real library defects, not stale tests; the rest are stale expectations or missing availability gates. Net diff: 16 files, +~300/-45.Fixes #4358.
1. The problem
Two items were reported as test-side issues but are reachable from production code.
a.
BaseQModel.__getattr__infinite recursion. The hook forwards unknown attributes to the innermodeland looks that up throughself._modules. Readingself._modulesbeforenn.Module.__init__has populated it (during__init__, or on a fixture built withobject.__new__) went throughhasattr(self, "_modules"), which re-enters__getattr__. Result:RecursionErroron the first unrelated attribute probe, and a pytest teardown that spent minutes formatting the traceback.flowchart TD A["obj.some_attribute"] --> B["BaseQModel.__getattr__"] B --> C["super().__getattr__ raises AttributeError"] C --> D{"__dict__ contains 'model'?"} D -- no --> E["hasattr(self, '_modules')"] E --> F["__getattr__('_modules')"] F --> C C -.- G["RecursionError<br/>never returns False"]b. Legacy cache-length shim never installed on transformers 5.22.
_patch_transformers_remote_code_compatreinstallsCache.get_max_length/get_usable_lengthfor older remote decoders, but gated the reinstall onhasattr(Cache, "get_max_cache_shape"). In 5.22 that cache-level name is gone too — the query lives onCacheLayerMixin.get_max_length()— so the shim was skipped and remote decode still raisedAttributeError.BaseQModel.__getattr__container probehasattr(self, "_modules")(gptqmodel/models/base.py:6247)self.__dict__.get("_modules")(gptqmodel/models/base.py:6247)Cache.get_max_cache_shape(gptqmodel/utils/hf.py:1208)Cache.get_max_lengthto be missing (gptqmodel/utils/hf.py:1208)self.get_max_cache_shape(layer_idx)(gptqmodel/utils/hf.py:1231)None(gptqmodel/utils/hf.py:1233)2. The new flow
flowchart TD A["_patch_transformers_remote_code_compat"] --> B{"Cache.get_max_length exists?"} B -- yes --> Z["leave the installed API alone"] B -- no --> C["install get_max_length(self, layer_idx=0)"] C --> D{"layer defines get_max_length?"} D -- yes --> E["layer.get_max_length()"] D -- no --> F{"layer defines get_max_cache_shape?"} F -- yes --> G["layer.get_max_cache_shape()"] F -- no --> H["cache-level get_max_cache_shape,<br/>only when callable"] H -- absent --> I["return None (unbounded)"] E --> J["None if value is None or negative"] G --> J I --> J J --> K["get_usable_length(new_seq_length, layer_idx)"]3. Failure and ambiguity contract
_modulesexistsRecursionErrorAttributeErrorfrom the original exceptionmodelpresent, attribute missing on wrappermodelmodel(unchanged)AttributeError(shim absent)None= unbounded-1None, matching transformers 4 semanticsget_max_cache_shapepresent (older 5.x)4. Test-side items
Each was reproduced first; none changes library behaviour.
kernels/test_awq_machete_group_size.py(True, None)stayed in the class-levelcached_validate_oncelru-cache aftermonkeypatch.undo(), breaking twotest_selection.pynodestest_machete_jit.pylayout tests (5)MacheteLinear.__init__validates the kernel, so a host without the compiled extension cannot allocate the checkpoint bufferstest_machete_jit.py::...build_only...Ninja is requiredwhen ninja is absentninjais missingmodule_tree/test_moe_expert_coverage.py[bailing_hybrid]BailingMoeQModelnow declares the alternate remoteattention.*branch for nativebailing_hybrid(self_attn.*)test_torch_cpu_avx512{,_awq}.pyoracle tests (4)scalesdtype; FP32 affine metadata isscales_and_zerosscales.dtype == checkpoint_scale_dtypeandscales_and_zeros.dtype == float32test_torch_cpu_avx512_awq.py::...train_mode...(1)x.float() @ w.float() + biasrounded once, bounded by one output ulpkernels/test_ret_idx_cache_invalidation.pyload_assign (4)state_dict()emits the #4091 checkpoint snapshot layout, not the live runtime layoutkernels/test_w4afp8_gb10.pyqzeros_formatis the in-process marker every GPTQ kernel emitstest_exllamav3_torch_padding.py(2)_torch_innerby designtest_gguf_all_formats.pydenseexpectation pre-rounded the weight, double-roundingtest_split_by_layer_save.py_DummyQuantizeConfiglackedhas_dynamic_exclusionsQuantizeConfigtest_subset_plan.pylayer_modules_for_prefix, replacing the caller's blocksNone(flat declaration)test_hf_config_compat.pycaplogtest_nf12_kernel_manifest.py(5)mlx_nf12imports MLX at module scope5. Tests / guarantees
tests/test_base_qmodel_getattr_recursion.py(new, 4)AttributeError; forwarding to the inner model still works; an earlyhasattrprobe in__init__does not recursetests/test_hf_config_compat.py::test_normalize_hf_config_compat_restores_legacy_cache_length_helpersNonefor dynamic layerstests/module_tree/test_moe_expert_coverage.pytests/test_gguf_all_formats.py::test_gguf_kernel_independent_packed_oracle6. Validation
Exact commands, run on
def6e61e3plus this branch:ruff checkon every touched file: clean.Before/after on the affected nodes (same host, same interpreter):
def6e61e3test_awq_machete_group_size.py+test_selection.py -k "Machete or group_size"test_moe_expert_coverage.py[bailing_hybrid]test_torch_cpu_avx512.py/_awq.pytest_nf12_kernel_manifest.pytest_machete_jit.pytest_hf_config_compat.pytest_split_by_layer_save.py,test_subset_plan.pytest_ret_idx_cache_invalidation.pytest_exllamav3_torch_padding.pytest_gguf_all_formats.pytest_base_qmodel_getattr_recursion.pyRecursionError(new test)An additional sweep of
tests/module_treereports 17 failures, which reproduce unchanged atdef6e61e3: 9 native-fusion kernel cases, 4 llama-fusion storage cases,glm4vleaf coverage,nemotronh_nano_omniMoE tags, jamba shared-input planning, and one falcon-Mamba AWQ fold. They are out of scope for this issue.7. Reviewer notes
_missing_specsalternate-branch rule is explicit per model type, not a generic "ignore anything that misses" escape: it still fails when neither branch resolves.docs/transformers-5-compat.md§ J.7 carries the same flow diagram and the before/after table for the cache shim.Validation was run on the affected node groups only; a full-suite sweep was not attempted.