Repository navigation
fix(ep): fail MallocSymm with the heap size instead of hipMemset(nullptr) - #900
Conversation
…ptr) EpDispatchCombineHandle::MallocSymm (non-CCO path) passed the result of ShmemExtMallocWithFlags straight to hipMemset. When the shmem symmetric heap is exhausted the allocator logs "Out of heap memory" and returns nullptr, and every rank then exits with [.../dispatch_combine.cpp:212] hip failed with invalid argument which points at HIP instead of heap sizing. - Check the allocation and throw std::runtime_error (as the CCO branch of MallocSymm already does) naming the requested size, the rank, the heap size, its free space / largest free block and MORI_SHMEM_HEAP_SIZE. - Every symmetric buffer in src/ops goes through MallocSymm, so this one check covers all EP kernel types. size == 0 keeps its old behaviour. - No change to heap defaults or to the allocation sizes. Found and prepared by the AMD automation team. Signed-off-by: Yaakoub El Khamra <[email protected]>
|
Rebased onto current |
c50de92 to
5e75e85
Compare
|
CI note: |
👍 . Will it be merged by someone from your side or is there something for me to do? |
I will merge after CI green. And it seems that the apparent ci error has no correlation with your changes. |
Fixes #899
Motivation
Prepared and host-compiled against
ROCm/morimain3711c9235afa4c58def7e13a4fea6177b8fa9203("umbp: hugepage-backed ranged scratch arenas (#830)"). One commit, one file (src/ops/dispatch_combine/dispatch_combine.cpp), +27 lines. The patch also applies unchanged to inspected mainff2dd5b30be016480522873513a35924ac4bd7c7, wheregit diff --checkandclang-format 20.1.8 --dry-run --Werrorpass. It has since been rebased unchanged, with no conflicts, onto current mainc7da62dbcf736a5fbc381af75e4fd888b374839e, where the repository pre-commit hooks (pre-commit run --from-ref origin/main --to-ref HEAD) all pass. Source line citations and the host-compile/harness results below refer to the prepared base; the newer mains were checked for application and style only.Summary
EpDispatchCombineHandle::MallocSymm(the non-CCO branch) passes the result ofShmemExtMallocWithFlagstohipMemsetwithout checking it. When the shmem symmetric heap is too small, the allocator returnsnullptrand every rank exits withThat message points at HIP, not at heap sizing. This PR checks the allocation and throws a
std::runtime_error, as the CCO branch of the same function already does. The message names the requested size, the rank, the heap size, the heap's free space and largest free block, andMORI_SHMEM_HEAP_SIZE. Heap defaults and buffer sizes are not changed.Open PR #521 contains a similar check as part of runtime resizing; see "Related" for how this PR differs.
Problem
We served DeepSeek-V4-Pro with ATOM on 8x MI355X (image
rocm/atom-dev:nightly_202610111450, ATOM2479251d, mori wheelamd-mori-nightly 1.2.4.dev20260910). We used DP attention + EP8 and did not setMORI_SHMEM_HEAP_SIZE, so the 4 GiB static default applied. Two configurations failed at MoRI handle creation: one with--enable-tboand one with--all2all-backend low-latency.In both runs, all 8 ranks logged
and then exited with
[.../src/ops/dispatch_combine/dispatch_combine.cpp:212] hip failed with invalid argument. The serving front end only reportedRuntimeError: Engine Core Mgr: Received unexpected SHUTDOWN signal from DP rank N during initialization.The two lines are written through different paths: the HIP line with an unbuffered
fprintf(stderr, ...)and the heap line through the logger. In multi-rank output they interleave. In one of the two runs, the firstdispatch_combine.cpp:212line comes before the firstOut of heap memoryline. If you read the tail of the log or search for the failing file and line, you find a HIP "invalid argument" error with no mention of the heap.Technical Details
Root cause
Source reading at the base commit:
src/ops/dispatch_combine/dispatch_combine.cppL211-212: in the!useCcoCommbranch,void* buf = ShmemExtMallocWithFlags(size, flags);is followed byHIP_RUNTIME_CHECK(hipMemset(buf, 0, size));. There is no null check.src/application/memory/va_manager.cppL199-204: when no free block fits,HeapVAManager::AllocatelogsOut of heap memory! ...and returns 0.src/shmem/memory.cppAllocateStaticHeap(L35-49) then returnsnullptr.AllocateVMMHeap(L65-78) also returnsnullptrwhenVMMAllocChunkreturns an invalid object.include/mori/application/utils/check.hppL57-65:HIP_RUNTIME_CHECKprints[file:line] hip failed with <error>and callsexit(-1).So an exhausted heap leads to
hipMemset(nullptr, 0, size), which fails withinvalid argument, and the process exits at L212. The CCO branch of the same function already throwsstd::runtime_error("MallocSymm: cco arena exhausted (need ..., have ...)")(L244). Only the shmem branch is unchecked.Isolation mode is different:
SymmMemManager::ExtMallocWithFlags(src/application/memory/symmetric_memory.cppL93-97) wraps the device allocation inHIP_RUNTIME_CHECKitself, so a real HIP allocation failure there still exits inside the allocator, beforeMallocSymmsees a result. This PR does not change that path.Evidence
dispatch_combine.cpp:212 hip failed with invalid argument(8 lines per run) and the front-endRuntimeError(one per run). These are from our server-initialisation logs of the two runs.dispatch_combine.cpp:212line is the log line directly before the firstOut of heap memoryline.dispatch_combine.cppin the mori wheel of that image are identical to main, so the failing L212 is the uncheckedhipMemsetabove. The MoRI version was read from the image's installed packages.src/ops(IntraNode, IntraNodeLL, InterNode, InterNodeV1/V1LL, AsyncLL) is allocated throughMallocSymm.ShmemExtMallocWithFlagsis called only insideMallocSymm(dispatch_combine.cppL211), and nothing insrc/opscallsShmemMalloc*directly.5b0ed757).Fix
In
src/ops/dispatch_combine/dispatch_combine.cpp:MallocSymm(non-CCO branch), ifShmemExtMallocWithFlagsreturnsnullptrfor a non-zero size, throwstd::runtime_error("MallocSymm: symmetric heap allocation of <size> bytes failed on rank <rank> (<heap description>)").DescribeShmemHeapForAllocFailure(), builds the heap description from existing shmem state:MemoryStates::staticHeapSize(static heap) orMemoryStates::vmmHeapVirtualSize(VMM heap);HeapVAManager::GetStats;if the heap is too small, increase MORI_SHMEM_HEAP_SIZE. It is conditional because a VMM allocation can also fail for reasons other than capacity, such as the physical chunk allocation inSymmMemManager::VMMAllocChunk;Example from the CPU check below (real constructor, 4 GiB static heap, an illustrative IntraNode EP8 configuration that does not fit):
size == 0behaves as before:ShmemExtMallocWithFlagsreturnsnullptrfor 0 bytes by design (memory.cppL190-192), and that is not a heap failure.Why it works
hipMemset(nullptr)no longer runs and the misleadinginvalid argumentexit no longer happens.EpDispatchCombineHandleconstructor (InitializeShmemBuf/InitializeTokenNumSignalBuf/InitializeBarrier->MallocSymm) and leaves the constructor.pybind11::init<EpDispatchCombineConfig, uintptr_t>()(src/pybind/pybind_ops.cppL307-309). pybind11 translates astd::runtime_errorinto a PythonRuntimeErrorthat carrieswhat()(translate_exceptionin pybind11'sdetail/internals.h). The CPU check below confirms this for the real constructor: Python receivesRuntimeError: MallocSymm: symmetric heap allocation of .... We did not test how a particular serving framework displays that error for each rank. We expect it to appear in the traceback that the framework reports for the failing rank, instead of only in a separate allocator log line.EpDispatchCombineInstantiate(src/pybind/pybind_xla_ffi_ops.cppL321-361) catchesstd::exceptionand returnsError::Internal(e.what()), so the message is carried in the FFI error. This path was read, not run.throw std::runtime_error("...: out ShmemMalloc failed")ininclude/mori/collective/allgather/).Risk / compatibility
exit(-1)fromHIP_RUNTIME_CHECKbecomes a C++ exception (a PythonRuntimeError). Callers that let exceptions propagate still stop, with a readable message.SymmMemObjPtris a pair of raw pointers with no owning destructor. Buffers thatMallocSymmallocated before the failure therefore stay allocated in the heap. The CPU check shows this: one heap block is still allocated after the throw. Before this change the process exited, so these buffers did not matter. Now a caller that catches the error and keeps running keeps them. An example is the XLA path above: it returns the error, and its handle cache entry stays empty, so if instantiation is attempted again it constructs a new handle while the earlier buffers are still held. The CCO branch already throws from the same place with the same property. We left cleanup on a failed constructor out of this minimal fix. If you want it here, we can add it.GetStats(which takes the VA manager's mutex) runs only on the failure path.Related
f52e68b6). Within a larger runtime-resize feature, itsShmemMallocAndReturnMemObjPtrskipshipMemsetfor a null buffer and throwsstd::runtime_error("shmem allocation of N bytes failed"), which its rollback relies on. This PR is narrower: a standalone diagnostic on current main, with no resize or rollback logic. It also reports the rank, heap size, free space and largest free block. Both change the same allocation code. If ep: allow EpDispatchCombineOp to be resized at runtime #521 lands first, this PR reduces to adding the heap description to that throw, and we will rebase.35fede8d, on an unmerged personal-namespace branch of this repository (not the ep: allow EpDispatchCombineOp to be resized at runtime #521 head branch), throwsstd::bad_allocat the same place. It is not on main and is not part of ep: allow EpDispatchCombineOp to be resized at runtime #521.src/shmem/memory.cppL44-46 still says(default: 2GB)for the static heap, while the default has been 4 GB since Feat(shmem): increase default static heap to 4GB and VMM heap to 16GB #204. That stale hint is visible in our logs next to the correct one.Test Plan
GPU validation plan
Not required for merge in our view: the changed code is host-only, and it was executed above through the real constructor. As a smoke test on one 8-GPU MI300X/MI355X node with this branch built:
pytest tests/python/ops/test_dispatch_combine_intranode.py(32G heap from conftest). Expect the same pass/fail set as main.tests/python/ops/bench_dispatch_combine.pywithMORI_SHMEM_HEAP_SIZEbelow what the configuration needs. The bench usesos.environ.setdefault, so the override applies. Before:dispatch_combine.cpp:<line>] hip failed with invalid argumentwith exit code 255 (line 212 at the prepared base and in our runs; line 240 on current main). After:RuntimeError: MallocSymm: symmetric heap allocation of N bytes failed on rank R (current heap size ...; if the heap is too small, increase MORI_SHMEM_HEAP_SIZE)on each rank.CPU: the host-compile, harness and style checks are listed under Test Result.
Test Result
CPU only; no GPU was used. Exact output lines:
Host compile of the base and patched file with ROCm 7.0.1
hipcc(HIP version 7.0.51831-a3e329ad8). The file is built as plain CXX (src/ops/CMakeLists.txt), with the CMake Release flags-std=c++17 -O3(CMAKE_CXX_FLAGS_RELEASE "-O3", so asserts stay on), plus-Wall -Wextra:base_obj_rc=0,patched_obj_rc=0,base: 19 warnings generated. | patched: 19 warnings generated.,SAME_WARNINGS. None of the warnings are in the new lines.git apply --checkof the patch on the base commit:apply_check_rc=0.git diff --check: clean.Behaviour check: a harness that is not part of this PR. It is linked without any unresolved-symbol override, and every object in it is created by a constructor.
dispatch_combine.cpp(base or patched),src/shmem/memory.cpp(ShmemExtMallocWithFlags,ShmemQueryMemObjPtr,ShmemFree) andsrc/application/memory/va_manager.cpp. Each case runsnew EpDispatchCombineHandle(config)(the real constructor) and, if that succeeds,delete.symmetric_memory.cppandcontext.cppare not linked. Instead the harness defines theSymmMemManagerandContextmembers that this path needs. VMM VA comes from the realHeapVAManager::Allocate(size, 256), as inSymmMemManager::AllocateVirtualAddress; physical chunk mapping is not modelled. The bootstrap is a small subclass. The HIP runtime functions are host stubs, andhipMemsetreturnshipErrorInvalidValuefor(nullptr, size > 0). Functions that must not be reached abort withTRAP <name>; none fired.The base build is expected to reproduce the bug (exit 255 with the L212 line), and the patched build to throw (exit 3):
In the base build, the static case prints the same pair of lines as our runs (with this configuration's sizes):
Out of heap memory! Requested: ... Current heap size: 4294967296 bytesfollowed bydispatch_combine.cpp:212] hip failed with invalid argument.Scope of each case:
ctor_static_exhaustionandctor_vmm_exhaustionare the target of this PR: heap capacity runs out.ctor_isolation_injected_invalidis artificial. The double returns an invalid object, which the real isolation allocator does not do for a HIP failure. It only exercises the isolation wording of the message.ctor_isolation_hip_oom_unchangedmodels a real HIP out-of-memory in isolation mode. It exits inside the allocator (exit 255) in both builds, so this PR does not change that case.size_zero_unchangedcallsMallocSymm(0)on a constructed handle. Exit 134 isassert(obj.IsValid()), as on base. This case assumeshipMemset(nullptr, 0, 0)returns success.Python check: the same objects, built into a pybind11 module (pybind11 3.1.0 headers) that declares the handle exactly as
pybind_ops.cppL307-309, thenEpDispatchCombineHandle(cfg)from Python on a 4 GiB static heap. Base: the interpreter exits with status 255 after the L212 line. Patched:Not run: the full CMake build and the GPU test suite. No test is added to the repository. The ops pytest session (
tests/python/ops/conftest.pyL48) pinsMORI_SHMEM_HEAP_SIZE=32Gfor a shared worker pool, so a heap-exhaustion test would need its own process pool. We can add one if you want it.Submission Checklist
Credit