Skip to content

Add unique_id_from_bytes for NCCLLibrary #6343

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,27 @@ def ncclGetUniqueId(self) -> ncclUniqueId:
self.NCCL_CHECK(self._funcs["ncclGetUniqueId"](ctypes.byref(unique_id)))
return unique_id

def unique_id_from_bytes(self, data: bytes) -> ncclUniqueId:
"""
Reconstructs an `ncclUniqueId` object from bytes data.

Args:
data: Must be a 128-byte data block (matching NCCL's unique_id).

Returns:
ncclUniqueId: The reconstructed NCCL Unique ID object.

Raises:
ValueError: If the input data length is not 128 bytes.
"""
if len(data) != 128:
raise ValueError(
f"Expected 128 bytes for ncclUniqueId, got {len(data)} bytes")

unique_id = ncclUniqueId()
ctypes.memmove(ctypes.addressof(unique_id.internal), data, 128)
return unique_id

def ncclCommInitRank(
self, world_size: int, unique_id: ncclUniqueId, rank: int
) -> ncclComm_t:
Expand Down
Loading