Skip to content
Open
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
20 changes: 15 additions & 5 deletions lib/bindings/python/src/dynamo/nixl_connect/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
from __future__ import annotations

import asyncio
import base64
import logging
import socket
import uuid
Expand Down Expand Up @@ -1185,7 +1186,7 @@ async def _wait_for_completion_(self) -> None:
case _:
return

def metadata(self) -> RdmaMetadata:
def metadata(self, hex_encode: bool = False) -> RdmaMetadata:
"""
Gets the request descriptor for the operation.
"""
Expand All @@ -1209,9 +1210,14 @@ def metadata(self) -> RdmaMetadata:
f"dynamo.nixl_connect.{self.__class__.__name__}: Compressed NIXL metadata is larger than original ({compressed_len} > {original_len})."
)

if not hex_encode:
encoded_metadata = base64.b64encode(nixl_metadata).decode("utf-8")
encoded_metadata = "b64:" + encoded_metadata
else:
encoded_metadata = nixl_metadata.hex()
self._serialized_request = RdmaMetadata(
descriptors=descriptors,
nixl_metadata=nixl_metadata.hex(),
nixl_metadata=encoded_metadata,
notification_key=self._notification_key,
operation_kind=int(self._operation_kind),
)
Expand Down Expand Up @@ -1471,11 +1477,15 @@ def __init__(
self._connector = connector

# When `nixl_metadata` is a string, it is assumed to have come from a remote worker
# via a `RdmaMetadata` object and therefore can assumed be a hex-encoded, compressed
# via a `RdmaMetadata` object and therefore can assumed be a b64-encoded, compressed
# representation of the NIXL metadata.
if isinstance(nixl_metadata, str):
# Decode the hex-encoded string into bytes.
nixl_metadata = bytes.fromhex(nixl_metadata)
Copy link
Collaborator

Choose a reason for hiding this comment

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

while b64 encoding is a win in size, we cannot just change the encoding and walk away.

please add a method to fallback to hex encoding to retain compatability.

Copy link
Author

Choose a reason for hiding this comment

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

Added a fallback to hex in case people work with mismatched nixl_connect versions.

In some cases b64 and hex data cannot be distinguished so I added a small identifiable prefix for the new b64 encoding.

if nixl_metadata.startswith("b64:"):
# Decode the b64-encoded string into bytes.
nixl_metadata = base64.b64decode(nixl_metadata.lstrip("b64:"))
else:
# fallback for earlier versions of nixl connect
nixl_metadata = bytes.fromhex(nixl_metadata)
# Decompress the NIXL metadata.
nixl_metadata = zlib.decompress(nixl_metadata)

Expand Down
Loading