Skip to content

[BUGFIX] Avoid CustomAllreduce when expandable_segments:True - #4560

Closed
jamesETsmith wants to merge 1 commit into
ROCm:mainfrom
jamesETsmith:fix/expandable-segments-custom-ar-fallback
Closed

jamesETsmith wants to merge 1 commit into
ROCm:mainfrom
jamesETsmith:fix/expandable-segments-custom-ar-fallback

Conversation

@jamesETsmith

@jamesETsmith jamesETsmith commented Aug 4, 2026 •

Copy link
Copy Markdown
Contributor

Motivation

Fixes #4174.

AITER CustomAllreduce aborts during initialization when PyTorch uses expandable_segments:True. PyTorch expandable-segment allocations use HIP virtual memory management and cannot be exported through AITER's classic hipIpcGetMemHandle path.

The goal is to preserve correctness and avoid terminating TP workers. In this configuration, collectives fall back to RCCL instead of using CustomAllreduce.

Technical Details

Before initializing the classic HIP IPC transport, CustomAllreduce now checks whether PyTorch expandable segments are enabled.

The active setting is read from PyTorch's allocator snapshot, allowing programmatic allocator changes to be detected. Environment-variable parsing is used as a fallback and follows PyTorch's precedence:

  1. PYTORCH_CUDA_ALLOC_CONF
  2. PYTORCH_HIP_ALLOC_CONF
  3. PYTORCH_ALLOC_CONF

When expandable segments are enabled for the classic IPC transport, CustomAllreduce remains disabled and emits an actionable warning. Existing callers then use their RCCL fallback. AITER's VMM transport is unaffected.

Regression tests cover allocator snapshot detection, environment fallback, variable precedence, repeated settings, and disabled communicator behavior.

Test Plan

  • Run focused regression tests on an AMD Instinct MI355X.
  • Run Ruff and Black against the changed files.
  • Compile the changed Python files.
  • Check the diff for whitespace errors.

Test Result

  • pytest op_tests/test_custom_all_reduce_allocator.py -q: 8 passed on MI355X, Slurm job 37581.
  • ruff check aiter/dist/device_communicators/custom_all_reduce.py op_tests/test_custom_all_reduce_allocator.py: passed.
  • black --check aiter/dist/device_communicators/custom_all_reduce.py op_tests/test_custom_all_reduce_allocator.py: passed.
  • python3 -m py_compile aiter/dist/device_communicators/custom_all_reduce.py op_tests/test_custom_all_reduce_allocator.py: passed.
  • git diff --check: passed.

Submission Checklist

@jamesETsmith
jamesETsmith requested a review from a team August 4, 2026 18:37
@github-actions

github-actions Bot commented Aug 4, 2026

Copy link
Copy Markdown
Contributor

🏷️ CI Guide

