Repository navigation
[core][rdt] Expose registered NIXL memory-pool statistics - #68142
huangcarry wants to merge 2 commits into
Conversation
Signed-off-by: huangcarry <[email protected]>
Signed-off-by: huangcarry <[email protected]>
There was a problem hiding this comment.
Code Review
This pull request introduces a new API to inspect and snapshot the live usage of a registered NIXL memory pool. It adds the NixlMemoryPoolStats dataclass and the get_nixl_memory_pool_stats function under ray.experimental. To support this, thread synchronization was added to MemoryPoolManager and NixlTensorTransport to ensure thread-safe and atomic snapshotting. Comprehensive documentation and unit tests have also been added. There are no review comments, and I have no feedback to provide.
|
@Sparks0219 Would you be able to review the NIXL pool statistics API, given your work on the sender-side pool in #65205? This adds immutable capacity/allocation/fragmentation snapshots, including failed-allocation counts, without changing the allocator or initializing a transport on query. Feedback on the public API shape and accounting semantics would be especially helpful. The latest microcheck, release, docs and DCO checks pass. Local tests and the real T4 CPU/CUDA-pool lifecycle and fragmented-OOM validation, including their version boundaries, are documented in the description. The existing ray-core team review request remains open. |
Follows up on #61573 with the receive side of the NIXL memory pool. When the receiver has registered a pool with `register_nixl_memory_pool` and passes no target buffers, `ray.get` reads the incoming tensors into regions of the pool, which is registered with NIXL once, instead of registering new buffers for every transfer. Once the transfer lands, the tensors are copied out into ordinary tensors on the source's device type, and the regions go straight back to the pool. The tensors you get are independent of the pool, so the pool size bounds how much data can be in flight at once, not how much received data you can hold. An earlier version of this PR tied blocks to the returned tensors with `weakref`, which broke when a view outlived the tensor, so it copies out instead. - `MemoryPoolManager.allocate_regions`, `copy_out_and_free` and `free_blocks` make up the receive-side allocator. Regions start on `_MAX_ALIGNMENT`, so the sender's packed layout decodes in place. The pool now has a lock, since sends and receives use it from both the main and `_ray_system` threads. - A failed or abandoned receive gives its regions back only after its transfer handle is released, including when that release waits for `_finish_transfers` (#67389) to stop polling the handle. - Every pool call runs with the cleanups that garbage collection triggers deferred, as the cache lock already does, so a fetch request's `__del__` can't deadlock on the pool's lock. - An object with an empty tensor skips the receive pool: NIXL can't find a zero-length descriptor inside a registered region (`NIXL_ERR_NOT_FOUND`). - With user target buffers the pool is bypassed, as before. **Not a duplicate:** this is the receive-side follow-up to #61573. Searching open PRs for the NIXL memory pool turns up #68142 (pool statistics, which touches the same files but not the receive path) and nothing else on the receive side. **Tests** (4x T4, UCX with `UCX_TLS=^gdr_copy`, Ray nightly 2b3daa8 with this branch's `python/ray/experimental` and `python/ray/tests` linked in): - `pytest python/ray/tests/rdt/test_rdt_nixl.py python/ray/tests/rdt/test_nixl_agent_lock.py python/ray/tests/rdt/test_nixl_memory_pool.py`: 95 passed, 1 skipped (`test_nixl_borrow_after_abort`, skipped on master). - `pytest python/ray/tests/rdt/test_nixl_backend_selection.py python/ray/tests/rdt/test_rdt_custom.py python/ray/tests/rdt/test_rdt_gloo.py` (with the two unit files above): 101 passed, 1 skipped. - Each new test fails with its fix reverted. AI assistance (Claude Code) was used for this PR. 🤖 Generated with [Claude Code](https://claude.com/claude-code) --------- Signed-off-by: Joshua Lee <[email protected]> Co-authored-by: Claude Opus 5.5 <[email protected]>
Description
A NIXL pool can have enough total free space for a tensor and still reject it because that space is fragmented. Add
ray.experimental.get_nixl_memory_pool_stats(actor, timeout=10.0)to inspect a pool's capacity, allocated/free bytes, largest free block, allocated object count, free-block count, and lifetime allocation failures.The alpha API returns an immutable scalar snapshot or None when no pool is registered. Queries do not initialize a transport or keep tensors alive. Snapshots serialize with allocation/free operations and pool registration. Allocated bytes include the existing allocator's padding; the allocation algorithm is unchanged. Failure count increases once per NixlOutOfMemoryError attempt, including a failed replacement whose prior allocation is preserved.
The actor must enable tensor transport. Device indices are process-local. Timeout bounds the caller's wait and does not cancel queued work. These are pool statistics, not CUDA free memory, allocator usage, or total RDT tensor storage.
Related issues
Related to transport diagnostics in #67778. This is separate from #60431 (
ray memory): it measures the configured NIXL pool and does not add a C++/Python memory-summary callback or cluster-wide aggregation.Duplicate check (2026-11-13): #64137 discusses tuning, #59398 concerns pinned receive buffers, and #64542 concerns NIC assignment. Searches for NIXL pool statistics and observability found no open implementation of this snapshot API. This does not assert that no unpublished work exists.
Additional information
AI assistance was used for implementation, test execution, and review (OpenCode/DeepSeek and Codex). I reviewed every changed line and ran the relevant tests locally before requesting review. The hardware validation described below was executed with AI assistance; local testing and hardware testing are distinguished explicitly.
Validation:
Relevant pre-commit hooks passed. Real Tesla T4 / torch 2.10.0+cu128 / NIXL 0.4.0 / UCX validation passed three scenarios without skips: CPU-pool transport/reclamation, CUDA-pool transport/reclamation, and fragmented-pool OOM with exactly one failure increment and eventual full reclamation. Snapshots remained alive while objects were reclaimed. Installed production-file hashes matched the patch; native/source base was 96600b8.
Full upstream CI, a C++ source build, Sphinx, multi-node transport, MIG, and multi-GPU hardware were not run. The committed CPU suite includes the configured-pool public API round trip. The added fake agent is local to the actor method so worker deserialization does not require importing the test module.