Repository navigation
fix(rocm): stop pinning max_split_size_mb in the allocator default - #5108
Merged
Merged
Conversation
`ROCM_DEFAULT_ALLOC_CONF` kept `max_split_size_mb:256`, which prevents the caching allocator from serving a sub-cap request out of a freed 256 MiB block. MACaQ's wide-layer churn therefore maps new segments instead of reusing the cache: one 14336x4096 layer peaked at 5258 MiB reserved for 4224 MiB allocated, and 4466 MiB without the cap, with identical tensors. Drop the cap and the inert `garbage_collection_threshold` (it is a ratio of the whole device and never fires without a memory fraction), matching #4389 on CUDA. Keep only `expandable_segments:False` for the ROCm VMM exclusion (#4072). Fixes #5072
ZX-ModelCloud
marked this pull request as ready for review
November 18, 2026 04:27
8 tasks done
Qubitium
pushed a commit
that referenced
this pull request
Nov 18, 2026
…tqmodel (#5199) (#5256) optimize/_common.set_env() runs before gptqmodel is imported and set PYTORCH_ALLOC_CONF=expandable_segments:True,max_split_size_mb:1024,... GPT-QModel defers to a caller-set allocator config, so the requantization CLI (optimize/requant_embed_lm_head.py) replaced the ROCm default (expandable_segments:False) with the configuration that corrupts ordinary Torch results after empty_cache() on gfx1201, and restored the max_split_size_mb cap that #5108 removed. #5165 fixed only docs/eora/. Drop the line so import gptqmodel installs the per-platform default. Remove the same pinned literal from scripts/eval_model.py, scripts/benchmark_llama_cpp_vs_gptqmodel_gguf.py, and tests/benchmark/benchmark_test.py. Tests in tests/test_rocm_default_env.py: - a fresh interpreter imports the real tool, then gptqmodel, and must end up with _alloc_conf.default_alloc_conf() (a caller value still wins); - a repo-wide AST guard rejects any os.environ/os.putenv write of expandable_segments:True to PYTORCH_*ALLOC_CONF outside gptqmodel/_alloc_conf.py unless it sits under a HIP/ROCm check.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
import gptqmodelinstallsROCM_DEFAULT_ALLOC_CONF = "max_split_size_mb:256,garbage_collection_threshold:0.7"on every ROCm process.max_split_size_mb:256caps the largest block the caching allocator will split, so a request below the cap cannot be served from a free block at or above it. A layer whose working set churns around 256 MiB therefore maps a new segment instead of reusing the freed one: reserved memory grows while active memory stays flat, and the inflated reservation is still held afterquantize()returns.#4389 dropped the same knob from the CUDA default; the ROCm value was left in place because #4313's regression tests pinned the exact string and a per-layer
empty_cache()was thought to cover it. Thatempty_cache()only runs between layers, so it cannot reclaim the waste inside one layer, and MACaQ never calls it.Fixes #5072
What Changed
gptqmodel/_alloc_conf.py:ROCM_DEFAULT_ALLOC_CONFis nowexpandable_segments:False. This keeps [BUG][ROCm] Default expandable_segments alloc conf silently corrupts GPU results on ROCm 10.1/gfx1201; HIP JIT loaders write hipify output into source tree; ParoQuantTritonLinear strided crash (#4047 incomplete); bnb Triton drops autograd at M>=16 #4072's VMM exclusion and leaves every other allocator setting at Torch's default.max_split_size_mband the inertgarbage_collection_thresholdare gone, matching the CUDA default from [MEM] CUDA default alloc conf (expandable_segments + max_split_size_mb:256) grows reserved VRAM per layer during GPTQ (1B: 5.4 GiB reserved for 1.23 allocated; 8B: ~45 GiB), AllSpark keeps both weight layouts resident, CPU fp16 TorchLinear ~120x slow GEMM #4389.gptqmodel/quantization/awq/quantize/scale.py: comment-only. The per-layerempty_cache()stays; it still bounds the cache for a caller who configures a cap.docs/rocm-default-environment.md: table and import-time flow updated to the new literal.tests/test_rocm_alloc_conf_5072.py.No API change. A caller who sets
PYTORCH_ALLOC_CONF,PYTORCH_CUDA_ALLOC_CONForPYTORCH_HIP_ALLOC_CONFkeeps their value verbatim, including an explicitmax_split_size_mb.Measured effect
One 14336x4096 MACaQ layer, same inputs and seed, only the allocator configuration changed:
max_split_size_mb:256,garbage_collection_threshold:0.7)3512ae62...garbage_collection_threshold:0.7only3512ae62...expandable_segments:False)3512ae62...The cap is the whole effect: GC-only and cap-free are identical, and all three produce identical tensors.
Allocator-level check: allocate 255 MiB, free it, request 200 MiB.
Tests
The new
test_default_alloc_conf_reuses_a_freed_segment_for_a_smaller_requestis a ROCm device test (skipped elsewhere) and fails under the old default. The policy testtest_rocm_default_keeps_only_the_vmm_exclusionpins the new literal.A ratio assertion on one wide MACaQ layer (the check suggested in the issue) would not have caught this: the old default peaks at 1.25x allocated on a single layer, below a 1.5x threshold. The freed-segment reuse rule is the exact behavior the cap changes, so the regression asserts that directly.
Model Support / Module Plan
Not applicable: no model type, alias, definition or module plan change.
AWQ onboarding safety
Not applicable: the AWQ change is comment-only. No grouping, search, replay or fold behavior changed.
Logic Flow Documentation
The import-time allocator flow is unchanged; only the value installed on the ROCm branch of that flow changed. The existing diagram in
docs/rocm-default-environment.mdwas updated to the new literal.Review Requirements
Kernel Accuracy Requirements
Not applicable: no kernel, fusion, or packed-storage change.
Notes
AWQProcessor's per-layerempty_cache()is kept as defense for caller-configured split caps.