Repository navigation
Description
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
tests/models/model_test.py,tests/test_awq_weight_mean.pyandtests/test_quant_formats.pyshould not set the allocator at all. GPT-QModel installs the right per-platform default at import, which isexpandable_segments:Trueon CUDA since fix: stop forcing max_split_size_mb on CUDA allocator config (#4389) #4419. If a test needs to pin it, it should usegptqmodel._alloc_conf.default_alloc_conf(), and never addexpandable_segmentswhentorch.version.hipis set.- On the library side, consider warning once at import when a caller-provided allocator setting (
PYTORCH_ALLOC_CONF,PYTORCH_CUDA_ALLOC_CONForPYTORCH_HIP_ALLOC_CONF) enablesexpandable_segmentson ROCm. GPT-QModel callsempty_cache()per layer on ROCm (_release_rocm_layer_cacheand 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
Qubitium commentedon Nov 17, 2026
One more data point, for AWQ. This is the
test_awq_gemmquantize stage (Llama-3.2-1B, 512 C4 rows, batch 1), instrumented to check every weight afterapply_scale/apply_clipand everypseudo_quantize_tensorinput:expandable_segments:True,max_split_size_mb:256,garbage_collection_threshold:0.7(the harness value)mlp.gate_projandmlp.up_projweights non-finite right afterapply_clip, even though the clipmax_vals and AWQ scales were all finiteThat is the same family as the round-14
assert not torch.isnan(scales).any() | torch.isnan(w).any()failure intest_awq_gemm(#4770).🤖 Generated with Claude Code
Qubitium commentedon Nov 17, 2026
Agent claim:
agent-root-4821-allocconfis 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
test: stop the harness pinning PYTORCH_ALLOC_CONF over the backend de…
Qubitium commentedon Nov 17, 2026
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:Quantization: Module ... -> Damp recovery failed after reaching damp_percent=0.99000warnings, meaning non-PD Hessians in nearly every module. The round-14 ROCm log of this test has 14. The CUDA log has 0.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:15removed, the same test fails cleanly withhipErrorOutOfMemoryat layer 0 (gar.py:174). The test'sbatch_size=64forward 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