worker
¶
Classes¶
fastvideo.worker.Executor
¶
Executor(fastvideo_args: FastVideoArgs)
Bases: ABC
Source code in fastvideo/worker/executor.py
Functions¶
fastvideo.worker.Executor.collective_rpc
abstractmethod
¶
collective_rpc(method: str | Callable[..., _R], timeout: float | None = None, args: tuple = (), kwargs: dict[str, Any] | None = None) -> list[_R]
Execute an RPC call on all workers.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
method
|
str | Callable[..., _R]
|
Name of the worker method to execute, or a callable that is serialized and sent to all workers to execute. If the method is a callable, it should accept an additional
|
required |
timeout
|
float | None
|
Maximum time in seconds to wait for execution. Raises a
:exc: |
None
|
args
|
tuple
|
Positional arguments to pass to the worker method. |
()
|
kwargs
|
dict[str, Any] | None
|
Keyword arguments to pass to the worker method. |
None
|
Returns:
| Type | Description |
|---|---|
list[_R]
|
A list containing the results from each worker. |
Note
It is recommended to use this API to only pass control messages, and set up data-plane communication to pass data.
Source code in fastvideo/worker/executor.py
fastvideo.worker.Executor.merge_lora_weights
abstractmethod
¶
fastvideo.worker.Executor.set_lora_adapter
abstractmethod
¶
fastvideo.worker.Executor.shutdown
abstractmethod
¶
fastvideo.worker.Executor.unmerge_lora_weights
abstractmethod
¶
fastvideo.worker.MultiprocExecutor
¶
MultiprocExecutor(fastvideo_args: FastVideoArgs)
Bases: Executor
Source code in fastvideo/worker/executor.py
Functions¶
fastvideo.worker.MultiprocExecutor.__del__
¶
fastvideo.worker.MultiprocExecutor.__enter__
¶
fastvideo.worker.MultiprocExecutor.__exit__
¶
fastvideo.worker.MultiprocExecutor.shutdown
¶
Properly shut down the executor and its workers
Source code in fastvideo/worker/multiproc_executor.py
Functions¶
fastvideo.worker.initialize_ray_cluster
¶
initialize_ray_cluster(fastvideo_args: FastVideoArgs, ray_address: str | None = None)
Initialize the distributed cluster with Ray.
it will connect to the Ray cluster and create a placement group for the workers, which includes the specification of the resources for each distributed worker.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
parallel_config
|
The configurations for parallel execution. |
required | |
ray_address
|
str | None
|
The address of the Ray cluster. If None, uses the default Ray cluster address. |
None
|
Source code in fastvideo/worker/ray_utils.py
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 | |
Modules¶
fastvideo.worker.executor
¶
Classes¶
fastvideo.worker.executor.Executor
¶
Executor(fastvideo_args: FastVideoArgs)
Bases: ABC
Source code in fastvideo/worker/executor.py
Functions¶
fastvideo.worker.executor.Executor.collective_rpc
abstractmethod
¶collective_rpc(method: str | Callable[..., _R], timeout: float | None = None, args: tuple = (), kwargs: dict[str, Any] | None = None) -> list[_R]
Execute an RPC call on all workers.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
method
|
str | Callable[..., _R]
|
Name of the worker method to execute, or a callable that is serialized and sent to all workers to execute. If the method is a callable, it should accept an additional
|
required |
timeout
|
float | None
|
Maximum time in seconds to wait for execution. Raises a
:exc: |
None
|
args
|
tuple
|
Positional arguments to pass to the worker method. |
()
|
kwargs
|
dict[str, Any] | None
|
Keyword arguments to pass to the worker method. |
None
|
Returns:
| Type | Description |
|---|---|
list[_R]
|
A list containing the results from each worker. |
Note
It is recommended to use this API to only pass control messages, and set up data-plane communication to pass data.
Source code in fastvideo/worker/executor.py
fastvideo.worker.executor.Executor.merge_lora_weights
abstractmethod
¶ fastvideo.worker.executor.Executor.set_lora_adapter
abstractmethod
¶ fastvideo.worker.executor.Executor.shutdown
abstractmethod
¶ fastvideo.worker.executor.Executor.unmerge_lora_weights
abstractmethod
¶Functions¶
fastvideo.worker.gpu_worker
¶
Classes¶
fastvideo.worker.gpu_worker.Worker
¶
Worker(fastvideo_args: FastVideoArgs, local_rank: int, rank: int, distributed_init_method: str)
Source code in fastvideo/worker/gpu_worker.py
Functions¶
fastvideo.worker.gpu_worker.Worker.init_device
¶Initialize the device for the worker.
Source code in fastvideo/worker/gpu_worker.py
fastvideo.worker.gpu_worker.Worker.shutdown
¶Gracefully shut down the worker process
Source code in fastvideo/worker/gpu_worker.py
Functions¶
fastvideo.worker.multiproc_executor
¶
Classes¶
fastvideo.worker.multiproc_executor.MultiprocExecutor
¶
MultiprocExecutor(fastvideo_args: FastVideoArgs)
Bases: Executor
Source code in fastvideo/worker/executor.py
Functions¶
fastvideo.worker.multiproc_executor.MultiprocExecutor.__del__
¶ fastvideo.worker.multiproc_executor.MultiprocExecutor.__enter__
¶ fastvideo.worker.multiproc_executor.MultiprocExecutor.__exit__
¶ fastvideo.worker.multiproc_executor.MultiprocExecutor.shutdown
¶Properly shut down the executor and its workers
Source code in fastvideo/worker/multiproc_executor.py
fastvideo.worker.multiproc_executor.UnreadyWorkerProcHandle
dataclass
¶
UnreadyWorkerProcHandle(proc: BaseProcess, rank: int, pipe: Connection, ready_pipe: Connection)
WorkerProcess handle before READY.
fastvideo.worker.multiproc_executor.WorkerMultiprocProc
¶
WorkerMultiprocProc(fastvideo_args: FastVideoArgs, local_rank: int, rank: int, distributed_init_method: str, pipe: Connection)
Adapter that runs one Worker in busy loop.
Source code in fastvideo/worker/multiproc_executor.py
Functions¶
fastvideo.worker.multiproc_executor.WorkerMultiprocProc.worker_busy_loop
¶Main busy loop for Multiprocessing Workers
Source code in fastvideo/worker/multiproc_executor.py
fastvideo.worker.multiproc_executor.WorkerMultiprocProc.worker_main
staticmethod
¶Worker initialization and execution loops. This runs a background process
Source code in fastvideo/worker/multiproc_executor.py
Functions¶
fastvideo.worker.multiproc_executor.set_multiproc_executor_envs
¶
Set up environment variables that should be used when there are workers in a multiprocessing environment. This should be called by the parent process before worker processes are created
Source code in fastvideo/worker/multiproc_executor.py
fastvideo.worker.ray_distributed_executor
¶
Classes¶
fastvideo.worker.ray_distributed_executor.RayDistributedExecutor
¶
RayDistributedExecutor(fastvideo_args: FastVideoArgs)
fastvideo.worker.ray_distributed_executor.RayWorkerMetaData
dataclass
¶
Metadata for a Ray worker. The order of ray worker creation can be random, and we need to reset the rank after creating all workers.
Functions¶
fastvideo.worker.ray_env
¶
Functions¶
fastvideo.worker.ray_env.get_env_vars_to_copy
¶
get_env_vars_to_copy(exclude_vars: set[str] | None = None, additional_vars: set[str] | None = None, destination: str | None = None) -> set[str]
Get the environment variables to copy to downstream Ray actors.
Example use cases: - Copy environment variables from RayDistributedExecutor to Ray workers. - Copy environment variables from RayDPClient to Ray DPEngineCoreActor.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
exclude_vars
|
set[str] | None
|
A set of FastVideo defined environment variables to exclude from copying. |
None
|
additional_vars
|
set[str] | None
|
A set of additional environment variables to copy. If a variable is in both exclude_vars and additional_vars, it will be excluded. |
None
|
destination
|
str | None
|
The destination of the environment variables. |
None
|
Returns: A set of environment variables to copy.
Source code in fastvideo/worker/ray_env.py
fastvideo.worker.ray_utils
¶
Classes¶
fastvideo.worker.ray_utils.RayWorkerWrapper
¶
Bases: WorkerWrapperBase
Ray wrapper for fastvideo.worker.Worker, allowing Worker to be lazily initialized after Ray sets CUDA_VISIBLE_DEVICES.
Source code in fastvideo/worker/ray_utils.py
Functions¶
fastvideo.worker.ray_utils.assert_ray_available
¶
Raise an exception if Ray is not available.
fastvideo.worker.ray_utils.initialize_ray_cluster
¶
initialize_ray_cluster(fastvideo_args: FastVideoArgs, ray_address: str | None = None)
Initialize the distributed cluster with Ray.
it will connect to the Ray cluster and create a placement group for the workers, which includes the specification of the resources for each distributed worker.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
parallel_config
|
The configurations for parallel execution. |
required | |
ray_address
|
str | None
|
The address of the Ray cluster. If None, uses the default Ray cluster address. |
None
|
Source code in fastvideo/worker/ray_utils.py
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 | |
fastvideo.worker.ray_utils.is_in_ray_actor
¶
Check if we are in a Ray actor.
fastvideo.worker.worker_base
¶
Classes¶
fastvideo.worker.worker_base.WorkerWrapperBase
¶
WorkerWrapperBase(fastvideo_args: FastVideoArgs, rpc_rank: int = 0)
This class represents one process in an executor/engine. It is responsible
for lazily initializing the worker and handling the worker's lifecycle.
We first instantiate the WorkerWrapper, which remembers the worker module
and class name. Then, when we call update_environment_variables, and the
real initialization happens in init_worker.
Initialize the worker wrapper with the given fastvideo_args and rpc_rank. Note: rpc_rank is the rank of the worker in the executor. In most cases, it is also the rank of the worker in the distributed group. However, when multiple executors work together, they can be different. e.g. in the case of SPMD-style offline inference with TP=2, users can launch 2 engines/executors, each with only 1 worker. All workers have rpc_rank=0, but they have different ranks in the TP group.
Source code in fastvideo/worker/worker_base.py
Functions¶
fastvideo.worker.worker_base.WorkerWrapperBase.adjust_rank
¶Adjust the rpc_rank based on the given mapping. It is only used during the initialization of the executor, to adjust the rpc_rank of workers after we create all workers.
Source code in fastvideo/worker/worker_base.py
fastvideo.worker.worker_base.WorkerWrapperBase.init_worker
¶Here we inject some common logic before initializing the worker. Arguments are passed to the worker class constructor.