Repository navigation
[core][rdt] Application-level exclusive NIC assignment for NIXL/UCX t… - #64542
AyushKashyapII wants to merge 27 commits into
Conversation
…ransfers (ray-project#64426) Signed-off-by: Ayush KAshyap <[email protected]>
There was a problem hiding this comment.
Code Review
This pull request introduces an application-level exclusive NIC assignment mechanism for RDT/NIXL transfers to prevent network device contention among actors on the same node. It adds a cluster-wide NICAllocator actor, RDMA NIC discovery utilities, and integration hooks for acquiring and releasing NICs. The review feedback focuses on performance optimizations, suggesting the use of a process-local variable to track acquired NICs and avoid redundant remote calls during shutdown, as well as checking the environment variable before importing and invoking allocator functions when NIC pinning is disabled.
| _INFINIBAND_SYSFS_ROOT = "/sys/class/infiniband" | ||
|
|
There was a problem hiding this comment.
To avoid unnecessary and potentially blocking GCS/remote calls during actor shutdown, we should track whether the current process actually successfully acquired a NIC. Let's define a process-local variable _acquired_nic to store the name of the acquired NIC.
_INFINIBAND_SYSFS_ROOT = "/sys/class/infiniband"
# Track the currently acquired NIC for this process to avoid unnecessary release calls on shutdown.
_acquired_nic: Optional[str] = None| nic = ray.get(allocator.acquire.remote(node_id, actor_id), timeout=timeout_s) | ||
| if nic is None: | ||
| logger.warning( | ||
| "All %d RDMA NICs on node %s are already assigned; " | ||
| "falling back to unpinned UCX device selection.", | ||
| len(nics), | ||
| node_id, | ||
| ) | ||
| return nic |
There was a problem hiding this comment.
Update acquire_nic_for_current_actor to record the successfully acquired NIC in the process-local _acquired_nic variable.
nic = ray.get(allocator.acquire.remote(node_id, actor_id), timeout=timeout_s)
if nic is None:
logger.warning(
"All %d RDMA NICs on node %s are already assigned; "
"falling back to unpinned UCX device selection.",
len(nics),
node_id,
)
else:
global _acquired_nic
_acquired_nic = nic
return nic| def release_nic_for_current_actor(timeout_s: float = 5.0) -> None: | ||
| """Best-effort release of this actor's NIC on shutdown.""" | ||
| if not _nic_pinning_enabled(): | ||
| return | ||
| try: | ||
| ctx = ray.get_runtime_context() | ||
| actor_id = ctx.get_actor_id() | ||
| if actor_id is None: | ||
| return | ||
| allocator = ray.get_actor(NIC_ALLOCATOR_NAME, namespace=NIC_ALLOCATOR_NAMESPACE) | ||
| ray.get( | ||
| allocator.release.remote(ctx.get_node_id(), actor_id), | ||
| timeout=timeout_s, | ||
| ) | ||
| except Exception: | ||
| logger.debug("RDT NIC release skipped.", exc_info=True) |
There was a problem hiding this comment.
Update release_nic_for_current_actor to check _acquired_nic and return early if no NIC was acquired. This avoids unnecessary blocking calls to ray.get_actor and ray.get during shutdown for actors/workers that never held a NIC.
| def release_nic_for_current_actor(timeout_s: float = 5.0) -> None: | |
| """Best-effort release of this actor's NIC on shutdown.""" | |
| if not _nic_pinning_enabled(): | |
| return | |
| try: | |
| ctx = ray.get_runtime_context() | |
| actor_id = ctx.get_actor_id() | |
| if actor_id is None: | |
| return | |
| allocator = ray.get_actor(NIC_ALLOCATOR_NAME, namespace=NIC_ALLOCATOR_NAMESPACE) | |
| ray.get( | |
| allocator.release.remote(ctx.get_node_id(), actor_id), | |
| timeout=timeout_s, | |
| ) | |
| except Exception: | |
| logger.debug("RDT NIC release skipped.", exc_info=True) | |
| def release_nic_for_current_actor(timeout_s: float = 5.0) -> None: | |
| """Best-effort release of this actor's NIC on shutdown.""" | |
| global _acquired_nic | |
| if not _nic_pinning_enabled() or _acquired_nic is None: | |
| return | |
| try: | |
| ctx = ray.get_runtime_context() | |
| actor_id = ctx.get_actor_id() | |
| if actor_id is None: | |
| return | |
| allocator = ray.get_actor(NIC_ALLOCATOR_NAME, namespace=NIC_ALLOCATOR_NAMESPACE) | |
| ray.get( | |
| allocator.release.remote(ctx.get_node_id(), actor_id), | |
| timeout=timeout_s, | |
| ) | |
| _acquired_nic = None | |
| except Exception: | |
| logger.debug("RDT NIC release skipped.", exc_info=True) |
| def _init_nixl_agent(self): | ||
| """Builds the NIXL agent for the selected backend.""" | ||
| backend = self.select_backend() | ||
| if backend == "UCX" and "UCX_NET_DEVICES" not in os.environ: |
There was a problem hiding this comment.
Optimize the backend check to also verify if RAY_RDT_NIC_PINNING is enabled before importing and calling acquire_nic_for_current_actor. This completely avoids any import and function call overhead for the default case where NIC pinning is disabled.
| if backend == "UCX" and "UCX_NET_DEVICES" not in os.environ: | |
| if ( | |
| backend == "UCX" | |
| and "UCX_NET_DEVICES" not in os.environ | |
| and os.environ.get("RAY_RDT_NIC_PINNING", "0") == "1" | |
| ): |
| # Return this actor's pinned RDMA NIC (if any) to the cluster-wide | ||
| # pool. No-op unless RAY_RDT_NIC_PINNING=1. | ||
| from ray.experimental.rdt.nic_allocator import release_nic_for_current_actor | ||
|
|
||
| release_nic_for_current_actor() |
There was a problem hiding this comment.
Optimize the shutdown hook to only import and call release_nic_for_current_actor if RAY_RDT_NIC_PINNING is enabled. This avoids unnecessary imports and overhead during shutdown for the default case.
| # Return this actor's pinned RDMA NIC (if any) to the cluster-wide | |
| # pool. No-op unless RAY_RDT_NIC_PINNING=1. | |
| from ray.experimental.rdt.nic_allocator import release_nic_for_current_actor | |
| release_nic_for_current_actor() | |
| # Return this actor's pinned RDMA NIC (if any) to the cluster-wide | |
| # pool. No-op unless RAY_RDT_NIC_PINNING=1. | |
| if os.environ.get("RAY_RDT_NIC_PINNING", "0") == "1": | |
| from ray.experimental.rdt.nic_allocator import release_nic_for_current_actor | |
| release_nic_for_current_actor() |
Signed-off-by: Ayush KAshyap <[email protected]>
|
hey @Sparks0219
Added regression tests for both. Ready for another look whenever you get a chance.Thanks !!! |
Signed-off-by: Ayush KAshyap <[email protected]>
Signed-off-by: Ayush KAshyap <[email protected]>
Signed-off-by: Ayush KAshyap <[email protected]>
|
while working on it @edoakes @Sparks0219 , (release running after GCS teardown): I don't think patching the hook timing is the right fix which i thought of earlier. The actor calling release() on its way out is inherently unreliable -- it also doesn't cover SIGKILL, which was already a known gap. I'd rather flip the design so the allocator verifies actor liveness itself and reclaims NICs from dead owners opportunistically (checked only when the pool looks exhausted, not via a background poller), which would fix both issues with one mechanism instead of chasing hook-ordering edge cases. Before I implement that, I want to check: is there an existing Ray-internal way to check "is this actor still alive" that you'd consider appropriate for application-level code to depend on? The two I'm aware of are ray.util.state.get_actor() (public API, but depends on the dashboard/ state API being up) or a lower-level GCS actor-info accessor (more reliable, but reaches further into internals than the rest of this PR does). Wanted your take before building on either. |
Signed-off-by: Ayush KAshyap <[email protected]>
Signed-off-by: Ayush KAshyap <[email protected]>
|
hey @Sparks0219
Still open: the release-after-GCS-teardown issue. I don't think patching hook timing is the right fix -- I'd rather have the allocator verify actor liveness itself and reclaim from dead owners opportunistically (checked only when the pool looks exhausted), which also covers the existing SIGKILL gap in one mechanism instead of two. Before I build that: is there a Ray-internal way to check "is this actor still alive" that you'd consider appropriate for application-level code to depend on? I'm weighing ray.util.state.get_actor() (public, but needs the dashboard/state API up) against a lower-level GCS actor-info accessor (more reliable, but reaches further into internals than the rest of this PR does). Wanted your take before picking one and building on it -- happy to go either way, or something else entirely if you have a preference. |
|
This pull request has been automatically marked as stale because it has not had You can always ask for help on our discussion forum or Ray's public slack channel. If you'd like to keep this open, just leave any comment, and the stale label will be removed. |
|
Hey sorry for the delay in reviewing, will take a look in the next couple days @AyushKashyapII |
Signed-off-by: Ayush KAshyap <[email protected]>
|
hey @Sparks0219 thanks for the reply i have corrected the build error and merged it with the master branch .it should be up for merge .would be happy to make necessary changes which u think are important |
Signed-off-by: Ayush KAshyap <[email protected]>
Signed-off-by: L1ric <[email protected]>
Signed-off-by: L1ric <[email protected]>
|
hey @Sparks0219 ,pinging this again the issue has been left stale for weeks and i just wanted to get ur attention into it |
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.
Reviewed by Cursor Bugbot for commit 4367e7a. Configure here.
|
Hey @AyushKashyapII, apologies I went on vacation and I'll be back by next week, I'll take a look at this then |
|
hi @Sparks0219 , enjoy ur vacation !!! just wanted to ping this i have fixed the build errors which showed up and when u get time would love to get ur review on this . |
|
hey @Sparks0219 wanted to ping this again i wanted to close this PR hopefully if the solution satisfies u and would be ready to make any changes if required . could u please take a look into it |
|
hey @Sparks0219 was just hoping if u could find some time to like review this PR.this has been stale for a while and ur review would be of great help |

Why
Ray actors using RDT/NIXL over UCX don't control which RDMA NIC they use —UCX picks devices on its own. On multi-NIC nodes this means several actors can silently pile onto the same NIC while others sit idle, causing unpredictable tensor-transfer performance with no visible error.
Closes/Addresses #64426.
What
Per discussion on the issue (thanks @Sparks0219 @stephanie-wang), this implements NIC pinning entirely at the application level inside
ray.experimental.rdt— no Ray Core / scheduler / resource-model changes.This keeps the change small, fully opt-in, and iterable, while leaving the door open to promote parts of it into core later if the design holds up.ray/experimental/rdt/nic_allocator.py(new)discover_rdma_nics()— enumerates port-qualified RDMA device names (e.g.mlx5_0:1) from/sys/class/infiniband, the same sysfs surface_is_efa_available()already relies on (works inside containers/pods where netdevs are namespaced away). Returns[]on non-RDMA/non-Linux hosts.NICAllocator— a small@ray.remoteactor acting as a cluster-wide registry of(node, NIC) -> owning actor. Runs as a single detached singleton; single-threaded actor execution gives us race-free acquire/release for free. Supports idempotent node registration, re-entrant acquisition (an actor re-acquiring gets the same NIC back instead of leaking a second one), and asnapshot()for observability.acquire_nic_for_current_actor()/release_nic_for_current_actor()— the public entry points. Both are no-ops unlessRAY_RDT_NIC_PINNING=1is set, and fail open on any error (discovery failure, allocator unreachable, timeout) by returningNone/ logging-and-returning, so a broken allocator degrades to today's behavior rather than breaking transfers.ray/experimental/rdt/nixl_tensor_transport.py_init_nixl_agent()now callsacquire_nic_for_current_actor()and, if it gets a NIC back, setsUCX_NET_DEVICESbefore constructing the NIXL agent (UCX reads this at context-init time). Scoped to theUCXbackend only —LIBFABRIC/EFA is untouched. A user-suppliedUCX_NET_DEVICESalways takes precedence and is never overwritten.
ray/experimental/rdt/rdt_manager.pyRDTManager.shutdown()now callsrelease_nic_for_current_actor()to return the actor's NIC to the pool on clean shutdown. (Known gap: a SIGKILLed actor leaks its NIC untilrelease_all_for_nodeis called —snapshot()gives operators visibility into this; a reaper is a natural follow-up.)ray/tests/test_rdt_nic_allocator.py(new)discover_rdma_nicsagainst a fake sysfs tree (parametrized: no devices / single device / multi-port / multi-device, verifying sorted determinism).NICAllocatorlogic exercised directly as a plain class (no cluster): acquire/release cycle, exhaustion, re-entrancy, idempotent registration, unknown node,release_all_for_node.Nonebefore any Ray call is made.ray_start_regular: 4 actors contend for 2 fake NICs, exactly 2 succeed, and releasing one frees a slot for a waiter.Design notes / open questions carried from the issue discussion
RAY_RDT_NIC_PINNINGunset, every code path here is a no-op; existing RDT/NIXL users see zero behavior change.is what keeps this out of Ray Core for v1, per @stephanie-wang's suggestion.
nvidia-smi topo -m) is intentionally out of scope here — this PR only does exclusive assignment. Happy to iterate on affinity-aware allocation as a follow-up once the basic mechanism is validated.Test plan
test_rdt_nic_allocator.py(sysfs discovery, allocator logic, fail-open paths, end-to-end multi-actor contention)UCX_NET_DEVICESis set correctly per actor and transfers no longer collide on one NIC