Skip to content

fix: honour cpu_workers and live kernel policy; warn on retired env vars (#4396) - #4423

Merged
Qubitium merged 1 commit into
mainfrom
pr/4396
Nov 16, 2026
Merged

Qubitium merged 1 commit into
mainfrom
pr/4396

Conversation

@Qubitium

Copy link
Copy Markdown
Collaborator

Summary

from_pretrained resolved the RuntimeConfig/KernelConfig policy but never installed it before the per-process thread-pool prebuild, so cpu_workers was ignored by the first load and every later load silently reused the singleton's original worker count. The same policy read was hidden behind lru_cache, so toggling cpu_bf16x3_matmul between runs had no effect. Retired GPTQMODEL_* / GPTQ_TORCH_* variables were also ignored without a warning, and the GPTQMODEL_RESUME retirement guard had been deleted. The follow-up items (native-GGUF argument forwarding and the internal gguf shim) are fixed too.

What Changed

  • models/auto.py: call configure_kernel(kernel) before _prebuild_device_thread_pool in from_pretrained; retune an existing pool in from_pretrained/from_quantized; forward kernel= and p2p= (and p2p= from load) to the model definition.
  • __init__.py: build the pool with an explicit CPU worker count and add resize_device_thread_pool, which replaces the singleton when the policy asks for a different count. Add a once-per-process warning for every retired env var naming its KernelConfig/RuntimeConfig/QuantizeConfig replacement.
  • utils/cpu_features.py, nn_modules/exllamav3_torch.py: cache only the hardware capability probe, not the mutable policy read, so cpu_bf16x3_matmul on→off→on is observed by the next forward.
  • models/base.py: restore the deleted GPTQMODEL_RESUME retirement guard.
  • utils/internal_gguf.py: install the shim only when importlib.util.find_spec("gguf") finds no real package.
  • tests/test_cpu_policy_4396.py: CPU-only regressions for pool sizing/resizing, policy toggling, one warning per retired var, GGUF arg forwarding, and shim non-clobbering.

Tests

$ python3 -m pytest tests/test_cpu_policy_4396.py -q
8 passed in 6.98s

$ python3 -m pytest tests/test_kernel_config.py tests/test_exllamav3_cpu.py tests/test_cpu_policy_4396.py -q
87 passed, 6 skipped in 6.86s

$ python3 -m pytest tests/test_hf_config_compat.py tests/test_internal_gguf.py -q
148 passed, 7 skipped in 6.61s

$ ruff check gptqmodel/__init__.py gptqmodel/utils/cpu_features.py gptqmodel/nn_modules/exllamav3_torch.py gptqmodel/models/auto.py gptqmodel/models/base.py gptqmodel/utils/internal_gguf.py tests/test_cpu_policy_4396.py
All checks passed!

tests/test_cpu_thread_pool*.py does not exist in this tree. No GPU or network downloads were used; the model-load tests stub the model definition and the config probe.

Model Support / Module Plan

N/A — no new model types or registry entries.

Fixes #4396

@Qubitium
Qubitium merged commit 551f861 into main Nov 16, 2026
9 checks passed
@Qubitium
Qubitium deleted the pr/4396 branch November 16, 2026 13:59
Qubitium added a commit that referenced this pull request Nov 16, 2026
…uantize (#4381) (#4426)

* fix: restore base modules and re-pick CPU kernels after weight-only quantize (#4381)

* fix(module-tree): quantize consumers after producers in six definitions (#4372) (#4427)

LongCat-Flash interleaves attn0 -> mlps0 -> attn1 -> mlps1, but the tree
emitted both attention sub-blocks before both MLPs. Its MLA q_a/kv_a and
q_b/kv_b also shared a subset. Restructure the layer declaration into
per-sub-block entries so the emitted subsets follow the forward order, and
split the MLA stages.

Also move the attention output projection after its producers in
kimi_linear, nemotron_h (including the Nemotron Omni copy), bailing_moe,
and deepseek_vl_v2, and give lfm2_moe's conv in_proj/out_proj distinct
subsets.

Add static subset-order assertions and a generic tiny-model data-flow
probe that perturbs each declared Linear and requires every consumer to be
in a later subset. Update the registered module-plan fixture, the bailing
shared-expert plan test, and teach _tiny_config about lfm2_moe layer types.
Add lfm2_moe to the AWQ fold-preservation families.

* fix(awq): resolve fp16-only GEMV dtype before calibration (#4394) (#4424)

AWQ FORMAT.GEMV/GEMV_FAST/LLM_AWQ kernels declare SUPPORTS_DTYPES=[fp16], but the quantize path loaded a bf16 shell model and only failed in layer-0 finalize after the AWQ search had run. Extend _coerce_quantized_awq_dtype to the quantize path and teach it that AUTO selects fp16-only kernels for those layouts: auto-selected dtypes are fixed to fp16 (logged, whole model) while an explicit unsupported dtype raises a ValueError naming the conflict and both fixes. Apply the same explicit-dtype contract to checkpoint loads.

* fix: honour cpu_workers and live kernel policy; warn on retired env vars (#4396) (#4423)

* fix(gguf): serialize ggml-cuda entry process-wide (#4378) (#4421)

* fix(gguf): serialize ggml-cuda entry process-wide (#4378)

`_GGMLBridge.cuda_backend_lock` handed out one lock per CUDA device, so forwards on cuda:0 and cuda:1 could be inside ggml-cuda at the same time. ggml-cuda shares cuBLAS handles and memory pools across devices; on 2x RTX 4090 with PYTHON_GIL=0, 4 threads x 200 forwards aborted 5 of 20 runs in cublasGemmEx.

Return one re-entrant process-wide lock from `cuda_backend_lock`. The per-device backend-handle map is unchanged, and single-thread latency is unchanged because a forward already took one lock.

Add CPU-runnable regression tests that assert both devices share one lock and that cross-device forwards never overlap inside the backend critical section. They fail on the pre-fix code (max_active == 2).

Update the GIL=0 ledger with the concurrency contract change.

* test(gguf): give the plan-weight fake the process-wide backend lock

The kernel takes the bridge's cuda_backend_lock for every ggml-cuda entry,
but _FakeBridge predated that contract and had no such method, so
test_kernel_builds_the_weight_once_for_many_batch_sizes failed whenever a
CUDA device was visible. Expose the lock from the fake.

* test(gguf): collect worker failures as Exception, not BaseException

Code Quality flagged the two worker-thread handlers. They still re-raise the
collected failure in the main thread; narrowing the catch keeps
KeyboardInterrupt/SystemExit out of the collected list.

* fix: restore base modules and re-pick CPU kernels after weight-only quantize (#4381)

* test(insession): use one import style for gptqmodel.models.base

Code Quality flagged the test for importing the module both as an alias and
with from-import. The two monkeypatches now target the module path by string,
which still rebinds the global that rehome_quantized_kernel looks up.
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