distributed
¶
Classes¶
fastvideo.distributed.StatelessProcessGroup
dataclass
¶
StatelessProcessGroup(rank: int, world_size: int, store: Store, data_expiration_seconds: int = 3600, send_dst_counter: dict[int, int] = dict(), recv_src_counter: dict[int, int] = dict(), broadcast_send_counter: int = 0, broadcast_recv_src_counter: dict[int, int] = dict(), entries: deque[tuple[str, float]] = deque())
A dataclass to hold a metadata store, and the rank, world_size of the group. Only use it to communicate metadata between processes. For data-plane communication, create NCCL-related objects.
Functions¶
fastvideo.distributed.StatelessProcessGroup.all_gather_obj
¶
All gather an object from all ranks.
Source code in fastvideo/distributed/utils.py
fastvideo.distributed.StatelessProcessGroup.barrier
¶
fastvideo.distributed.StatelessProcessGroup.broadcast_obj
¶
Broadcast an object from a source rank to all other ranks. It does not clean up after all ranks have received the object. Use it for limited times, e.g., for initialization.
Source code in fastvideo/distributed/utils.py
fastvideo.distributed.StatelessProcessGroup.create
staticmethod
¶
create(host: str, port: int, rank: int, world_size: int, data_expiration_seconds: int = 3600) -> StatelessProcessGroup
A replacement for torch.distributed.init_process_group that does not
pollute the global state.
If we have process A and process B called torch.distributed.init_process_group
to form a group, and then we want to form another group with process A, B, C,
D, it is not possible in PyTorch, because process A and process B have already
formed a group, and process C and process D cannot join that group. This
function is a workaround for this issue.
torch.distributed.init_process_group is a global call, while this function
is a stateless call. It will return a StatelessProcessGroup object that can be
used for exchanging metadata. With this function, process A and process B
can call StatelessProcessGroup.create to form a group, and then process A, B,
C, and D can call StatelessProcessGroup.create to form another group.
Source code in fastvideo/distributed/utils.py
fastvideo.distributed.StatelessProcessGroup.expire_data
¶
Expire data that is older than data_expiration_seconds seconds.
Source code in fastvideo/distributed/utils.py
fastvideo.distributed.StatelessProcessGroup.recv_obj
¶
Receive an object from a source rank.
fastvideo.distributed.StatelessProcessGroup.send_obj
¶
Send an object to a destination rank.
Source code in fastvideo/distributed/utils.py
Functions¶
fastvideo.distributed.divide
¶
Ensure that numerator is divisible by the denominator and return the division value.
fastvideo.distributed.ensure_divisibility
¶
Ensure that numerator is divisible by the denominator.
fastvideo.distributed.get_local_torch_device
¶
Return the torch device for the current rank.
Source code in fastvideo/distributed/parallel_state.py
fastvideo.distributed.init_logger
¶
init_logger(name: str) -> _FastvideoLogger
The main purpose of this function is to ensure that loggers are retrieved in such a way that we can be sure the root fastvideo logger has already been configured.
Source code in fastvideo/logger.py
fastvideo.distributed.initialize_model_parallel
¶
initialize_model_parallel(tensor_model_parallel_size: int = 1, sequence_model_parallel_size: int = 1, data_parallel_size: int = 1, backend: str | None = None) -> None
Initialize model parallel groups.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
tensor_model_parallel_size
|
int
|
number of GPUs used for tensor model parallelism (used for language encoder). |
1
|
sequence_model_parallel_size
|
int
|
number of GPUs used for sequence model parallelism (used for DiT). |
1
|
Source code in fastvideo/distributed/parallel_state.py
fastvideo.distributed.sequence_model_parallel_all_gather
¶
sequence_model_parallel_all_gather(input_: Tensor, dim: int = -1) -> Tensor
All-gather the input tensor across model parallel group.
fastvideo.distributed.sequence_model_parallel_all_to_all_4D
¶
sequence_model_parallel_all_to_all_4D(input_: Tensor, scatter_dim: int = 2, gather_dim: int = 1) -> Tensor
All-to-all communication of 4D tensors (e.g. QKV matrices) across sequence parallel group.
Source code in fastvideo/distributed/communication_op.py
fastvideo.distributed.split_tensor_along_last_dim
¶
split_tensor_along_last_dim(tensor: Tensor, num_partitions: int, contiguous_split_chunks: bool = False) -> Sequence[Tensor]
Split a tensor along its last dimension.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
tensor
|
Tensor
|
input tensor. |
required |
num_partitions
|
int
|
number of partitions to split the tensor |
required |
contiguous_split_chunks
|
bool
|
If True, make each chunk contiguous in memory. |
False
|
Returns:
| Type | Description |
|---|---|
Sequence[Tensor]
|
A list of Tensors |
Source code in fastvideo/distributed/utils.py
fastvideo.distributed.tensor_model_parallel_all_gather
¶
tensor_model_parallel_all_gather(input_: Tensor, dim: int = -1) -> Tensor
All-gather the input tensor across model parallel group.
fastvideo.distributed.tensor_model_parallel_all_reduce
¶
All-reduce the input tensor across model parallel group.
Modules¶
fastvideo.distributed.communication_op
¶
Functions¶
fastvideo.distributed.communication_op.sequence_model_parallel_all_gather
¶
sequence_model_parallel_all_gather(input_: Tensor, dim: int = -1) -> Tensor
All-gather the input tensor across model parallel group.
fastvideo.distributed.communication_op.sequence_model_parallel_all_to_all_4D
¶
sequence_model_parallel_all_to_all_4D(input_: Tensor, scatter_dim: int = 2, gather_dim: int = 1) -> Tensor
All-to-all communication of 4D tensors (e.g. QKV matrices) across sequence parallel group.
Source code in fastvideo/distributed/communication_op.py
fastvideo.distributed.communication_op.tensor_model_parallel_all_gather
¶
tensor_model_parallel_all_gather(input_: Tensor, dim: int = -1) -> Tensor
All-gather the input tensor across model parallel group.
fastvideo.distributed.communication_op.tensor_model_parallel_all_reduce
¶
All-reduce the input tensor across model parallel group.
fastvideo.distributed.device_communicators
¶
Modules¶
fastvideo.distributed.device_communicators.base_device_communicator
¶
Classes¶
fastvideo.distributed.device_communicators.base_device_communicator.DeviceCommunicatorBase
¶DeviceCommunicatorBase(cpu_group: ProcessGroup, device: device | None = None, device_group: ProcessGroup | None = None, unique_name: str = '')
Base class for device-specific communicator with autograd support.
It can use the cpu_group to initialize the communicator.
If the device has PyTorch integration (PyTorch can recognize its
communication backend), the device_group will also be given.
Source code in fastvideo/distributed/device_communicators/base_device_communicator.py
fastvideo.distributed.device_communicators.base_device_communicator.DeviceCommunicatorBase.all_gather
¶all_gather(input_: Tensor, dim: int = -1) -> Tensor
Performs an all_gather operation with gradient support.
Source code in fastvideo/distributed/device_communicators/base_device_communicator.py
fastvideo.distributed.device_communicators.base_device_communicator.DeviceCommunicatorBase.all_reduce
¶Performs an all_reduce operation with gradient support.
Source code in fastvideo/distributed/device_communicators/base_device_communicator.py
fastvideo.distributed.device_communicators.base_device_communicator.DeviceCommunicatorBase.all_to_all_4D
¶Performs a 4D all-to-all operation with gradient support.
Source code in fastvideo/distributed/device_communicators/base_device_communicator.py
fastvideo.distributed.device_communicators.base_device_communicator.DeviceCommunicatorBase.gather
¶NOTE: We assume that the input tensor is on the same device across
all the ranks.
NOTE: dst is the local rank of the destination rank.
Source code in fastvideo/distributed/device_communicators/base_device_communicator.py
fastvideo.distributed.device_communicators.base_device_communicator.DeviceCommunicatorBase.recv
¶recv(size: Size, dtype: dtype, src: int | None = None) -> Tensor
Receives a tensor from the source rank.
Source code in fastvideo/distributed/device_communicators/base_device_communicator.py
fastvideo.distributed.device_communicators.base_device_communicator.DeviceCommunicatorBase.send
¶send(tensor: Tensor, dst: int | None = None) -> None
Sends a tensor to the destination rank in a non-blocking way
Source code in fastvideo/distributed/device_communicators/base_device_communicator.py
fastvideo.distributed.device_communicators.base_device_communicator.DistributedAutograd
¶Collection of autograd functions for distributed operations.
This class provides custom autograd functions for distributed operations like all_reduce, all_gather, and all_to_all. Each operation is implemented as a static inner class with proper forward and backward implementations.
fastvideo.distributed.device_communicators.base_device_communicator.DistributedAutograd.AllGather
¶
Bases: Function
Differentiable all_gather operation.
The operation gathers tensors from all ranks and concatenates them along a specified dimension. The backward pass uses reduce_scatter to efficiently distribute gradients back to source ranks.
fastvideo.distributed.device_communicators.base_device_communicator.DistributedAutograd.AllReduce
¶
Bases: Function
Differentiable all_reduce operation.
The gradient of all_reduce is another all_reduce operation since the operation combines values from all ranks equally.
fastvideo.distributed.device_communicators.base_device_communicator.DistributedAutograd.AllToAll4D
¶
Bases: Function
Differentiable all_to_all operation specialized for 4D tensors.
This operation is particularly useful for attention operations where we need to redistribute data across ranks for efficient parallel processing.
The operation supports two modes: 1. scatter_dim=2, gather_dim=1: Used for redistributing attention heads 2. scatter_dim=1, gather_dim=2: Used for redistributing sequence dimensions
fastvideo.distributed.device_communicators.cpu_communicator
¶
Classes¶
fastvideo.distributed.device_communicators.cpu_communicator.CpuCommunicator
¶CpuCommunicator(cpu_group: ProcessGroup, device: device | None = None, device_group: ProcessGroup | None = None, unique_name: str = '')
Bases: DeviceCommunicatorBase
Source code in fastvideo/distributed/device_communicators/cpu_communicator.py
fastvideo.distributed.device_communicators.cpu_communicator.CpuCommunicator.gather
¶NOTE: We assume that the input tensor is on the same device across
all the ranks.
NOTE: dst is the local rank of the destination rank.
Source code in fastvideo/distributed/device_communicators/cpu_communicator.py
fastvideo.distributed.device_communicators.cuda_communicator
¶
Classes¶
fastvideo.distributed.device_communicators.cuda_communicator.CudaCommunicator
¶CudaCommunicator(cpu_group: ProcessGroup, device: device | None = None, device_group: ProcessGroup | None = None, unique_name: str = '')
Bases: DeviceCommunicatorBase
Source code in fastvideo/distributed/device_communicators/cuda_communicator.py
fastvideo.distributed.device_communicators.cuda_communicator.CudaCommunicator.recv
¶recv(size: Size, dtype: dtype, src: int | None = None) -> Tensor
Receives a tensor from the source rank.
Source code in fastvideo/distributed/device_communicators/cuda_communicator.py
fastvideo.distributed.device_communicators.cuda_communicator.CudaCommunicator.send
¶send(tensor: Tensor, dst: int | None = None) -> None
Sends a tensor to the destination rank in a non-blocking way
Source code in fastvideo/distributed/device_communicators/cuda_communicator.py
fastvideo.distributed.device_communicators.npu_communicator
¶
Classes¶
fastvideo.distributed.device_communicators.npu_communicator.NpuCommunicator
¶NpuCommunicator(cpu_group: ProcessGroup, device: device | None = None, device_group: ProcessGroup | None = None, unique_name: str = '')
Bases: DeviceCommunicatorBase
Source code in fastvideo/distributed/device_communicators/npu_communicator.py
fastvideo.distributed.device_communicators.npu_communicator.NpuCommunicator.recv
¶recv(size: Size, dtype: dtype, src: int | None = None) -> Tensor
Receives a tensor from the source rank.
Source code in fastvideo/distributed/device_communicators/npu_communicator.py
fastvideo.distributed.device_communicators.npu_communicator.NpuCommunicator.send
¶send(tensor: Tensor, dst: int | None = None) -> None
Sends a tensor to the destination rank in a non-blocking way
Source code in fastvideo/distributed/device_communicators/npu_communicator.py
fastvideo.distributed.device_communicators.pyhccl
¶
Classes¶
fastvideo.distributed.device_communicators.pyhccl.PyHcclCommunicator
¶PyHcclCommunicator(group: ProcessGroup | StatelessProcessGroup, device: int | str | device, library_path: str | None = None)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
group
|
ProcessGroup | StatelessProcessGroup
|
the process group to work on. If None, it will use the default process group. |
required |
device
|
int | str | device
|
the device to bind the PyHcclCommunicator to. If None, it will be bind to f"npu:{local_rank}". |
required |
library_path
|
str | None
|
the path to the HCCL library. If None, it will use the default library path. |
None
|
It is the caller's responsibility to make sure each communicator is bind to a unique device.
Source code in fastvideo/distributed/device_communicators/pyhccl.py
Functions¶
fastvideo.distributed.device_communicators.pynccl
¶
Classes¶
fastvideo.distributed.device_communicators.pynccl.PyNcclCommunicator
¶PyNcclCommunicator(group: ProcessGroup | StatelessProcessGroup, device: int | str | device, library_path: str | None = None)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
group
|
ProcessGroup | StatelessProcessGroup
|
the process group to work on. If None, it will use the default process group. |
required |
device
|
int | str | device
|
the device to bind the PyNcclCommunicator to. If None, it will be bind to f"cuda:{local_rank}". |
required |
library_path
|
str | None
|
the path to the NCCL library. If None, it will use the default library path. |
None
|
It is the caller's responsibility to make sure each communicator is bind to a unique device.
Source code in fastvideo/distributed/device_communicators/pynccl.py
Functions¶
fastvideo.distributed.parallel_state
¶
FastVideo distributed state. It takes over the control of the distributed environment from PyTorch. The typical workflow is:
- call
init_distributed_environmentto initialize the distributed environment. -
call
initialize_model_parallelorensure_model_parallel_initializedto initialize the model parallel groups. -
any code dealing with the distributed stuff
-
call
destroy_model_parallelto destroy the model parallel groups. - call
destroy_distributed_environmentto destroy the distributed environment.
If you only need to use the distributed environment without model parallelism, you can skip the model parallel initialization and destruction steps.
Classes¶
fastvideo.distributed.parallel_state.GroupCoordinator
¶
GroupCoordinator(group_ranks: list[list[int]], local_rank: int, torch_distributed_backend: str | Backend, use_device_communicator: bool, use_message_queue_broadcaster: bool = False, group_name: str | None = None)
PyTorch ProcessGroup wrapper for a group of processes. PyTorch ProcessGroup is bound to one specific communication backend, e.g. NCCL, Gloo, MPI, etc. GroupCoordinator takes charge of all the communication operations among the processes in the group. It manages both CPU and device communication.
Source code in fastvideo/distributed/parallel_state.py
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 | |
Attributes¶
fastvideo.distributed.parallel_state.GroupCoordinator.first_rank
property
¶Return the global rank of the first process in the group
fastvideo.distributed.parallel_state.GroupCoordinator.is_first_rank
property
¶Return whether the caller is the first process in the group
fastvideo.distributed.parallel_state.GroupCoordinator.is_last_rank
property
¶Return whether the caller is the last process in the group
fastvideo.distributed.parallel_state.GroupCoordinator.last_rank
property
¶Return the global rank of the last process in the group
fastvideo.distributed.parallel_state.GroupCoordinator.next_rank
property
¶Return the global rank of the process that follows the caller
fastvideo.distributed.parallel_state.GroupCoordinator.prev_rank
property
¶Return the global rank of the process that precedes the caller
Functions¶
fastvideo.distributed.parallel_state.GroupCoordinator.all_reduce
¶User-facing all-reduce function before we actually call the all-reduce operation.
We need this because Dynamo does not support passing an arbitrary
object (self in this case) to a custom op. We need to pass the
group name as a string, and then look up the group coordinator from
the group name, dispatch the all-reduce operation to the group
coordinator.
In addition, PyTorch custom ops do not support mutation or returning a new tensor in the same op. So we always make the all-reduce operation out-of-place.
Source code in fastvideo/distributed/parallel_state.py
fastvideo.distributed.parallel_state.GroupCoordinator.barrier
¶Barrier synchronization among the group.
NOTE: don't use device_group here! barrier in NCCL is
terrible because it is internally a broadcast operation with
secretly created GPU tensors. It is easy to mess up the current
device. Use the CPU group instead.
Source code in fastvideo/distributed/parallel_state.py
fastvideo.distributed.parallel_state.GroupCoordinator.broadcast
¶broadcast(input_: Tensor, src: int = 0)
Broadcast the input tensor.
NOTE: src is the local rank of the source rank.
Source code in fastvideo/distributed/parallel_state.py
fastvideo.distributed.parallel_state.GroupCoordinator.broadcast_object
¶Broadcast the input object.
NOTE: src is the local rank of the source rank.
Source code in fastvideo/distributed/parallel_state.py
fastvideo.distributed.parallel_state.GroupCoordinator.broadcast_object_list
¶Broadcast the input object list.
NOTE: src is the local rank of the source rank.
Source code in fastvideo/distributed/parallel_state.py
fastvideo.distributed.parallel_state.GroupCoordinator.broadcast_tensor_dict
¶broadcast_tensor_dict(tensor_dict: dict[str, Tensor | Any] | None = None, src: int = 0, group: ProcessGroup | None = None, metadata_group: ProcessGroup | None = None) -> dict[str, Tensor | Any] | None
Broadcast the input tensor dictionary.
NOTE: src is the local rank of the source rank.
Source code in fastvideo/distributed/parallel_state.py
482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 | |
fastvideo.distributed.parallel_state.GroupCoordinator.gather
¶NOTE: We assume that the input tensor is on the same device across
all the ranks.
NOTE: dst is the local rank of the destination rank.
Source code in fastvideo/distributed/parallel_state.py
fastvideo.distributed.parallel_state.GroupCoordinator.recv
¶recv(size: Size, dtype: dtype, src: int | None = None) -> Tensor
Receives a tensor from the source rank.
Source code in fastvideo/distributed/parallel_state.py
fastvideo.distributed.parallel_state.GroupCoordinator.recv_object
¶Receive the input object list from the source rank.
Source code in fastvideo/distributed/parallel_state.py
fastvideo.distributed.parallel_state.GroupCoordinator.recv_tensor_dict
¶recv_tensor_dict(src: int | None = None, all_gather_group: Optional[GroupCoordinator] = None) -> dict[str, Tensor | Any] | None
Recv the input tensor dictionary.
NOTE: src is the local rank of the source rank.
Source code in fastvideo/distributed/parallel_state.py
fastvideo.distributed.parallel_state.GroupCoordinator.send
¶send(tensor: Tensor, dst: int | None = None) -> None
Sends a tensor to the destination rank in a non-blocking way
Source code in fastvideo/distributed/parallel_state.py
fastvideo.distributed.parallel_state.GroupCoordinator.send_object
¶Send the input object list to the destination rank.
Source code in fastvideo/distributed/parallel_state.py
fastvideo.distributed.parallel_state.GroupCoordinator.send_tensor_dict
¶send_tensor_dict(tensor_dict: dict[str, Tensor | Any], dst: int | None = None, all_gather_group: Optional[GroupCoordinator] = None) -> dict[str, Tensor | Any] | None
Send the input tensor dictionary.
NOTE: dst is the local rank of the source rank.
Source code in fastvideo/distributed/parallel_state.py
Functions¶
fastvideo.distributed.parallel_state.destroy_model_parallel
¶
Set the groups to none and destroy them.
Source code in fastvideo/distributed/parallel_state.py
fastvideo.distributed.parallel_state.get_local_torch_device
¶
Return the torch device for the current rank.
Source code in fastvideo/distributed/parallel_state.py
fastvideo.distributed.parallel_state.initialize_model_parallel
¶
initialize_model_parallel(tensor_model_parallel_size: int = 1, sequence_model_parallel_size: int = 1, data_parallel_size: int = 1, backend: str | None = None) -> None
Initialize model parallel groups.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
tensor_model_parallel_size
|
int
|
number of GPUs used for tensor model parallelism (used for language encoder). |
1
|
sequence_model_parallel_size
|
int
|
number of GPUs used for sequence model parallelism (used for DiT). |
1
|
Source code in fastvideo/distributed/parallel_state.py
fastvideo.distributed.parallel_state.initialize_sequence_parallel_group
¶
initialize_sequence_parallel_group(sequence_model_parallel_size: int = 1, backend: str | None = None, group_name_suffix: str = '') -> GroupCoordinator
Initialize a sequence parallel group for a specific model.
This function creates a sequence parallel group that can be used with the patch_sequence_parallel_group context manager. It allows different models to use different sequence parallelism configurations.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
sequence_model_parallel_size
|
int
|
number of GPUs used for sequence model parallelism. |
1
|
backend
|
str | None
|
communication backend to use. |
None
|
group_name_suffix
|
str
|
optional suffix to make the group name unique. |
''
|
Returns:
| Type | Description |
|---|---|
GroupCoordinator
|
A GroupCoordinator for sequence parallelism that can be used with |
GroupCoordinator
|
the patch_sequence_parallel_group context manager. |
Example usage
# Initialize sequence parallel group for model2
sp_group_model2 = initialize_sequence_parallel_group(
sequence_model_parallel_size=2,
group_name_suffix="model2"
)
# Use sequence parallelism for model2
with patch_sequence_parallel_group(sp_group_model2):
# Run model2 with sequence parallelism
output2 = model2(input2)
Source code in fastvideo/distributed/parallel_state.py
1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 | |
fastvideo.distributed.parallel_state.initialize_tensor_parallel_group
¶
initialize_tensor_parallel_group(tensor_model_parallel_size: int = 1, backend: str | None = None, group_name_suffix: str = '') -> GroupCoordinator
Initialize a tensor parallel group for a specific model.
This function creates a tensor parallel group that can be used with the patch_tensor_parallel_group context manager. It allows different models to use different tensor parallelism configurations.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
tensor_model_parallel_size
|
int
|
number of GPUs used for tensor model parallelism. |
1
|
backend
|
str | None
|
communication backend to use. |
None
|
group_name_suffix
|
str
|
optional suffix to make the group name unique. |
''
|
Returns:
| Type | Description |
|---|---|
GroupCoordinator
|
A GroupCoordinator for tensor parallelism that can be used with |
GroupCoordinator
|
the patch_tensor_parallel_group context manager. |
Example usage
# Initialize tensor parallel group for model1
tp_group_model1 = initialize_tensor_parallel_group(
tensor_model_parallel_size=4,
group_name_suffix="model1"
)
# Use tensor parallelism for model1
with patch_tensor_parallel_group(tp_group_model1):
# Run model1 with tensor parallelism
output1 = model1(input1)
Source code in fastvideo/distributed/parallel_state.py
1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 | |
fastvideo.distributed.parallel_state.is_the_same_node_as
¶
is_the_same_node_as(pg: ProcessGroup | StatelessProcessGroup, source_rank: int = 0) -> list[int]
This is a collective operation that returns if each rank is in the same node as the source rank. It tests if processes are attached to the same memory system (shared access to shared memory).
Source code in fastvideo/distributed/parallel_state.py
1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 | |
fastvideo.distributed.parallel_state.model_parallel_is_initialized
¶
model_parallel_is_initialized() -> bool
fastvideo.distributed.parallel_state.patch_tensor_parallel_group
¶
patch_tensor_parallel_group(tp_group: GroupCoordinator)
Patch the tp group temporarily until this function ends.
This method is for draft workers of speculative decoding to run draft model with different tp degree from that of target model workers.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
tp_group
|
GroupCoordinator
|
the tp group coordinator |
required |
Source code in fastvideo/distributed/parallel_state.py
fastvideo.distributed.utils
¶
Classes¶
fastvideo.distributed.utils.StatelessProcessGroup
dataclass
¶
StatelessProcessGroup(rank: int, world_size: int, store: Store, data_expiration_seconds: int = 3600, send_dst_counter: dict[int, int] = dict(), recv_src_counter: dict[int, int] = dict(), broadcast_send_counter: int = 0, broadcast_recv_src_counter: dict[int, int] = dict(), entries: deque[tuple[str, float]] = deque())
A dataclass to hold a metadata store, and the rank, world_size of the group. Only use it to communicate metadata between processes. For data-plane communication, create NCCL-related objects.
Functions¶
fastvideo.distributed.utils.StatelessProcessGroup.all_gather_obj
¶All gather an object from all ranks.
Source code in fastvideo/distributed/utils.py
fastvideo.distributed.utils.StatelessProcessGroup.barrier
¶ fastvideo.distributed.utils.StatelessProcessGroup.broadcast_obj
¶Broadcast an object from a source rank to all other ranks. It does not clean up after all ranks have received the object. Use it for limited times, e.g., for initialization.
Source code in fastvideo/distributed/utils.py
fastvideo.distributed.utils.StatelessProcessGroup.create
staticmethod
¶create(host: str, port: int, rank: int, world_size: int, data_expiration_seconds: int = 3600) -> StatelessProcessGroup
A replacement for torch.distributed.init_process_group that does not
pollute the global state.
If we have process A and process B called torch.distributed.init_process_group
to form a group, and then we want to form another group with process A, B, C,
D, it is not possible in PyTorch, because process A and process B have already
formed a group, and process C and process D cannot join that group. This
function is a workaround for this issue.
torch.distributed.init_process_group is a global call, while this function
is a stateless call. It will return a StatelessProcessGroup object that can be
used for exchanging metadata. With this function, process A and process B
can call StatelessProcessGroup.create to form a group, and then process A, B,
C, and D can call StatelessProcessGroup.create to form another group.
Source code in fastvideo/distributed/utils.py
fastvideo.distributed.utils.StatelessProcessGroup.expire_data
¶Expire data that is older than data_expiration_seconds seconds.
Source code in fastvideo/distributed/utils.py
fastvideo.distributed.utils.StatelessProcessGroup.recv_obj
¶Receive an object from a source rank.
fastvideo.distributed.utils.StatelessProcessGroup.send_obj
¶Send an object to a destination rank.
Source code in fastvideo/distributed/utils.py
Functions¶
fastvideo.distributed.utils.divide
¶
Ensure that numerator is divisible by the denominator and return the division value.
fastvideo.distributed.utils.ensure_divisibility
¶
Ensure that numerator is divisible by the denominator.
fastvideo.distributed.utils.split_tensor_along_last_dim
¶
split_tensor_along_last_dim(tensor: Tensor, num_partitions: int, contiguous_split_chunks: bool = False) -> Sequence[Tensor]
Split a tensor along its last dimension.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
tensor
|
Tensor
|
input tensor. |
required |
num_partitions
|
int
|
number of partitions to split the tensor |
required |
contiguous_split_chunks
|
bool
|
If True, make each chunk contiguous in memory. |
False
|
Returns:
| Type | Description |
|---|---|
Sequence[Tensor]
|
A list of Tensors |