Repository navigation
[Transport] Add native batched transfers to NIXL - #205182
thisisatharva-rh wants to merge 11 commits into
Conversation
[ghstack-poisoned]
PR Status: ready for maintainer reviewWaiting for re-review: These reviewers have been asked to review the latest updates. ✅ AUTOMATED REVIEW - Ready for human review:
Findings (9): Reviewed commit: 🔗 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 FailuresAs of commit ea3b1d9 with merge base b649432 ( This comment was automatically generated by Dr. CI and updates every 15 minutes. |
[ghstack-poisoned]
…ked waiter test [ghstack-poisoned]
[ghstack-poisoned]
| works: list[Work] = [] | ||
| for pairs in groups.values(): | ||
| try: | ||
| work = self._prepare(agent, operation, pairs, timeout) |
There was a problem hiding this comment.
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?
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
…p dispatch [ghstack-poisoned]
Withdrawn: the automated review of 34a7417 found nothing blocking.
…rns an error state [ghstack-poisoned]
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
⚪ 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.
| 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 |
There was a problem hiding this comment.
⚪ 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.
| transfers: list[tuple[MemoryView, RemoteBuffer]], | ||
| deadline: float | None, | ||
| ) -> tuple[list[Work], Exception | None]: | ||
| with self._locked(_remaining(deadline)): |
There was a problem hiding this comment.
⚪ 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).
| # 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(): |
There was a problem hiding this comment.
⚪ 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.
| 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) |
There was a problem hiding this comment.
⚪ 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).
| with self.assertRaisesRegex(TimeoutError, "before dispatch"): | ||
| work.wait() | ||
| self.assertTrue(work.is_completed()) | ||
| self.assertEqual(targets[1].count_nonzero(), 0) |
There was a problem hiding this comment.
⚪ 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.
| # Nothing started, so the batch raises at submission. | ||
| with self.assertRaisesRegex(RuntimeError, "initialize failed"): | ||
| first.write_batch(pairs, async_op=True) | ||
| else: |
There was a problem hiding this comment.
⚪ 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.
| self.assertEqual(targets[1][4:].count_nonzero(), 0) | ||
| self.assertEqual(targets[2], sources[0]) | ||
|
|
||
| def test_pending_batch_retains_every_view(self): |
There was a problem hiding this comment.
⚪ 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.
| 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 |
There was a problem hiding this comment.
⚪ 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.
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
Authored with the assistance of an AI coding agent