Runs automatically on every PR:

  • ✅ Pre-checks (submodule verification, code formatting)
  • ✅ Aiter op tests (gfx942 + gfx950)
  • ✅ Triton tests on MI35X (only when aiter/ops/triton/** or related paths are changed)

Extended tests (opt-in via labels):

Label Tests
ci:triton-300x Run an additional Triton test job on MI300X in PRs; main branch always runs both MI35X and MI300X
ci:sglang SGLang integration tests: DeepSeek-R1-MXFP4 accuracy, Qwen 3.5 accuracy
ci:atom ATOM benchmark: DeepSeek-R1-0528, GPT-OSS-120B
ci:atom_full ATOM accuracy suite for PR and main models from ATOM models_accuracy.json
ci:vllm vLLM benchmark: GPT-OSS-120B, DeepSeek-R1-0528, Kimi-K2.5
ci:all All standard extended tests (excludes ci:atom_full)

Only add ci:atom_full for FlyDSL or Triton upgrades.
Add labels via the sidebar or gh pr edit 4560 --add-label <label>

@jamesETsmith

Copy link
Copy Markdown
Contributor Author

I don't think the CI error is related to my changes:

Finished uploading artifact content to blob storage!
SHA256 digest of uploaded artifact zip is ad96480a43d7a33d493b04426fab3b9f09fb5d9934a544f049ccfaee6a3a5a01
Finalizing artifact upload
Error: Failed to FinalizeArtifact: Unable to make request: ECONNRESET
If you are using self-hosted runners, please make sure your runner has access to all GitHub endpoints: https://docs.github.com/en/actions/hosting-your-own-runners/managing-self-hosted-runners/about-self-hosted-runners#communication-between-self-hosted-runners-and-github

@zufayu

zufayu commented Aug 6, 2026

Copy link
Copy Markdown
Contributor

@TennyWang1223 — two things here: one concrete, one that needs your judgement.

1. The new test cannot pass, and CI never ran it

test_custom_allreduce_stays_disabled_for_expandable_segments asserts "falling back to RCCL" in caplog.text. That can never be true: aiter/__init__.py:44 sets logger.propagate = False on the aiter logger — the one custom_all_reduce.py:30 imports — while pytest's caplog installs its handler on the root logger, so it never sees those records. Reproduced with the repo's verbatim getLogger() and the test's verbatim body:

E   AssertionError: assert 'falling back to RCCL' in ''
E    +  where '' = <LogCaptureFixture>.text
----------------------------- Captured stderr call -----------------------------
[aiter] Custom allreduce is disabled because PyTorch expandable-segment allocations ... falling back to RCCL.

The warning is emitted (through aiter's own handler, to stderr), but caplog.text is empty.

CI didn't catch it because build_aiter_wheels (3.12, rocm/pytorch:latest) failed on an artifact-upload ECONNRESET, and split_aiter_tests / Standard Tests (1 GPU) / Multi-GPU Tests (8 GPU) all declare needs: build_aiter_wheels, so all three were skipped. .github/scripts/split_tests.sh scans op_tests/ dynamically, so the file will land in a shard after merge and turn main red.

The sibling assertion assert communicator.disabled is True is also vacuous — disabled is already True at custom_all_reduce.py:740, so any early return satisfies it. The caplog line is the only one that actually exercises the new branch.

Fix: capture logging.getLogger("aiter") directly (attach caplog.handler to it, or flip propagate for the duration of the test), or monkeypatch custom_all_reduce.logger.warning; and re-run the failed build job so Standard Tests actually go green before merge.

2. Is disabling CustomAllreduce outright the right scope?

This is the part I can't answer from the diff. Not everything CustomAllreduce IPC-exports comes from the PyTorch allocator:

buffer allocated by affected by expandable_segments
meta raw HIP (ops.allocate_meta_buffer, uncached=True) no
input pool torch.empty (_init_ipc: self._pool.create("input", max_size)) yes
user tensors, CUDA-graph capture only PyTorch yes

The third row is already avoidable today: enable_register_for_capturing = False routes capture through the copy-in path and stops exporting user tensors — exactly what gfx1250 does at custom_all_reduce.py:849. And outside capture, custom_all_reduce() already passes registered_input=False and copies into the pool, so the eager path never exports user memory either.

That leaves one buffer: the input pool. If it were allocated with a raw HIP call instead of torch.empty, CustomAllreduce would keep working under expandable_segments, at the cost of one extra copy on the capture path. IPCBufferPool currently only exposes uncached=True, which maps to hipDeviceMallocUncached and isn't usable for a max_size data buffer, so this would mean adding a cached raw-alloc path — real work, not a one-liner.

Whether that's worth doing is your call, and here's why I'm asking: vLLM turns on expandable_segments in several of its OOM-hardening paths, so as written this PR makes those deployments fall back to RCCL permanently, with only a log line to show for it. Is CustomAllreduce still ahead of RCCL at TP=8 once the capture path becomes copy-in? If yes, the narrower fix looks worth the effort; if no, the blanket disable in this PR is the right call and should just be merged (after the test above is fixed).

For the record, the diagnosis in the PR description is correct — fixing only the input buffer would not be sufficient on its own, since custom_all_reduce.cuh:3411 re-exports user graph buffers unless capture registration is also turned off.

@TennyWang1223

Copy link
Copy Markdown
Contributor

@zufayu
After testing locally, switching directly to RCCL causes a significant performance regression, while the copy-in fix has almost no performance overhead. So I think it's better to change AITER CAR's input pool to use direct hipMalloc. I'll push a fix PR later.

@jamesETsmith

Copy link
Copy Markdown
Contributor Author

@zufayu and @TennyWang1223, thanks for looking at the PR! IIUC, @TennyWang1223 will implement an alternative change to input pool and you'll merge that over this PR, is that correct?

If this PR is still useful, I can update the tests according to @zufayu's suggestion, just lmk!

@TennyWang1223

Copy link
Copy Markdown
Contributor

@zufayu , @jamesETsmith
PR #4621 fixes this error. Instead of falling back to RCCL, it keeps using custom_allreduce, at the cost of an additional d2d copy. Could you please help double-check it? If it's confirmed to resolve the custom allreduce graph capture crash when PyTorch sets expandable_segments:True, then #4560 can be closed.

@jamesETsmith

Copy link
Copy Markdown
Contributor Author

@zufayu , @jamesETsmith PR #4621 fixes this error. Instead of falling back to RCCL, it keeps using custom_allreduce, at the cost of an additional d2d copy. Could you please help double-check it? If it's confirmed to resolve the custom allreduce graph capture crash when PyTorch sets expandable_segments:True, then #4560 can be closed.

Trying this now, thanks @TennyWang1223!

@jamesETsmith

Copy link
Copy Markdown
Contributor Author

@TennyWang1223 your PR looks good to me (I posted a comment on the PR here)! I'll leave this one open until yours is merged and then close it

@jamesETsmith

Copy link
Copy Markdown
Contributor Author

Closing this since #4621 has been merged. Thanks again for the review and follow up PR!

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] custom_all_reduce.cu:397 hipIpcGetMemHandle fails when caller uses PYTORCH_HIP_ALLOC_CONF=expandable_segments:True

3 participants