Skip to content

[Transport] Add native batched transfers to NIXL - #205182

Open
thisisatharva-rh wants to merge 11 commits into
gh/thisisatharva-rh/4/basefrom
gh/thisisatharva-rh/4/head
Open

thisisatharva-rh wants to merge 11 commits into
gh/thisisatharva-rh/4/basefrom
gh/thisisatharva-rh/4/head

Conversation

@thisisatharva-rh

@thisisatharva-rh thisisatharva-rh commented Nov 16, 2026 •

Copy link
Copy Markdown
Collaborator

Stack from ghstack (oldest at bottom):

Signed-off-by: thisisatharva-rh [email protected]

Summary

Adds native batching to NIXLTransport, so a batch becomes one NIXL request for each (remote agent, local memory type, remote memory type), not one request per pair. That's the minimum NIXL allows, since each descriptor list has one memory type and each request goes to one peer. Each remote registration's metadata is loaded once per batch, before anything is dispatched, so metadata that fails to load or names a different agent fails the batch with nothing started. Anything NIXL rejects when creating a request stops dispatch under the usual non-atomic batch contract: the requests already started finish before the error is reported.

Test Plan

python test/distributed/test_transport_nixl.py
python test/distributed/test_transport_nixl_native.py

Authored with the assistance of an AI coding agent

[ghstack-poisoned]
@pytorch-bot

pytorch-bot Bot commented Nov 16, 2026 •

Copy link
Copy Markdown

PR Status: ready for maintainer review

Waiting for re-review: brandondfeng.

These reviewers have been asked to review the latest updates.

✅ AUTOMATED REVIEW - Ready for human review:

The PR adds native write_batch/read_batch to NIXLTransport, sending one NIXL
request per (remote agent, local memory type, remote memory type) and loading
each remote registration's metadata once before dispatch. The latest round also
stops dispatch when agent.transfer raises or returns an error state.
Recommendation: Approve; every remaining point is non-blocking. brandondfeng's
CHANGES_REQUESTED review still has to be re-reviewed and dismissed.

Findings (9):

[minor] torch/distributed/_transport/nixl/_transport.py:633
Non-blocking: an interrupt during a batch leaves the started requests with no
Work to wait on. `_post` stores any BaseException from `agent.transfer` in
`work._error` on purpose, because DMA may already have started. The new `raise
work._error` re-raises KeyboardInterrupt/SystemExit straight out of
write_batch/read_batch. The caller gets nothing for that request or for earlier
groups still running. Batch Works carry no notification, so the progress thread
never polls them. They stay in `_pending`/`_transfers`, and `unregister_memory`
fails with "memory has pending transfers" until close(). This contradicts the
`_api.py:535-538` contract (started Works settle before the error is reported),
the `_submit_batch` docstring, the comment at :614-616, and single write/read
behavior. Also, `return works, work._error` reports the same exception both as
dispatch_error and as the child's error; that is unnecessary. Fix: replace
:630-635 with `if work._error is not None or work._state not in ("PROC",
"DONE"): return works, None`. The child Work already carries the error, and
`_BatchWork.wait` reports it after everything settles. Add a KeyboardInterrupt
mode to test_batch_transfer_error_stops_dispatch; no test covers this branch
now.

[minor] torch/distributed/_transport/nixl/_transport.py:614
Non-blocking: the PR body says "Anything NIXL rejects when creating a request
stops dispatch". Since this round, a raise or an error state from
`agent.transfer` also stops dispatch, so "creating or posting a request" is more
accurate.

[minor] torch/distributed/_transport/nixl/_transport.py:584
Non-blocking, carried over: `_submit_batch` holds `_operation_lock` for the
whole batch. That covers every `_check_transfer`, every `add_remote_agent`, and
each group's `get_xfer_descs`/`initialize_xfer`/`transfer`. A concurrent
write/read, wait_notifications, or progress-thread poll can therefore wait for
the entire dispatch. Please document the lock scope in the class docstring
(:78-80) and in the `_progress` comment (:290-295).

