Skip to content

[core][rdt] Enable LIBFABRIC backend for NIXL - #62339

Merged
Sparks0219 merged 6 commits into
ray-project:masterfrom
Sparks0219:joshlee/use-libfabric-nixl-backend
Jun 23, 2026
Merged

Sparks0219 merged 6 commits into
ray-project:masterfrom
Sparks0219:joshlee/use-libfabric-nixl-backend

Conversation

@Sparks0219

@Sparks0219 Sparks0219 commented Apr 3, 2026 •

Copy link
Copy Markdown
Contributor

Why are these changes needed?

Ray's NIXL tensor transport currently hardcodes the UCX backend
(nixl_agent_config(backends=["UCX"])). On AWS EFA instances UCX cannot drive
the EFA NICs (they are libfabric-only), so cross-node RDT transfers silently
degrade to software-emulated RMA over TCP (~0.3 GB/s) — correct data, but
~600× slower than the hardware is capable of, with no warning emitted. NIXL
itself logs a hint recommending LIBFABRIC.

This change makes NixlTensorTransport select the LIBFABRIC backend on EFA
hardware (falling back to UCX everywhere else), unlocking genuine GPUDirect RDMA
over EFA. Builds on the initial draft (joshlee/use-libfabric-nixl-backend) and
hardens it for the environments where naive device-presence selection fails:
containers/K8s, hosts without GPUDirect, and CUDA VMM allocators.

