Skip to content

test: stop the harness pinning PYTORCH_ALLOC_CONF over the backend default (#4821) - #4838

Merged
Qubitium merged 1 commit into
ModelCloud:mainfrom
Qubitium:fix/issue-4821-test-alloc-conf
Nov 17, 2026
Merged

Qubitium merged 1 commit into
ModelCloud:mainfrom
Qubitium:fix/issue-4821-test-alloc-conf

Conversation

@Qubitium

Copy link
Copy Markdown
Collaborator

Fixes #4821.

tests/models/model_test.py assigned

os.environ["PYTORCH_ALLOC_CONF"] = "expandable_segments:True,max_split_size_mb:256,garbage_collection_threshold:0.7"

unconditionally at import; tests/test_awq_weight_mean.py and tests/test_quant_formats.py did the same. Roughly 250 test modules import ModelTest (directly or via tests/awq_test_utils.py), so a plain pytest run replaced the allocator configuration before CUDA was initialised.

That overrode two things it should not have:

  1. The caller's value. gptqmodel/_alloc_conf.py deliberately defers to a configuration the caller already set.
  2. The ROCm-safe default. gptqmodel/_alloc_conf.py is the only place that knows ROCm must never enable expandable_segments (on ROCm 10.1 / gfx1201 the VMM segment release/remap inside empty_cache() corrupts ordinary Torch results). Every ROCm test that touches ModelTest therefore ran with the configuration the project documents as unsafe — tests/test_qqq.py among them.

The harness now leaves the variable alone. gptqmodel's import hook applies the CUDA default on CUDA, the ROCm default on ROCm, and defers to the caller either way. tests/benchmark/benchmark_test.py keeps its explicit pin: benchmark runs compare allocator settings on purpose, and changing a recorded baseline is a separate decision.

Verification

check parent commit this PR
test_harness_import_preserves_the_caller_alloc_conf FAIL (assert 'expandable_s...threshold:0.7' == 'max_split_size_mb:512') PASS
test_rocm_default_env.py (CUDA host) — 12 passed, 5 skipped
test_alloc_conf.py (CUDA host) — 13 passed, 3 skipped
test_rocm_default_env.py -k "harness or import_installs" (idle R9700) — 3 passed
harness import on CUDA expandable_segments:True,max_split_size_mb:256,garbage_collection_threshold:0.7 expandable_segments:True (DEFAULT_ALLOC_CONF)
harness import on R9700 expandable_segments:True,... max_split_size_mb:256,garbage_collection_threshold:0.7 (ROCM_DEFAULT_ALLOC_CONF)

The two new tests are in tests/test_rocm_default_env.py:

  • test_harness_import_preserves_the_caller_alloc_conf — backend-independent; the child process sets PYTORCH_ALLOC_CONF=max_split_size_mb:512, imports tests.models.model_test, and asserts the value survives.
  • test_harness_import_keeps_the_rocm_safe_default — ROCm-only; asserts the harness import leaves ROCM_DEFAULT_ALLOC_CONF in place with no expandable_segments.

🤖 Generated with Claude Code

…fault (ModelCloud#4821)

`tests/models/model_test.py` assigned
`PYTORCH_ALLOC_CONF=expandable_segments:True,max_split_size_mb:256,garbage_collection_threshold:0.7`
unconditionally at import, and `tests/test_awq_weight_mean.py` /
`tests/test_quant_formats.py` did the same. About 250 test modules import
`ModelTest`, directly or through `tests/awq_test_utils.py`, so a plain
`pytest` run replaced the allocator configuration before CUDA was
initialised.

That overrode two things it should not have:

- the value a caller already set, and
- `gptqmodel/_alloc_conf.py`, which installs the documented per-backend
  default at import and is the only place that knows ROCm must never enable
  `expandable_segments`. On ROCm 10.1 / gfx1201 the VMM segment
  release/remap inside `empty_cache()` corrupts ordinary Torch results, so
  every ROCm test that touches `ModelTest` ran with the configuration the
  project documents as unsafe. `tests/test_qqq.py` was one of them.

The harness now leaves the variable alone; `gptqmodel`'s import hook applies
the CUDA default on CUDA, the ROCm default on ROCm, and defers to the
caller either way.

`tests/benchmark/benchmark_test.py` keeps its explicit pin: benchmark runs
compare allocator settings on purpose, and changing a recorded baseline is a
separate decision.

Tests
- `test_harness_import_preserves_the_caller_alloc_conf` fails on the parent
  commit (`assert 'expandable_s...threshold:0.7' == 'max_split_size_mb:512'`)
  and passes here; it runs on any backend.
- `test_harness_import_keeps_the_rocm_safe_default` asserts the harness import
  leaves `ROCM_DEFAULT_ALLOC_CONF` in place on a real ROCm build.
- On an idle R9700 (gfx1201, ROCm 10.1, torch 2.16.0.dev+rocm10.1),
  `tests/test_rocm_default_env.py -k "harness or import_installs"` is
  3 passed, including the two new harness tests.
- On CUDA, importing the harness now yields the documented default
  (`expandable_segments:True`) instead of the old three-knob string.
@Qubitium

Copy link
Copy Markdown
Collaborator Author

Real-hardware confirmation of the root cause, on an idle Radeon AI PRO R9700 (gfx1201, ROCm 10.1, torch 2.16.0.dev+rocm10.1):

tests/test_qqq.py::TestGroupSize::test_quant_and_inference_0
=================== 1 passed, 1 warning in 456.74s (0:07:36) ===================

On the parent commit the same test, alone on the same idle card, fails in ~34 s with

linalg.cholesky: The factorization could not be completed because the input is not
positive-definite ...

which is the allocator-corruption signature #4821 section 4 describes. With the harness no longer pinning PYTORCH_ALLOC_CONF, the process runs under ROCM_DEFAULT_ALLOC_CONF (max_split_size_mb:256,garbage_collection_threshold:0.7, no expandable_segments) and passes.

Also confirmed the two directions of the deferral on the card:

  • harness import with no caller value → PYTORCH_ALLOC_CONF=max_split_size_mb:256,garbage_collection_threshold:0.7
  • harness import with PYTORCH_ALLOC_CONF=max_split_size_mb:512 → value preserved

This should also clear the test_qqq entry in #4770 section 4.

@Qubitium
Qubitium merged commit 059c79d into ModelCloud:main Nov 17, 2026
4 checks passed
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