You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[BUG][ROCm] #5165 (fix of #5121) incomplete: optimize/_common.set_env() still forces PYTORCH_ALLOC_CONF=expandable_segments:True (the documented corrupting config) before import gptqmodel - requant_embed_lm_head on ROCm: plain matmul+empty_cache 1.57M wrong rows #5199
Found on main @ 396b5f0, AMD Radeon AI PRO R9700 (gfx1201), torch 2.16.0.dev+rocm10.1.
What is wrong
#5165 (the fix for #5121 item 1) removed PYTORCH_ALLOC_CONF="expandable_segments:True" from the four docs/eora/ scripts. The reason given was that on ROCm expandable_segments:True plus torch.cuda.empty_cache() corrupts ordinary Torch results (#4072, docs/rocm-default-environment.md).
The repository's quantization CLI tools still install that same configuration on every platform. optimize/_common.py:17-26:
defset_env() ->None:
"""Configure process defaults before importing numerical libraries."""
...
os.environ.setdefault(
"PYTORCH_ALLOC_CONF",
"expandable_segments:True,max_split_size_mb:1024,garbage_collection_threshold:0.5",
)
optimize/requant_embed_lm_head.py:35 calls set_env() at import time, before gptqmodel is imported. GPT-QModel's ROCm default (expandable_segments:False) defers to a caller-set PYTORCH_ALLOC_CONF, so it keeps this value and prints no warning. The tool then requantizes with the configuration that docs/rocm-default-environment.md calls corrupting, and quantization calls empty_cache() throughout. This also brings back the max_split_size_mb cap that #5108 (#5072) just removed from the ROCm default.
Repro (pure Torch after the tool's env setup, no quantization)
importos, sysmode=sys.argv[1]
ifmode=="optimize":
fromoptimize._commonimportset_env# what optimize/requant_embed_lm_head.py does firstset_env()
ifmodein ("optimize", "gptqmodel"):
importgptqmodel# ROCm default defers to the value set aboveimporttorchprint("PYTORCH_ALLOC_CONF =", os.environ.get("PYTORCH_ALLOC_CONF"))
torch.manual_seed(0)
a=torch.randn(2097152, 64, device="cuda"); b=torch.randn(64, 16, device="cuda")
ref= (a @ b).cpu()
bad=0forrepinrange(3):
junk= [torch.empty(512<<20, dtype=torch.uint8, device="cuda") for_inrange(4)]
deljunktorch.cuda.empty_cache()
out= (a @ b).cpu()
bad+=int(((out-ref).abs().amax(1) >1e-3).sum())
print("bad rows", bad)
Run from the repo root on gfx1201:
plain PYTORCH_ALLOC_CONF = None bad rows 0
gptqmodel PYTORCH_ALLOC_CONF = expandable_segments:False bad rows 0
optimize PYTORCH_ALLOC_CONF = expandable_segments:True,max_split_size_mb:1024,garbage_collection_threshold:0.5 bad rows 1572864
Suggested fix
Drop the PYTORCH_ALLOC_CONF line from set_env(). import gptqmodel already installs the right per-platform default: expandable_segments:True on CUDA, expandable_segments:False on ROCm. If the tool really needs its own value, set it only when the host is not ROCm (check torch.version.hip after import, or the same running_on_rocm() probe _alloc_conf uses). A repo-wide test should reject any expandable_segments:True literal outside _alloc_conf.py that is not guarded for ROCm. The #5165 fix only covered docs/eora/.
Severity
Medium to high: silent result corruption when the shipped requantization CLI runs on ROCm. The fix is one line.
i'd like to work on this. starting now: dropping the forced PYTORCH_ALLOC_CONF from optimize/_common.set_env() and adding a repo-wide guard test against unguarded expandable_segments:True literals
Activity
n-o-t-mugen commentedon Nov 18, 2026
Agent claim released:
agent-34732ec3ea49finished this issue.Pull request: #5256
i'd like to work on this. starting now: dropping the forced PYTORCH_ALLOC_CONF from optimize/_common.set_env() and adding a repo-wide guard test against unguarded expandable_segments:True literals
fix(optimize): stop forcing expandable_segments:True before import gp…