[minor] torch/distributed/_transport/nixl/_transport.py:618
Non-blocking, carried over: `docs/source/distributed/transport.md:130` says
"Each live transfer owns a distinct request handle". Pairs in the same batch
group now share one handle. The PR doesn't touch that file.

[minor] test/distributed/test_transport_nixl.py:1076
Non-blocking: in test_batch_transfer_error_stops_dispatch,
`self.assertEqual(targets[1].count_nonzero(), 0)` cannot fail, even if group 1
were posted. `transfer` is replaced outright by `fail_transfer`, which never
copies, and the fake `check_xfer_state` (:167-170) never copies either. Only the
`call_count == 1` asserts at :1066-1067 catch continued dispatch. Fix: drop the
line, or wrap the real fake `transfer` and fail only the call for remote_agent
== "second". Because setUp sets transfer_state = "DONE", a wrongly dispatched
group 1 would then copy into targets[1]. Optionally, the error_state mode can
use `patch.object(agent, "transfer_state", "ERR")`, as
test_native_terminal_failure_is_released does (:625).

[minor] test/distributed/test_transport_nixl.py:1131
Non-blocking, carried over: in test_batch_deadline_checked_before_each_group,
`assertEqual(targets[1].count_nonzero(), 0)` cannot fail. The fake is held at
"PROC", so `transfer` returns before copying (:152-153), and `check_xfer_state`
never copies.

(3 more not shown, see the review run)

Reviewed commit: ea3b1d9

Review run

🐛 Report a bad review

🔗 Helpful Links

🧪 See artifacts and rendered test results at hud.pytorch.org/pr/205182

Note: Links to docs will display an error until the docs builds have been completed.

✅ No Failures

As of commit ea3b1d9 with merge base b649432 (image):
💚 Looks good so far! There are no failures yet. 💚

This comment was automatically generated by Dr. CI and updates every 15 minutes.

[ghstack-poisoned]
thisisatharva-rh added a commit that referenced this pull request Nov 17, 2026
thisisatharva-rh added a commit that referenced this pull request Nov 18, 2026
[ghstack-poisoned]
thisisatharva-rh added a commit that referenced this pull request Nov 18, 2026
@thisisatharva-rh
thisisatharva-rh marked this pull request as ready for review November 18, 2026 16:24
@github-actions github-actions Bot added bot-triaged This is a label only to be used by the auto triage bot triaged This issue has been looked at a team member, and triaged and prioritized into an appropriate module labels Nov 18, 2026
@pytorch-bot pytorch-bot Bot added the in progress PR is being worked on by the author, until the automated review accepts it label Nov 18, 2026
github-actions[bot]

This comment was marked as outdated.

@pytorch-bot pytorch-bot Bot added ready for review Automated review passed, ready for a final review by a maintainer. and removed in progress PR is being worked on by the author, until the automated review accepts it labels Nov 18, 2026
works: list[Work] = []
for pairs in groups.values():
try:
work = self._prepare(agent, operation, pairs, timeout)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

loading the metadata can succeed even if it does not cover a descriptor's requested range. so for example, in a batch with two peers, the second request can fail that range check after the first has already written.

could we validate all ranges before posting or narrow the promise that a bad descriptor starts no transfers?

@pytorch-bot pytorch-bot Bot added the in progress PR is being worked on by the author, until the automated review accepts it label Nov 19, 2026
github-actions[bot]

This comment was marked as outdated.

[ghstack-poisoned]
thisisatharva-rh added a commit that referenced this pull request Nov 20, 2026
github-actions[bot]

This comment was marked as outdated.

[ghstack-poisoned]
thisisatharva-rh added a commit that referenced this pull request Nov 20, 2026
github-actions[bot]

This comment was marked as outdated.

thisisatharva-rh added a commit that referenced this pull request Nov 24, 2026
github-actions[bot]

