ezpz.examples.fsdpΒΆ
FSDP training example on MNIST/OpenImages/ImageNet-style datasets.
Launch with:
1 | |
Help output (python3 -m ezpz.examples.fsdp --help):
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | |
Net
ΒΆ
Bases: Module
Simple CNN classifier used in the FSDP example.
Source code in src/ezpz/examples/fsdp.py
__init__(num_classes=10)
ΒΆ
Initialize convolutional and fully connected layers.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
num_classes
|
int
|
Number of output classes for the classifier. |
10
|
Source code in src/ezpz/examples/fsdp.py
forward(x)
ΒΆ
Compute logits for input images.
Source code in src/ezpz/examples/fsdp.py
fsdp_main(args)
ΒΆ
Main training loop orchestrating data, model, and logging.
Source code in src/ezpz/examples/fsdp.py
get_data(args)
ΒΆ
Load train/test datasets according to args.dataset.
Source code in src/ezpz/examples/fsdp.py
parse_args()
ΒΆ
CLI parser for the FSDP example.
Source code in src/ezpz/examples/fsdp.py
363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 | |
prepare_model_optimizer_and_scheduler(args)
ΒΆ
Create the FSDP-wrapped model, optimizer, and LR scheduler.
Source code in src/ezpz/examples/fsdp.py
test(model, test_loader)
ΒΆ
Evaluate model on validation data and gather metrics.
Source code in src/ezpz/examples/fsdp.py
train(model, train_loader, optimizer, epoch, sampler=None)
ΒΆ
One epoch of training and loss aggregation across ranks.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
Module | DistributedDataParallel | FullyShardedDataParallel
|
Wrapped model (DDP/FSDP). |
required |
train_loader
|
DataLoader
|
Dataloader for training set. |
required |
optimizer
|
Optimizer
|
Optimizer instance. |
required |
epoch
|
int
|
Current epoch index. |
required |
sampler
|
DistributedSampler | None
|
Optional distributed sampler to set epoch. |
None
|
Returns:
| Type | Description |
|---|---|
dict
|
Dict with epoch, wall-clock duration, and averaged train loss. |