vllm.distributed.kv_transfer.kv_pipe.pynccl_pipe
This module implements a PyNccl pipe for sending and receiving Optional[torch.Tensor] between distributed ranks with advanced communication features.
Key Features: - Supports sending and receiving tensors with metadata - Handles both CUDA and CPU device communications - Implements a non-blocking tensor transfer mechanism - Manages buffer size and provides backpressure control - Supports distributed process groups with configurable parameters
BrokenPipeException
¶
Bases: Exception
Source code in vllm/distributed/kv_transfer/kv_pipe/pynccl_pipe.py
PyNcclPipe
¶
Bases: KVPipeBase
Source code in vllm/distributed/kv_transfer/kv_pipe/pynccl_pipe.py
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 |
|
group
instance-attribute
¶
group = create(
host=kv_ip,
port=kv_port + port_offset,
rank=kv_rank,
world_size=kv_parallel_size,
store_timeout=store_timeout,
)
__init__
¶
__init__(
local_rank: int,
config: KVTransferConfig,
device: Optional[str] = None,
port_offset: int = 0,
)
Source code in vllm/distributed/kv_transfer/kv_pipe/pynccl_pipe.py
_get_device_send_recv_impl
¶
_get_device_send_recv_impl(
group: StatelessProcessGroup,
) -> tuple[
Callable[[Tensor, int], None],
Callable[[Tensor, int], None],
]
Source code in vllm/distributed/kv_transfer/kv_pipe/pynccl_pipe.py
_make_metadata
¶
Create the metadata as a dictionary based on the input tensor.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
tensor
|
Optional[Tensor]
|
The input tensor or None if no tensor is provided. |
required |
Returns:
Name | Type | Description |
---|---|---|
metadata |
Metadata
|
A dictionary with the following keys: - "dtype": The data type of the tensor or None. - "shape": The shape of the tensor or None. |
Source code in vllm/distributed/kv_transfer/kv_pipe/pynccl_pipe.py
_prepare_recv_buffer
¶
Create a buffer to receive the tensor based on the provided metadata.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
metadata
|
Metadata
|
A dictionary with keys "dtype" and "shape", describing the tensor's data type and shape. |
required |
Returns:
Name | Type | Description |
---|---|---|
buffer |
Tensor
|
A tensor of the specified type and shape,
allocated on |
Source code in vllm/distributed/kv_transfer/kv_pipe/pynccl_pipe.py
_recv_impl
¶
The actual implementation of receiving a tensor and its metadata from the target rank.
Returns:
Name | Type | Description |
---|---|---|
buffer |
Optional[Tensor]
|
The received tensor, or |
Source code in vllm/distributed/kv_transfer/kv_pipe/pynccl_pipe.py
_recv_metadata
¶
_recv_metadata() -> Metadata
Receive the metadata dictionary from the target rank.
Returns:
Name | Type | Description |
---|---|---|
metadata |
Metadata
|
A dictionary with keys "dtype" and "shape" describing the tensor. |
Source code in vllm/distributed/kv_transfer/kv_pipe/pynccl_pipe.py
_send_impl
¶
The actual implementation of sending the tensor and its metadata to the target rank.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
tensor
|
Optional[Tensor]
|
The input tensor to be sent, or |
required |
Source code in vllm/distributed/kv_transfer/kv_pipe/pynccl_pipe.py
_send_metadata
¶
_send_metadata(metadata: Metadata)
Send the metadata dictionary to the target rank.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
metadata
|
Metadata
|
A dictionary with keys "dtype" and "shape". |
required |
Source code in vllm/distributed/kv_transfer/kv_pipe/pynccl_pipe.py
block_if_full
¶
Block the current thread if the buffer size is larger than the threshold.
Source code in vllm/distributed/kv_transfer/kv_pipe/pynccl_pipe.py
close
¶
Close the pipe and release associated resources.
recv_tensor
¶
Receives a tensor and its metadata from the source rank. Blocking call.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
tensor
|
The received tensor, or |
required |
Source code in vllm/distributed/kv_transfer/kv_pipe/pynccl_pipe.py
send_tensor
¶
Sends a tensor and its metadata to the destination rank in a non-blocking way.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
tensor
|
Optional[Tensor]
|
The tensor to send, or |
required |
Source code in vllm/distributed/kv_transfer/kv_pipe/pynccl_pipe.py
send_tensor_wrapper
¶
Wrapper for _send_impl to handle exceptions and update buffer size.