This comment was marked as outdated.

thisisatharva-rh added a commit that referenced this pull request Dec 1, 2026
github-actions[bot]

This comment was marked as outdated.

thisisatharva-rh added a commit that referenced this pull request Dec 1, 2026
github-actions[bot]

This comment was marked as outdated.

@github-actions
github-actions Bot dismissed stale reviews from themself December 1, 2026 14:44

Withdrawn: the automated review of 34a7417 found nothing blocking.

thisisatharva-rh added a commit that referenced this pull request Dec 1, 2026

@github-actions github-actions 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.

Automated review of ea3b1d9: nothing blocking; ready for human review.

The PR adds native write_batch/read_batch to NIXLTransport, sending one NIXL request per (remote agent, local memory type, remote memory type) and loading each remote registration's metadata once before dispatch. The latest round also stops dispatch when agent.transfer raises or returns an error state. Recommendation: Approve; every remaining point is non-blocking. brandondfeng's CHANGES_REQUESTED review still has to be re-reviewed and dismissed.

⚪ 9 non-blocking findings are attached to the code below, collapsed.

This review is AI-generated and advisory. Each new automated review replaces the previous one. Report a bad review

if work._error is not None:
if isinstance(work._error, Exception):
return works, work._error
raise work._error

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.

⚪ Non-blocking: an interrupt during a batch leaves the started requests with no Work to wait on. _post stores any BaseException from agent.transfer…

Non-blocking: an interrupt during a batch leaves the started requests with no Work to wait on. _post stores any BaseException from agent.transfer in work._error on purpose, because DMA may already have started. The new raise work._error re-raises KeyboardInterrupt/SystemExit straight out of write_batch/read_batch. The caller gets nothing for that request or for earlier groups still running. Batch Works carry no notification, so the progress thread never polls them. They stay in _pending/_transfers, and unregister_memory fails with "memory has pending transfers" until close(). This contradicts the _api.py:535-538 contract (started Works settle before the error is reported), the _submit_batch docstring, the comment at :614-616, and single write/read behavior. Also, return works, work._error reports the same exception both as dispatch_error and as the child's error; that is unnecessary. Fix: replace :630-635 with if work._error is not None or work._state not in ("PROC", "DONE"): return works, None. The child Work already carries the error, and _BatchWork.wait reports it after everything settles. Add a KeyboardInterrupt mode to test_batch_transfer_error_stops_dispatch; no test covers this branch now.

Report this finding

local_type = view._memory._registration.memory_type
key = (remote.agent_name, local_type, remote.memory_type)
groups.setdefault(key, []).append((view, remote))
# Requests start one at a time, without rollback: a request NIXL rejects

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.

⚪ Non-blocking: the PR body says "Anything NIXL rejects when creating a request stops dispatch".

Since this round, a raise or an error state from agent.transfer also stops dispatch, so "creating or posting a request" is more accurate.

Report this finding

transfers: list[tuple[MemoryView, RemoteBuffer]],
deadline: float | None,
) -> tuple[list[Work], Exception | None]:
with self._locked(_remaining(deadline)):

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.

⚪ Non-blocking, carried over: _submit_batch holds _operation_lock for the whole batch.

That covers every _check_transfer, every add_remote_agent, and each group's get_xfer_descs/initialize_xfer/transfer. A concurrent write/read, wait_notifications, or progress-thread poll can therefore wait for the entire dispatch. Please document the lock scope in the class docstring (:78-80) and in the _progress comment (:290-295).

Report this finding

# stops dispatch and is reported after the started ones finish, per the
# backend-agnostic batch contract in Transport._transfer_batch.
works: list[Work] = []
for pairs in groups.values():

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.

⚪ Non-blocking, carried over: docs/source/distributed/transport.md:130 says "Each live transfer owns a distinct request handle".

Pairs in the same batch group now share one handle. The PR doesn't touch that file.

Report this finding