What's included

  1. Backend auto-selection (select_backend()): LIBFABRIC when EFA is
    present, else UCX. get_nixl_agent() uses it instead of the hardcoded UCX.

  2. Container/K8s-aware EFA detection. Device presence alone (glob /sys/class/net/efa*) is empty inside pods — netdevs are network-
    namespaced — so on K8s the naive check reports "no EFA" and silently selects
    the slow UCX/TCP path. Detection also accepts the rdma-verbs devices the EFA
    k8s device-plugin mounts (/dev/infiniband/uverbs* + /sys/class/infiniband/*).

  3. Validate before committing to LIBFABRIC. EFA-present ≠ GPUDirect-works:
    on hosts/drivers without nvidia-peermem/dmabuf, LIBFABRIC instantiates and
    registers small CUDA buffers via EFA's ~32 MiB host bounce pool (looks
    healthy), but fi_mr_reg of a real-size buffer fails at transfer time with
    NIXL_ERR_BACKEND. We register/deregister a CUDA buffer at realistic
    transfer size
    before committing, and fall back to UCX on failure. Size is
    tunable via RAY_NIXL_VALIDATE_BYTES.

  4. VMM (expandable_segments) safety. CUDA VMM memory
    (PYTORCH_CUDA_ALLOC_CONF=expandable_segments:True, standard in large-model
    training) cannot be RDMA-registered. The validation probe allocates
    non-expandable memory so it mirrors a real registrable buffer rather than
    false-failing on a VMM probe.

  5. RAY_NIXL_BACKEND override. Per-process auto-detection can diverge
    between the two endpoints of a transfer when they run in different processes
    / Ray jobs with different allocator state (observed: sender → UCX, receiver →
    LIBFABRIC → every read fails NIXL_ERR_BACKEND). RAY_NIXL_BACKEND=UCX| LIBFABRIC lets an orchestrator pin both sides; the size-matched probe makes
    auto-selection deterministic across same-shaped hosts as the default.

  6. Per-transfer stats + backend-specific diagnostics (NixlTransferStats:
    bytes, xfer time, throughput, backend) and backend-aware error hints
    (FI_LOG_LEVEL=Debug for LIBFABRIC, UCX_LOG_LEVEL=debug for UCX) on
    registration failure.

Benchmark results

Validated in a downstream RL trainer (miles) weight-sync workload (Megatron
trainer → sglang rollout engines) on Anyscale, p5.48xlarge (8×H100-80GB,
32×EFA), Ray 2.55.1 + this change, cross-node (every transfer crosses the node
boundary). This addresses the draft's "TODO: benchmarking".

Backend path effective bandwidth
LIBFABRIC (this PR) GPUDirect RDMA over EFA ~23–30 GiB/s per source
UCX (status quo on EFA) software-emulated RMA over TCP ~0.3 GB/s

End-to-end weight-sync time (pull_wait = pure transfer; full model bf16):

Model size shard/src pull_wait (transfer) full sync
Qwen3-30B-A3B 57 GiB 14.24 GiB 0.61 s 2.7 s
GLM-4.7-Flash (MLA+MoE) — 14.13 GiB 0.61 s 1.9 s
Moonlight-16B (MLA) — 7.48 GiB 0.33 s 1.0 s
  • LIBFABRIC over EFA was ~8–9× faster than NCCL broadcast for the same
    cross-node sync (~3 s vs ~26 s for the 57 GiB model).
  • Flat across 2→4 nodes (transfer is per-source-shard bound, not node-count
    bound).
  • All transfers byte-correct end-to-end (downstream --check-weight-update-equal
    byte-compares the received weights, incl. MLA and fused-MoE tensors).

Without fix #2 (K8s detection) the change is a silent no-op on pods (stays on
UCX/TCP). Without #3/#4 it selects LIBFABRIC and then fails at transfer time on
no-GPUDirect/VMM hosts. With all of them, the LIBFABRIC path is correct and
fast across dense, MoE, and MLA models.

Related issue number

Builds on / supersedes the draft on joshlee/use-libfabric-nixl-backend.

Checks

  • Testing strategy: exercised via a real cross-node RDT weight-sync workload on
    EFA hardware (numbers above), plus the fallback paths — UCX selection on
    non-EFA, and LIBFABRIC→UCX fallback when the transfer-size CUDA registration
    fails (no-GPUDirect host). Suggested unit coverage: select_backend() honors
    RAY_NIXL_BACKEND and the EFA globs; get_nixl_agent() falls back to UCX when
    the validation registration raises.
  • Signed off commits
  • scripts/format.sh
  • Doc update (doc/source/ray-core/direct-transport.rst — backend selection section)
  • Tests passing

Notes for reviewers

  • The NixlTransferStats backend field reads list(nixl_agent.backends.keys());
    confirm backends is always a dict on the supported NIXL version (an earlier
    review flagged a possible AttributeError) and consider guarding it, since the
    stats path runs on the hot recv path.
  • Detection globs are cached (functools.lru_cache) — fine since hardware
    doesn't change within a process.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces automatic backend selection for NIXL, enabling LIBFABRIC support on AWS EFA instances while defaulting to UCX in other environments. The changes include documentation updates, logic to detect EFA devices, and backend-specific diagnostic hints in error messages. A review comment correctly identified a potential AttributeError in the exception handler when accessing the NIXL agent's backends and suggested using the select_backend method for a more robust implementation.

@Sparks0219 Sparks0219 changed the title [core][rdt] Enable EFA backend for NIXL [core][rdt] Enable LIBFABRIC backend for NIXL Apr 4, 2026
@github-actions

Copy link
Copy Markdown

This pull request has been automatically marked as stale because it has not had
any activity for 14 days. It will be closed in another 14 days if no further activity occurs.
Thank you for your contributions.

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.

@github-actions github-actions Bot added the stale The issue is stale. It will be closed within 7 days unless there are further conversation label Apr 18, 2026
@Sparks0219

Copy link
Copy Markdown
Contributor Author

unstale

@github-actions github-actions Bot added unstale A PR that has been marked unstale. It will not get marked stale again if this label is on it. and removed stale The issue is stale. It will be closed within 7 days unless there are further conversation labels May 1, 2026
@xyuzh
xyuzh marked this pull request as ready for review June 15, 2026 18:54
@xyuzh
xyuzh requested a review from a team as a code owner June 15, 2026 18:54
@xyuzh
xyuzh force-pushed the joshlee/use-libfabric-nixl-backend branch from c27c3a2 to 324079c Compare June 15, 2026 19:09
@ray-gardener ray-gardener Bot added docs An issue or change related to documentation core Issues that should be addressed in Ray Core labels Jun 15, 2026
@xyuzh
xyuzh force-pushed the joshlee/use-libfabric-nixl-backend branch from 03081be to d223eab Compare June 15, 2026 21:46
@xyuzh xyuzh added the go add ONLY when ready to merge, run all tests label Jun 15, 2026
@xyuzh
xyuzh force-pushed the joshlee/use-libfabric-nixl-backend branch from d223eab to 13d38ce Compare June 15, 2026 22:22

To pin the backend explicitly, set the ``RAY_NIXL_BACKEND`` environment variable to either ``UCX`` or ``LIBFABRIC``. An explicit override skips both the EFA probe and the GPUDirect validation. Because the two endpoints of a transfer must agree on a backend, set ``RAY_NIXL_BACKEND`` consistently on every actor that participates in a transfer. Otherwise per-process auto-detection can diverge and fail every transfer with ``NIXL_ERR_BACKEND``. Auto-detection can diverge in two ways: a process picks a different backend under different allocator state, and nodes with different GPUDirect setup can auto-select different backends, for example one node passes the validation registration and selects ``LIBFABRIC`` while another fails it and falls back to ``UCX``. The fallback warning includes the node IP and actor ID to help spot a mixed cluster.

To tune the validation probe, set ``RAY_NIXL_PROBE_SIZE_BYTES`` (default 64 MiB). The probe allocates a CUDA buffer of this size and tries to register it; the value must exceed EFA's ~32 MiB host bounce pool so the probe exercises a real registration rather than the bounce path, which can succeed even without working GPUDirect.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we really need it to be configurable? Fewer knobs is better.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch, removed

monkeypatch.setattr(ntt.glob, "glob", fake_glob)


def test_efa_detected_on_host(monkeypatch):

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some of these tests seem a bit overkill; it's fine if we just check that the selected backend is right.

@xyuzh
xyuzh force-pushed the joshlee/use-libfabric-nixl-backend branch from 13d38ce to b5beaab Compare June 17, 2026 18:36
@xyuzh
xyuzh force-pushed the joshlee/use-libfabric-nixl-backend branch from b5beaab to 1f6fdc7 Compare June 17, 2026 18:41
- **AWS instances with EFA**: Ray detects EFA devices and validates that a realistic-size CUDA memory registration succeeds before it selects the ``LIBFABRIC`` backend. To detect EFA both on bare hosts and inside containers, Ray probes the EFA network device (``/sys/class/net/efa*``) as well as the rdma-verbs devices that the AWS EFA Kubernetes device plugin mounts into pods (``/sys/class/infiniband/*`` and ``/dev/infiniband/uverbs*``). The host network device isn't visible inside a pod, so the verbs probes are what make detection work under Kubernetes.
- **All other environments**: Ray uses the ``UCX`` backend.

If Ray detects EFA but the validation registration fails, Ray falls back to the ``UCX`` backend and logs a warning. This happens, for example, when the node lacks GPUDirect (no ``nvidia-peermem`` or dmabuf), so EFA can register only small buffers through its host bounce pool, or when the tensors use CUDA VMM memory (``PYTORCH_CUDA_ALLOC_CONF=expandable_segments:True``), which can't be RDMA-registered.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In this case, I think it's fine to simplify this and just fail as it most likely signals that there's something wrong with the instance.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree we could fail on this

"""Validates that LIBFABRIC/EFA can register a realistic GPU buffer.

return self._nixl_agent
EFA presence doesn't guarantee GPUDirect works. Without nvidia-peermem or

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think GPUDirect validation is also fine to leave as a TODO, the error is propagated during transfer time either way

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if the transfer buffer is less than the bounce pool than the error would not be propagated

@Sparks0219 Sparks0219 Jun 22, 2026 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It sounds like from the nixl docs that GPUDirect support is required: https://github.com/ai-dynamo/nixl/blob/1f4468faec77165dea7b9ebc67420d7e170c3fcf/src/plugins/libfabric/README.md
otherwise it'll error out, were you seeing something different? If the error is always propagated, can we remove the probe?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good call, I removed the nixl register validation

"""Allocates a raw, non-VMM CUDA buffer for backend probing.

PyTorch's caching allocator uses CUDA VMM (``cuMemCreate``) when
``PYTORCH_CUDA_ALLOC_CONF=expandable_segments:True`` (standard for Megatron).

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why can't you just allocate a torch buffer if expandable segments is off by default?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How can we ensure expandable_segments is off by default here?

Harden NIXL backend selection so an EFA-equipped node only commits to the
LIBFABRIC backend when it can actually use it, and make the choice
controllable and observable:

- Detect EFA inside containers/Kubernetes pods, not just on bare hosts, by
  also probing the rdma-verbs devices the AWS EFA device plugin mounts
  (/sys/class/infiniband/* and /dev/infiniband/uverbs*) in addition to the
  host netdev (/sys/class/net/efa*).
- Validate GPUDirect at selection time: when LIBFABRIC is auto-selected,
  register a realistic-size (non-VMM) CUDA buffer and fall back to UCX with a
  warning (including node IP and actor ID) if it fails, instead of surfacing
  NIXL_ERR_BACKEND only at transfer time.
- Add a RAY_NIXL_BACKEND override (UCX/LIBFABRIC) that skips both the EFA
  probe and the validation, so both endpoints can be pinned to the same
  backend deterministically.
- Add RAY_NIXL_PROBE_SIZE_BYTES (default 64 MiB) to tune the probe above
  EFA's ~32 MiB host bounce pool.
- Improve the registration-failure message with a VMM/expandable_segments
  hint and backend-specific diagnostics guidance.
- Add CPU-only unit tests covering detection, override parsing, and the
  LIBFABRIC->UCX validation fallback.

Signed-off-by: xyuzh <[email protected]>
Co-authored-by: Joshua Lee <[email protected]>
@xyuzh
xyuzh force-pushed the joshlee/use-libfabric-nixl-backend branch from 1f6fdc7 to 112f002 Compare June 18, 2026 00:58
@stephanie-wang

Copy link
Copy Markdown
Contributor

LGTM modulo @Sparks0219's remaining comments.


If Ray detects EFA but the validation registration fails, Ray raises an error instead of selecting a backend, because the failure usually signals a misconfigured instance. This happens, for example, when the node lacks GPUDirect (no ``nvidia-peermem`` or dmabuf), so EFA can register only small buffers through its host bounce pool, or when the tensors use CUDA VMM memory (``PYTORCH_CUDA_ALLOC_CONF=expandable_segments:True``), which can't be RDMA-registered. To use ``UCX`` on such a node, set ``RAY_NIXL_BACKEND=UCX``.

To pin the backend explicitly, set the ``RAY_NIXL_BACKEND`` environment variable to either ``UCX`` or ``LIBFABRIC``. An explicit override skips both the EFA probe and the GPUDirect validation. Because the two endpoints of a transfer must agree on a backend, set ``RAY_NIXL_BACKEND`` consistently on every actor that participates in a transfer. Otherwise per-process auto-detection can diverge — for example, one node has EFA and selects ``LIBFABRIC`` while another doesn't and selects ``UCX`` — and every transfer fails with ``NIXL_ERR_BACKEND``.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems a bit janky, perhaps in the future where RDT provides support for more nixl backends having a config like RAY_NIXL_BACKEND would be helpful. But right now, it seems that AWS instances with EFA enabled should always use the LIBFABRIC backend, and UCX otherwise, so I don't see much of the benefit of this config option.

@xyuzh xyuzh Jun 22, 2026 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there is a case when we have rollout in a cluster with EFA, trainer in a cluster with only UCX.
In this case we have to still use UCX for both clusters even EFA is detected
We have remove RAY_NIXL_BACKEND right now for the first iteration

"Set UCX_LOG_LEVEL=debug for detailed UCX diagnostics."
)
vmm_hint = ""
alloc_conf = os.environ.get("PYTORCH_CUDA_ALLOC_CONF", "").lower()

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this issue with pytorch vmm memory is not specific to LIBFABRIC right, it's applicable to any backend? I feel like nixl should propagate the error in this case, and RDT just shows it to the user. Is this not the case today?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right now the nixl doesn't expose any guidance on the error message:

  • nixl/_api.py → register_memory calls self.agent.registerMem(...) with no error handling of its own.
  • The C++ binding does throw_nixl_exception(ret), which maps the nixl_status_t to a typed exception like nixlBackendError, nixlInvalidParamError, etc.
  • The message is just nixlEnumStrings::statusStr(status) — i.e. the bare status name, e.g. "NIXL_ERR_BACKEND". No size, no gpu_id, no remediation, no libfabric/UCX detail.

So I think we should expose more clear error msg until nixl has a version that does it

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

gotcha makes sense, could you leave a TODO here so that we remember to remove this warning once nixl addresses this?

… diagnostics

Remove the explicit RAY_NIXL_BACKEND override path so backend selection is
driven purely by hardware auto-detection (LIBFABRIC on EFA, UCX elsewhere).
Slim the NIXL memory-registration failure message and point at the NIXL
libfabric plugin docs for troubleshooting instead of an inline checklist.

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.

Fix All in Cursor

Reviewed by Cursor Bugbot for commit 823d2e2. Configure here.

…me error

Drop the pre-commit LIBFABRIC validation probe (_libfabric_registration_works,
the non-VMM cudart allocation helper, and the cached _agent_init_error). EFA
auto-selects LIBFABRIC unconditionally; if GPUDirect isn't available, the
failure now surfaces with clear, backend-specific guidance from
_add_tensor_descs at registration time instead of from a separate startup probe.
Factor the actor-side NIXL availability check out of the
__ray_actor_has_tensor_transport__ closure into a module-level
_nixl_transport_available_in_process() helper so it can be unit-tested
directly. It returns False on any agent-init failure (nixl not installed,
LIBFABRIC/EFA failure, or other backend init errors) and logs at debug. Tests
updated to cover the helper's failure handling.

@Sparks0219 Sparks0219 left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@Sparks0219
Sparks0219 enabled auto-merge (squash) June 23, 2026 18:49
@xyuzh
xyuzh self-requested a review June 23, 2026 18:57
@Sparks0219
Sparks0219 merged commit da1baa3 into ray-project:master Jun 23, 2026
4 checks passed
limarkdcunha pushed a commit to limarkdcunha/ray that referenced this pull request Jun 30, 2026
## Why are these changes needed?

Ray's NIXL tensor transport currently hardcodes the UCX backend
(`nixl_agent_config(backends=["UCX"])`). On AWS EFA instances UCX cannot
drive
the EFA NICs (they are libfabric-only), so cross-node RDT transfers
silently
degrade to **software-emulated RMA over TCP (~0.3 GB/s)** — correct
data, but
~600× slower than the hardware is capable of, with no warning emitted.
NIXL
itself logs a hint recommending LIBFABRIC.

This change makes `NixlTensorTransport` select the **LIBFABRIC** backend
on EFA
hardware (falling back to UCX everywhere else), unlocking genuine
GPUDirect RDMA
over EFA. Builds on the initial draft
(`joshlee/use-libfabric-nixl-backend`) and
hardens it for the environments where naive device-presence selection
fails:
containers/K8s, hosts without GPUDirect, and CUDA VMM allocators.

### What's included

1. **Backend auto-selection** (`select_backend()`): `LIBFABRIC` when EFA
is
present, else `UCX`. `get_nixl_agent()` uses it instead of the hardcoded
UCX.

2. **Container/K8s-aware EFA detection.** Device presence alone (`glob
   /sys/class/net/efa*`) is **empty inside pods** — netdevs are network-
namespaced — so on K8s the naive check reports "no EFA" and silently
selects
the slow UCX/TCP path. Detection also accepts the rdma-verbs devices the
EFA
k8s device-plugin mounts (`/dev/infiniband/uverbs*` +
`/sys/class/infiniband/*`).

3. **Validate before committing to LIBFABRIC.** EFA-present ≠
GPUDirect-works:
on hosts/drivers without `nvidia-peermem`/dmabuf, LIBFABRIC instantiates
and
registers *small* CUDA buffers via EFA's ~32 MiB host bounce pool (looks
healthy), but `fi_mr_reg` of a real-size buffer fails at transfer time
with
`NIXL_ERR_BACKEND`. We register/deregister a CUDA buffer **at realistic
transfer size** before committing, and fall back to UCX on failure. Size
is
   tunable via `RAY_NIXL_VALIDATE_BYTES`.

4. **VMM (`expandable_segments`) safety.** CUDA VMM memory
(`PYTORCH_CUDA_ALLOC_CONF=expandable_segments:True`, standard in
large-model
   training) cannot be RDMA-registered. The validation probe allocates
non-expandable memory so it mirrors a real registrable buffer rather
than
   false-failing on a VMM probe.

5. **`RAY_NIXL_BACKEND` override.** Per-process auto-detection can
diverge
between the two endpoints of a transfer when they run in different
processes
/ Ray jobs with different allocator state (observed: sender → UCX,
receiver →
LIBFABRIC → every read fails `NIXL_ERR_BACKEND`). `RAY_NIXL_BACKEND=UCX|
LIBFABRIC` lets an orchestrator pin both sides; the size-matched probe
makes
   auto-selection deterministic across same-shaped hosts as the default.

6. **Per-transfer stats + backend-specific diagnostics**
(`NixlTransferStats`:
   bytes, xfer time, throughput, backend) and backend-aware error hints
(`FI_LOG_LEVEL=Debug` for LIBFABRIC, `UCX_LOG_LEVEL=debug` for UCX) on
   registration failure.

## Benchmark results

Validated in a downstream RL trainer (miles) weight-sync workload
(Megatron
trainer → sglang rollout engines) on Anyscale, p5.48xlarge (8×H100-80GB,
32×EFA), Ray 2.55.1 + this change, cross-node (every transfer crosses
the node
boundary). This addresses the draft's "TODO: benchmarking".

| Backend | path | effective bandwidth |
|---|---|---|
| **LIBFABRIC (this PR)** | GPUDirect RDMA over EFA | **~23–30 GiB/s per
source** |
| UCX (status quo on EFA) | software-emulated RMA over TCP | ~0.3 GB/s |

End-to-end weight-sync time (`pull_wait` = pure transfer; full model
bf16):

| Model | size | shard/src | `pull_wait` (transfer) | full sync |
|---|---|---|---|---|
| Qwen3-30B-A3B | 57 GiB | 14.24 GiB | 0.61 s | 2.7 s |
| GLM-4.7-Flash (MLA+MoE) | — | 14.13 GiB | 0.61 s | 1.9 s |
| Moonlight-16B (MLA) | — | 7.48 GiB | 0.33 s | 1.0 s |

- LIBFABRIC over EFA was **~8–9× faster than NCCL broadcast** for the
same
  cross-node sync (~3 s vs ~26 s for the 57 GiB model).
- Flat across 2→4 nodes (transfer is per-source-shard bound, not
node-count
  bound).
- All transfers byte-correct end-to-end (downstream
`--check-weight-update-equal`
  byte-compares the received weights, incl. MLA and fused-MoE tensors).

Without fix ray-project#2 (K8s detection) the change is a silent no-op on pods
(stays on
UCX/TCP). Without ray-project#3/ray-project#4 it selects LIBFABRIC and then fails at transfer
time on
no-GPUDirect/VMM hosts. With all of them, the LIBFABRIC path is correct
and
fast across dense, MoE, and MLA models.

## Related issue number

Builds on / supersedes the draft on
`joshlee/use-libfabric-nixl-backend`.

## Checks

- Testing strategy: exercised via a real cross-node RDT weight-sync
workload on
EFA hardware (numbers above), plus the fallback paths — UCX selection on
non-EFA, and LIBFABRIC→UCX fallback when the transfer-size CUDA
registration
fails (no-GPUDirect host). Suggested unit coverage: `select_backend()`
honors
`RAY_NIXL_BACKEND` and the EFA globs; `get_nixl_agent()` falls back to
UCX when
  the validation registration raises.
- [ ] Signed off commits
- [ ] `scripts/format.sh`
- [ ] Doc update (`doc/source/ray-core/direct-transport.rst` — backend
selection section)
- [ ] Tests passing

## Notes for reviewers

- The `NixlTransferStats` backend field reads
`list(nixl_agent.backends.keys())`;
confirm `backends` is always a dict on the supported NIXL version (an
earlier
review flagged a possible `AttributeError`) and consider guarding it,
since the
  stats path runs on the hot recv path.
- Detection globs are cached (`functools.lru_cache`) — fine since
hardware
  doesn't change within a process.

---------

Signed-off-by: Joshua Lee <[email protected]>
Signed-off-by: xyuzh <[email protected]>
Co-authored-by: xyuzh <[email protected]>
400Ping pushed a commit to 400Ping/ray that referenced this pull request Aug 18, 2026
## Why are these changes needed?

Ray's NIXL tensor transport currently hardcodes the UCX backend
(`nixl_agent_config(backends=["UCX"])`). On AWS EFA instances UCX cannot
drive
the EFA NICs (they are libfabric-only), so cross-node RDT transfers
silently
degrade to **software-emulated RMA over TCP (~0.3 GB/s)** — correct
data, but
~600× slower than the hardware is capable of, with no warning emitted.
NIXL
itself logs a hint recommending LIBFABRIC.

This change makes `NixlTensorTransport` select the **LIBFABRIC** backend
on EFA
hardware (falling back to UCX everywhere else), unlocking genuine
GPUDirect RDMA
over EFA. Builds on the initial draft
(`joshlee/use-libfabric-nixl-backend`) and
hardens it for the environments where naive device-presence selection
fails:
containers/K8s, hosts without GPUDirect, and CUDA VMM allocators.

### What's included

1. **Backend auto-selection** (`select_backend()`): `LIBFABRIC` when EFA
is
present, else `UCX`. `get_nixl_agent()` uses it instead of the hardcoded
UCX.

2. **Container/K8s-aware EFA detection.** Device presence alone (`glob
   /sys/class/net/efa*`) is **empty inside pods** — netdevs are network-
namespaced — so on K8s the naive check reports "no EFA" and silently
selects
the slow UCX/TCP path. Detection also accepts the rdma-verbs devices the
EFA
k8s device-plugin mounts (`/dev/infiniband/uverbs*` +
`/sys/class/infiniband/*`).

3. **Validate before committing to LIBFABRIC.** EFA-present ≠
GPUDirect-works:
on hosts/drivers without `nvidia-peermem`/dmabuf, LIBFABRIC instantiates
and
registers *small* CUDA buffers via EFA's ~32 MiB host bounce pool (looks
healthy), but `fi_mr_reg` of a real-size buffer fails at transfer time
with
`NIXL_ERR_BACKEND`. We register/deregister a CUDA buffer **at realistic
transfer size** before committing, and fall back to UCX on failure. Size
is
   tunable via `RAY_NIXL_VALIDATE_BYTES`.

4. **VMM (`expandable_segments`) safety.** CUDA VMM memory
(`PYTORCH_CUDA_ALLOC_CONF=expandable_segments:True`, standard in
large-model
   training) cannot be RDMA-registered. The validation probe allocates
non-expandable memory so it mirrors a real registrable buffer rather
than
   false-failing on a VMM probe.

5. **`RAY_NIXL_BACKEND` override.** Per-process auto-detection can
diverge
between the two endpoints of a transfer when they run in different
processes
/ Ray jobs with different allocator state (observed: sender → UCX,
receiver →
LIBFABRIC → every read fails `NIXL_ERR_BACKEND`). `RAY_NIXL_BACKEND=UCX|
LIBFABRIC` lets an orchestrator pin both sides; the size-matched probe
makes
   auto-selection deterministic across same-shaped hosts as the default.

6. **Per-transfer stats + backend-specific diagnostics**
(`NixlTransferStats`:
   bytes, xfer time, throughput, backend) and backend-aware error hints
(`FI_LOG_LEVEL=Debug` for LIBFABRIC, `UCX_LOG_LEVEL=debug` for UCX) on
   registration failure.

## Benchmark results

Validated in a downstream RL trainer (miles) weight-sync workload
(Megatron
trainer → sglang rollout engines) on Anyscale, p5.48xlarge (8×H100-80GB,
32×EFA), Ray 2.55.1 + this change, cross-node (every transfer crosses
the node
boundary). This addresses the draft's "TODO: benchmarking".

| Backend | path | effective bandwidth |
|---|---|---|
| **LIBFABRIC (this PR)** | GPUDirect RDMA over EFA | **~23–30 GiB/s per
source** |
| UCX (status quo on EFA) | software-emulated RMA over TCP | ~0.3 GB/s |

End-to-end weight-sync time (`pull_wait` = pure transfer; full model
bf16):

| Model | size | shard/src | `pull_wait` (transfer) | full sync |
|---|---|---|---|---|
| Qwen3-30B-A3B | 57 GiB | 14.24 GiB | 0.61 s | 2.7 s |
| GLM-4.7-Flash (MLA+MoE) | — | 14.13 GiB | 0.61 s | 1.9 s |
| Moonlight-16B (MLA) | — | 7.48 GiB | 0.33 s | 1.0 s |

- LIBFABRIC over EFA was **~8–9× faster than NCCL broadcast** for the
same
  cross-node sync (~3 s vs ~26 s for the 57 GiB model).
- Flat across 2→4 nodes (transfer is per-source-shard bound, not
node-count
  bound).
- All transfers byte-correct end-to-end (downstream
`--check-weight-update-equal`
  byte-compares the received weights, incl. MLA and fused-MoE tensors).

Without fix ray-project#2 (K8s detection) the change is a silent no-op on pods
(stays on
UCX/TCP). Without ray-project#3/ray-project#4 it selects LIBFABRIC and then fails at transfer
time on
no-GPUDirect/VMM hosts. With all of them, the LIBFABRIC path is correct
and
fast across dense, MoE, and MLA models.

## Related issue number

Builds on / supersedes the draft on
`joshlee/use-libfabric-nixl-backend`.

## Checks

- Testing strategy: exercised via a real cross-node RDT weight-sync
workload on
EFA hardware (numbers above), plus the fallback paths — UCX selection on
non-EFA, and LIBFABRIC→UCX fallback when the transfer-size CUDA
registration
fails (no-GPUDirect host). Suggested unit coverage: `select_backend()`
honors
`RAY_NIXL_BACKEND` and the EFA globs; `get_nixl_agent()` falls back to
UCX when
  the validation registration raises.
- [ ] Signed off commits
- [ ] `scripts/format.sh`
- [ ] Doc update (`doc/source/ray-core/direct-transport.rst` — backend
selection section)
- [ ] Tests passing

## Notes for reviewers

- The `NixlTransferStats` backend field reads
`list(nixl_agent.backends.keys())`;
confirm `backends` is always a dict on the supported NIXL version (an
earlier
review flagged a possible `AttributeError`) and consider guarding it,
since the
  stats path runs on the hot recv path.
- Detection globs are cached (`functools.lru_cache`) — fine since
hardware
  doesn't change within a process.

---------

Signed-off-by: Joshua Lee <[email protected]>
Signed-off-by: xyuzh <[email protected]>
Co-authored-by: xyuzh <[email protected]>
Signed-off-by: 400Ping <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

core Issues that should be addressed in Ray Core docs An issue or change related to documentation go add ONLY when ready to merge, run all tests unstale A PR that has been marked unstale. It will not get marked stale again if this label is on it.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants