Skip to content

fix(rocm): stop pinning max_split_size_mb in the allocator default - #5108

Merged
Qubitium merged 1 commit into
mainfrom
fix/5072-drop-rocm-split-cap
Nov 18, 2026
Merged

Qubitium merged 1 commit into
mainfrom
fix/5072-drop-rocm-split-cap

Conversation

@ZX-ModelCloud

Copy link
Copy Markdown
Collaborator

Summary

import gptqmodel installs ROCM_DEFAULT_ALLOC_CONF = "max_split_size_mb:256,garbage_collection_threshold:0.7" on every ROCm process. max_split_size_mb:256 caps 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 after quantize() 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. That empty_cache() only runs between layers, so it cannot reclaim the waste inside one layer, and MACaQ never calls it.

Fixes #5072

What Changed

No API change. A caller who sets PYTORCH_ALLOC_CONF, PYTORCH_CUDA_ALLOC_CONF or PYTORCH_HIP_ALLOC_CONF keeps their value verbatim, including an explicit max_split_size_mb.

Measured effect

One 14336x4096 MACaQ layer, same inputs and seed, only the allocator configuration changed:

config peak allocated peak reserved tensor digest
old default (max_split_size_mb:256,garbage_collection_threshold:0.7) 4224 MiB 5258 MiB 3512ae62...
garbage_collection_threshold:0.7 only 4224 MiB 4466 MiB 3512ae62...
new default (expandable_segments:False) 4224 MiB 4466 MiB 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.

config reserved after the second request
old default 458 MiB (a fresh segment on top of the held 258 MiB)
new default 258 MiB (the freed segment is reused)

Tests

pytest tests/test_rocm_alloc_conf_5072.py tests/test_alloc_conf.py \
  tests/test_cuda_alloc_conf_4389.py tests/test_awq_rocm_layer_cache_4313.py -q
# 30 passed, 1 skipped

pytest tests/test_rocm_default_env.py -q
# 17 passed

bash format/check.sh
# All checks passed!

The new test_default_alloc_conf_reuses_a_freed_segment_for_a_smaller_request is a ROCm device test (skipped elsewhere) and fails under the old default. The policy test test_rocm_default_keeps_only_the_vmm_exclusion pins 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.md was updated to the new literal.

Review Requirements

  • Reviewed this PR.
  • Checked that the code matches existing project structure, APIs, and conventions.
  • Avoided unnecessary monkeypatching and used the project's normal extension points where possible.
  • Minimized and compacted the impacted code surface.
  • Considered and eliminated potential regressions.

Kernel Accuracy Requirements

Not applicable: no kernel, fusion, or packed-storage change.

Notes

  • This is a ROCm default change. Callers that set their own allocator configuration are unaffected.
  • AWQProcessor's per-layer empty_cache() is kept as defense for caller-configured split caps.
  • Larger models benefit the most: the reservation is per layer, so an 8B-class model compounds the saving across layers.

`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
ZX-ModelCloud marked this pull request as ready for review November 18, 2026 04:27
@Qubitium
Qubitium merged commit 249ec41 into main Nov 18, 2026
9 checks passed
@Qubitium
Qubitium deleted the fix/5072-drop-rocm-split-cap branch November 18, 2026 04:33
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

2 participants