self.assertTrue(work.is_completed())
self.assertEqual(checks.call_count, 2 if mode == "raises" else 0)
self.assertEqual(agent.released, 1)
self.assertEqual(targets[1].count_nonzero(), 0)

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.

⚪ Non-blocking: in test_batch_transfer_error_stops_dispatch, self.assertEqual(targets[1].count_nonzero(), 0) cannot fail, even if group 1 were…

Non-blocking: in test_batch_transfer_error_stops_dispatch, self.assertEqual(targets\[1\].count_nonzero(), 0) cannot fail, even if group 1 were posted. transfer is replaced outright by fail_transfer, which never copies, and the fake check_xfer_state (:167-170) never copies either. Only the call_count == 1 asserts at :1066-1067 catch continued dispatch. Fix: drop the line, or wrap the real fake transfer and fail only the call for remote_agent == "second". Because setUp sets transfer_state = "DONE", a wrongly dispatched group 1 would then copy into targets[1]. Optionally, the error_state mode can use patch.object(agent, "transfer_state", "ERR"), as test_native_terminal_failure_is_released does (:625).

Report this finding

with self.assertRaisesRegex(TimeoutError, "before dispatch"):
work.wait()
self.assertTrue(work.is_completed())
self.assertEqual(targets[1].count_nonzero(), 0)

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.

⚪ Non-blocking, carried over: in test_batch_deadline_checked_before_each_group, assertEqual(targets[1].count_nonzero(), 0) cannot fail.

The fake is held at "PROC", so transfer returns before copying (:152-153), and check_xfer_state never copies.

Report this finding

# Nothing started, so the batch raises at submission.
with self.assertRaisesRegex(RuntimeError, "initialize failed"):
first.write_batch(pairs, async_op=True)
else:

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.

⚪ Non-blocking, carried over: test_batch_rejected_request[third] (:1031-1038) cannot fail on its claims. setUp sets transfer_state = "DONE" (:202), so…

Non-blocking, carried over: test_batch_rejected_request[third] (:1031-1038) cannot fail on its claims. setUp sets transfer_state = "DONE" (:202), so the first request finishes inside _post and assertTrue(work.is_completed()) cannot fail. The rejected group is last, so call_count == 2 comes out the same whether dispatch stops or continues. Fix: hold the first request at "PROC", and add a group after the rejected one.

Report this finding

self.assertEqual(targets[1][4:].count_nonzero(), 0)
self.assertEqual(targets[2], sources[0])

def test_pending_batch_retains_every_view(self):

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.

⚪ Non-blocking, carried over: test_pending_batch_retains_every_view (:1002-1012) does not assert len(first._pending) == 1.

If grouping ever split by local registration, the test would silently stop exercising multi-view retention.

Report this finding

target.zero_()
# Reconnecting with the same bind() bytes is a no-op.
transport.connect(urls[0])
# One batch reads from both peers; each peer's request spans two

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.

⚪ Non-blocking, carried over: the real-NIXL check that partial metadata loads are merged (:122-131) runs only with TORCH_TEST_NIXL=1 (:215-218).

Nothing in CI sets that, and the Test Plan's plain python commands skip it. Please confirm you ran it against a real NIXL/UCX install.

Report this finding

@pytorch-bot pytorch-bot Bot added ready for review Automated review passed, ready for a final review by a maintainer. and removed in progress PR is being worked on by the author, until the automated review accepts it labels Dec 1, 2026

This branch was previously deployed

1 inactive (outdated) deployment
bedrock — 6f927cb5 Deployed Nov 18, 2026 by thisisatharva-rh via analyze #35104
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bot-triaged This is a label only to be used by the auto triage bot ciflow/torchtitan Run TorchTitan integration tests open source ready for review Automated review passed, ready for a final review by a maintainer. release notes: distributed (c10d) release notes category triaged This issue has been looked at a team member, and triaged and prioritized into an appropriate module

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants