mstar.communication.tensors#
Functions
|
Select tensor transport backend based on protocol. |
Classes
|
Background thread for non-blocking mooncake READ operations. |
|
|
|
|
|
No-op engine for SHM / single-node — data is already in local GPU memory. |
|
|
|
Wraps mooncake.engine.TransferEngine for RDMA or TCP transport. |
|
Tensor transport via file I/O to a tmpfs directory ( |
|
|
|
Base class for inter-worker tensor transport. |
Abstract interface for low-level memory registration and async reads. |
|
|
- class mstar.communication.tensors.AsyncMooncakeReader(engine, device, max_workers=3, max_batch_size=500, enable_prof=False)[source]#
Bases:
objectBackground thread for non-blocking mooncake READ operations.
Follows SGLang’s pattern: caller records CUDA event on default stream, submits write task to thread pool. Worker thread waits on event via dedicated CUDA stream, then does blocking mooncake PUTs. The default stream is never blocked by store writes.
- submit(read_info)[source]#
Non-blocking: enqueue a batch of READs.
Records a CUDA event on the current stream to ensure GPU data is ready before the background thread reads it.
- Parameters:
read_info (list[TransferReadInfo])
- Return type:
Future
- class mstar.communication.tensors.BufferedShards(total_fanin: int, shard_dim: int, shards: dict[int, list[torch.Tensor]])[source]#
Bases:
object
- class mstar.communication.tensors.FutureAndPointers(future: concurrent.futures._base.Future | None, graph_edges: list[mstar.graph.base.GraphEdge], request_id: str = '', rx_time: float | None = None)[source]#
Bases:
object- Parameters:
- class mstar.communication.tensors.LocalTransferEngine(hostname)[source]#
Bases:
TensorTransferEngineNo-op engine for SHM / single-node — data is already in local GPU memory.
- Parameters:
hostname (str)
- get_async_reader(device)[source]#
Return an async reader for background transfers, or None if not needed.
- Return type:
None
- get_session_id()[source]#
Return the session ID for this engine (e.g., ‘hostname:port’).
- Return type:
- class mstar.communication.tensors.MooncakeCommunicationManager(my_entity_id, hostname, device, communicator, protocol=CommProtocol.RDMA, metadata_server='P2PHANDSHAKE', tcp_transfer_device='', enable_prof=False)[source]#
Bases:
TensorCommunicationManager- Parameters:
my_entity_id (str)
hostname (str)
device (str)
communicator (BaseCommunicator)
protocol (CommProtocol)
metadata_server (str)
tcp_transfer_device (str)
enable_prof (bool)
- register_for_send(request_id, tensor_infos, skip_cuda_sync=False)[source]#
Mark these tensors ready for remote consumers to RDMA-read.
skip_cuda_sync=Trueskips the default-stream sync this call normally issues to ensure the source tensors’ writes are visible before their addresses are shared with peers. Callers must have already synced on their own (e.g. before a batched loop) — meant to cut N serialized syncs to 1 when registering many tensors in a row.If self.enable_prof is set, this should also update self.req_tx_info
- class mstar.communication.tensors.MooncakeTransferEngine(hostname, protocol, metadata_server='P2PHANDSHAKE', tcp_transfer_device='')[source]#
Bases:
TensorTransferEngineWraps mooncake.engine.TransferEngine for RDMA or TCP transport.
- Parameters:
hostname (str)
protocol (CommProtocol)
metadata_server (str)
tcp_transfer_device (str)
- get_async_reader(device)[source]#
Return an async reader for background transfers, or None if not needed.
- Return type:
- get_session_id()[source]#
Return the session ID for this engine (e.g., ‘hostname:port’).
- Return type:
Bases:
TensorCommunicationManagerTensor transport via file I/O to a tmpfs directory (
/dev/shm).- Parameters:
Mark these tensors ready for remote consumers to RDMA-read.
skip_cuda_sync=Trueskips the default-stream sync this call normally issues to ensure the source tensors’ writes are visible before their addresses are shared with peers. Callers must have already synced on their own (e.g. before a batched loop) — meant to cut N serialized syncs to 1 when registering many tensors in a row.If self.enable_prof is set, this should also update self.req_tx_info
- Parameters:
request_id (str)
tensor_infos (list[TensorPointerInfo])
skip_cuda_sync (bool)
- class mstar.communication.tensors.TensorAndReferenceInfo(tensor: torch.Tensor, ref_cnt: int = 0, persist: bool = False, mem_registered: bool = False)[source]#
Bases:
object
- class mstar.communication.tensors.TensorCommunicationManager(my_entity_id, my_session_id, device, communicator, transfer_engine, enable_prof=False)[source]#
Bases:
ABCBase class for inter-worker tensor transport.
Holds common attributes and shared method implementations. Subclasses only need to override
__init__,register_for_send,start_read_tensors, and_cleanup_by_uuid.- Parameters:
my_entity_id (str)
my_session_id (str)
device (str)
communicator (BaseCommunicator)
transfer_engine (TensorTransferEngine)
enable_prof (bool)
- ack_unread_tensors(request_id, graph_edges)[source]#
Ack result tensors for an already-removed request without reading them.
The producer holds these output buffers until it gets the TENSOR_RECEIVED ack; emit it here so it can reclaim them.
- pending: list[FutureAndPointers]#
- abstractmethod register_for_send(request_id, tensor_infos, skip_cuda_sync=False)[source]#
Mark these tensors ready for remote consumers to RDMA-read.
skip_cuda_sync=Trueskips the default-stream sync this call normally issues to ensure the source tensors’ writes are visible before their addresses are shared with peers. Callers must have already synced on their own (e.g. before a batched loop) — meant to cut N serialized syncs to 1 when registering many tensors in a row.If self.enable_prof is set, this should also update self.req_tx_info
- Parameters:
request_id (str)
tensor_infos (list[TensorPointerInfo])
skip_cuda_sync (bool)
- register_request(request_id, sharding_config)[source]#
- Parameters:
request_id (str)
sharding_config (ShardingConfig)
- set_output_ref_counts(request_id, safety_hold_uuids, routed_edges)[source]#
Adjust ref counts from the safety hold (1) to the actual fanout.
Called after
process_node_outputsdetermines the real routing.safety_hold_uuidsis the set of UUIDs that were given ref=1 bystore_and_populate_graph_edges(skip_ref_count=True).routed_edgesis the flat list of all edges that will actually be consumed (local ingestion, remote send, persist, emit, streaming).
- store_and_populate_graph_edges(request_id, tensors, graph_edges, node_name=None, graph_walk=None, skip_cuda_sync=False, skip_ref_count=False)[source]#
- class mstar.communication.tensors.TensorStore[source]#
Bases:
object
- class mstar.communication.tensors.TensorTransferEngine[source]#
Bases:
ABCAbstract interface for low-level memory registration and async reads.
Wraps the transport-specific engine (Mooncake RDMA, local no-op, etc.) so that higher-level code (PagedAllocationManager, TensorCommunicationManager) never imports or depends on a specific transport library.
- abstractmethod get_async_reader(device)[source]#
Return an async reader for background transfers, or None if not needed.
- Return type:
AsyncMooncakeReader | None
- abstractmethod get_session_id()[source]#
Return the session ID for this engine (e.g., ‘hostname:port’).
- Return type:
- class mstar.communication.tensors.TransferReadInfo(source_session_id: str, local_ptr: int, remote_ptr: int, nbytes: int, fp: mstar.communication.tensors.FutureAndPointers | None = None)[source]#
Bases:
object- Parameters:
source_session_id (str)
local_ptr (int)
remote_ptr (int)
nbytes (int)
fp (FutureAndPointers | None)
- fp: FutureAndPointers | None = None#
- mstar.communication.tensors.create_tensor_communication_manager(protocol, my_entity_id, hostname, device, communicator, metadata_server='P2PHANDSHAKE', tcp_transfer_device='', shm_dir=None, enable_prof=False)[source]#
Select tensor transport backend based on protocol.
For the SHM protocol,
MSTAR_SHM_ARENAselects the implementation (seedocs/environment_variables.rst):0(default) — per-uuid files;1— the Rust shared-memory arena (raises if themstar_rustextension is missing);AUTO— the arena when the extension imports, files otherwise. The flag must match across the deployment: the arena location rides in the tensor descriptors, so a file-transport consumer cannot read an arena producer.- Parameters:
protocol (CommProtocol)
my_entity_id (str)
hostname (str)
device (str)
communicator (BaseCommunicator)
metadata_server (str)
tcp_transfer_device (str)
shm_dir (str | None)
enable_prof (bool)
- Return type: