distributed
optimus_dl.modules.model_transforms.distributed
¶
Distributed model transforms for training.
BaseDistributedTransform
¶
Bases: BaseModelTransform
Base class for distributed model transforms.
Provides common access to the collective and device information.
Source code in optimus_dl/modules/model_transforms/distributed.py
DDPTransform
¶
Bases: BaseDistributedTransform
Transform that wraps a model with Distributed Data Parallel.
DDP replicates the model on each device and synchronizes gradients during the backward pass.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
cfg
|
DDPTransformConfig
|
DDP configuration. |
required |
collective
|
Collective
|
Distributed collective. |
required |
device
|
device
|
Target compute device. |
required |
Source code in optimus_dl/modules/model_transforms/distributed.py
apply(model, **kwargs)
¶
Apply DDP wrapping to the model.
Source code in optimus_dl/modules/model_transforms/distributed.py
DDPTransformConfig
dataclass
¶
Bases: ModelTransformConfig
Configuration for Distributed Data Parallel (DDP).
Attributes:
| Name | Type | Description |
|---|
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
find_unused_parameters
|
bool
|
|
False
|
gradient_as_bucket_view
|
bool
|
|
True
|
static_graph
|
bool
|
|
False
|
Source code in optimus_dl/modules/model_transforms/distributed.py
DDPWrappedModel
¶
Bases: DistributedDataParallel, BaseModel
A wrapper for DDP that implements the BaseModel interface.
Source code in optimus_dl/modules/model_transforms/distributed.py
FullyShardTransform
¶
Bases: BaseDistributedTransform
Transform that wraps a model with FSDP2 (Fully Sharded Data Parallel).
FSDP2 shards model parameters, gradients, and optimizer states across ranks, enabling the training of models much larger than the memory of a single GPU.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
cfg
|
FullyShardTransformConfig
|
FSDP2 configuration. |
required |
collective
|
Collective
|
Distributed collective (MeshCollective required). |
required |
device
|
device
|
Target compute device. |
required |
Source code in optimus_dl/modules/model_transforms/distributed.py
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 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 | |
apply(model, **kwargs)
¶
Apply FSDP2 sharding to the model.
Source code in optimus_dl/modules/model_transforms/distributed.py
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 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 | |
FullyShardTransformConfig
dataclass
¶
Bases: ModelTransformConfig
Configuration for FSDP2 (fully_shard) transform.
Attributes:
| Name | Type | Description |
|---|
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
reshard_after_forward
|
bool | int
|
|
False
|
mixed_precision
|
MixedPrecisionConfig | None
|
|
None
|
offload
|
OffloadConfig | None
|
|
None
|
use_hybrid_sharding
|
bool
|
|
True
|
sync_grad_accum
|
bool
|
|
False
|
Source code in optimus_dl/modules/model_transforms/distributed.py
MixedPrecisionConfig
dataclass
¶
Configuration for FSDP mixed precision policy.
Attributes:
| Name | Type | Description |
|---|
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
param_dtype
|
str | None
|
|
None
|
reduce_dtype
|
str | None
|
|
None
|
output_dtype
|
str | None
|
|
None
|
cast_forward_inputs
|
bool
|
|
True
|
Source code in optimus_dl/modules/model_transforms/distributed.py
OffloadConfig
dataclass
¶
Configuration for FSDP offloading policy.
Attributes:
| Name | Type | Description |
|---|
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
cpu_offload
|
bool
|
|
False
|
pin_memory
|
bool
|
|
True
|