Skip to content

[TEST][ROCm] tests/models/model_test.py forces PYTORCH_ALLOC_CONF=expandable_segments:True for ~250 test files, overriding the ROCm-safe default: test_qqq quant tests fail on an idle R9700 (Cholesky not PD), root cause of #4770 sect. 4 #4821

Closed

Description

@Qubitium

Found on main @ dba142d, Radeon AI PRO R9700 (gfx1201), ROCm 10.1, torch 2.16.0.dev20261025+rocm10.1. The card was idle, with no other process on it.

What is wrong

tests/models/model_test.py:15 sets the allocator unconditionally when it is imported:

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

tests/test_awq_weight_mean.py:6 and tests/test_quant_formats.py:11 do the same. About 250 test files import ModelTest, directly or through tests/awq_test_utils.py. That includes every tests/models/* model test and test_qqq.py, test_lm_head.py, test_quant_trust_remote.py, test_awq_*.py, test_gptaq.py, test_lora.py and test_dynamic.py.

GPT-QModel deliberately does not enable expandable_segments on ROCm (#4072/#4079, gptqmodel/_alloc_conf.py ROCM_DEFAULT_ALLOC_CONF, docs/rocm-default-environment.md). It also defers to any value the caller already set. A normal pytest process imports the test module before CUDA is initialised, so the harness value wins. Every ROCm test that uses ModelTest therefore runs with the allocator configuration that the project documents as corrupting results on gfx1201:

import gptqmodel only                      -> segments is_expandable=[False]
from models.model_test import ModelTest    -> segments is_expandable=[True], allocator settings 'expandable_segments:True,...'

Effect: the "unexplained" ROCm failures in #4770 section 4 reproduce on an idle card

tests/test_qqq.py::TestGroupSize::test_quant_and_inference_0, alone, on an idle R9700:

allocator in effect result
expandable segments (harness as-is) FAIL in 34 s: linalg.cholesky: ... the leading minor of order 1 is not positive-definite at quantization/qqq.py:948, layer 0 (2/2 runs; the 2nd failed at leading minor 274)
same test, with model_test.py:15 removed (GPT-QModel's ROCm default) passes (459 s, generates "...named Paris")
earlier runs in which CUDA was initialised before the harness import, so expandable segments never took effect passed 3/3, including the whole file (10/10)

The whole tests/test_qqq.py with the harness value fails test_quant_and_inference_0 and _1 in 64 s, with the same Cholesky error. With AMD_SERIALIZE_KERNEL=3, round 14 saw exactly this error. Without that variable it surfaced as HSA_STATUS_ERROR_INVALID_CODE_OBJECT (#4770). The AWQ NaN scales and the hipErrorIllegalAddress in test_lm_head / test_quant_trust_remote listed there also ran under this configuration (their logs contain HIPCachingAllocator ... expandable_segments: memory mapping failed).

Pure-torch confirmation of the platform behaviour, independent of GPT-QModel. Allocate and fill some 96 MiB blocks, free them, call empty_cache(), then recompute a fixed matmul and compare it with a CPU reference, 20 times:

import os; os.environ["PYTORCH_ALLOC_CONF"] = sys.argv[1]   # set before torch
import torch
a_cpu, b_cpu = torch.randn(65536, 256), torch.randn(256, 256); ref = a_cpu @ b_cpu
a, b = a_cpu.cuda(), b_cpu.cuda(); bad = []
for it in range(20):
    held = [torch.empty(96 << 20, dtype=torch.uint8, device="cuda").fill_(it) for _ in range(200)]
    del held; torch.cuda.empty_cache()
    bad.append(int((~torch.isclose((a @ b).cpu(), ref, rtol=1e-3, atol=1e-3)).any(1).sum()))
print(bad)
expandable_segments:True,max_split_size_mb:256,garbage_collection_threshold:0.7
  [0, 4096, 6144, 8192, 8192, 6144, 0, 6144, 6144, 6144, 6144, 6144, 2048, 8192, 8192, 6144, 6144, 0, 2048, 2048]
max_split_size_mb:256,garbage_collection_threshold:0.7   (GPT-QModel's ROCm default)
  [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]

No co-tenant is needed. With another process holding all but 1.5 GiB of the card, the expandable run gave 2048-4096 wrong rows in 18/20 iterations, identical on a 2nd run. The non-expandable run gave 0. (The 2097152x16 matmul repro from #4072, which has no allocation churn between reps, now shows 0 bad rows under both settings on this torch build. Pure allocation churn is what still triggers it.)

Suggested fix

  1. tests/models/model_test.py, tests/test_awq_weight_mean.py and tests/test_quant_formats.py should not set the allocator at all. GPT-QModel installs the right per-platform default at import, which is expandable_segments:True on CUDA since fix: stop forcing max_split_size_mb on CUDA allocator config (#4389) #4419. If a test needs to pin it, it should use gptqmodel._alloc_conf.default_alloc_conf(), and never add expandable_segments when torch.version.hip is set.
  2. On the library side, consider warning once at import when a caller-provided allocator setting (PYTORCH_ALLOC_CONF, PYTORCH_CUDA_ALLOC_CONF or PYTORCH_HIP_ALLOC_CONF) enables expandable_segments on ROCm. GPT-QModel calls empty_cache() per layer on ROCm (_release_rocm_layer_cache and others), which is the trigger. Today the documented corrupting configuration is honoured silently.

Test that should have caught it

tests/test_rocm_default_env.py checks the library default, but not what the suite actually runs with. Add a ROCm-gated test that imports models.model_test in a child process and asserts that no segment is_expandable.

Severity

High for the ROCm test signal: about 250 test files run under a known-corrupting allocator on ROCm. This turns ROCm CI red or flaky with misleading symptoms (Cholesky failures, NaN AWQ scales, illegal addresses, invalid code objects), and it can also hide or fake kernel regressions. Medium for users, because the library honours a user-set expandable_segments:True on ROCm without a warning.

🤖 Generated with Claude Code

Activity

  1. Qubitium commented on Nov 17, 2026

    @Qubitium
    CollaboratorAuthor

    One more data point, for AWQ. This is the test_awq_gemm quantize stage (Llama-3.2-1B, 512 C4 rows, batch 1), instrumented to check every weight after apply_scale / apply_clip and every pseudo_quantize_tensor input:

    allocator runs non-finite events
    GPT-QModel ROCm default 2 none
    expandable_segments:True,max_split_size_mb:256,garbage_collection_threshold:0.7 (the harness value) 2 run 2: mlp.gate_proj and mlp.up_proj weights non-finite right after apply_clip, even though the clip max_vals and AWQ scales were all finite

    That is the same family as the round-14 assert not torch.isnan(scales).any() | torch.isnan(w).any() failure in test_awq_gemm (#4770).

    🤖 Generated with Claude Code

  2. Qubitium commented on Nov 17, 2026

    @Qubitium
    CollaboratorAuthor

    Agent claim: agent-root-4821-allocconf is working on this issue now.

    Started 2026-11-17T16:12:48Z. The claim expires 4.0h after this comment was last edited (heartbeat). Other agents: do not start this issue while the claim is live.

    claiming: stop the test harness forcing expandable_segments over the ROCm-safe default and the caller's value

  3. Qubitium commented on Nov 17, 2026

    @Qubitium
    CollaboratorAuthor

    tests/test_quant_trust_remote.py (MiniCPM-2B, GPTQ, batch_size=64), run alone on the idle R9700 under the harness allocator setting, expandable_segments:True:

    • 840 Quantization: Module ... -> Damp recovery failed after reaching damp_percent=0.99000 warnings, meaning non-PD Hessians in nearly every module. The round-14 ROCm log of this test has 14. The CUDA log has 0.
    • reserved memory reached 31.3 GiB while active memory at each layer start was at most 2.0 GiB; 99 alloc retries and repeated expandable_segments: memory mapping failed with OOM. The run timed out at layer 34/39 after 15 min (CUDA: 5.5 min).

    With model_test.py:15 removed, the same test fails cleanly with hipErrorOutOfMemory at layer 0 (gar.py:174). The test's batch_size=64 forward does not fit in 32 GB, which is a test sizing problem of its own. Under the harness setting, though, the run does not fail. It keeps going and quantizes from corrupted Hessians, so the checkpoint is silently degraded where it should have raised an OOM.

    🤖 Generated with Claude Code

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions