ezpz.utils
¶
ezpz/utils.py
DistributedPdb
¶
Bases: Pdb
Supports using PDB from inside a multiprocessing child process.
Usage: DistributedPdb().set_trace()
Source code in src/ezpz/utils.py
breakpoint(rank=0)
¶
Set a breakpoint, but only on a single rank. All other ranks will wait for you to be done with the breakpoint before continuing.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
rank
|
int
|
Which rank to break on. Default: |
0
|
Source code in src/ezpz/utils.py
get_bf16_config_json(enabled=True)
¶
Get the deepspeed bf16 config json.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
enabled
|
bool
|
Whether to use bf16. Default: |
True
|
Returns:
Name | Type | Description |
---|---|---|
dict |
dict
|
Deepspeed bf16 config. |
Source code in src/ezpz/utils.py
get_deepspeed_adamw_optimizer_config_json(auto_config=True)
¶
Get the deepspeed adamw optimizer config json.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
auto_config
|
bool
|
Whether to use the auto config. Default: |
True
|
Returns:
Name | Type | Description |
---|---|---|
dict |
dict
|
Deepspeed adamw optimizer config. |
Source code in src/ezpz/utils.py
get_deepspeed_config_json(auto_config=True, gradient_accumulation_steps=1, gradient_clipping='auto', steps_per_print=10, train_batch_size='auto', train_micro_batch_size_per_gpu='auto', wall_clock_breakdown=False, wandb=True, bf16=True, fp16=None, flops_profiler=None, optimizer=None, scheduler=None, zero_optimization=None, stage=0, allgather_partitions=None, allgather_bucket_size=int(500000000.0), overlap_comm=None, reduce_scatter=True, reduce_bucket_size=int(500000000.0), contiguous_gradients=None, offload_param=None, offload_optimizer=None, stage3_max_live_parameters=int(1000000000.0), stage3_max_reuse_distance=int(1000000000.0), stage3_prefetch_bucket_size=int(500000000.0), stage3_param_persistence_threshold=int(1000000.0), sub_group_size=None, elastic_checkpoint=None, stage3_gather_16bit_weights_on_model_save=None, ignore_unused_parameters=None, round_robin_gradients=None, zero_hpz_partition_size=None, zero_quantized_weights=None, zero_quantized_gradients=None, log_trace_cache_warnings=None, save_config=True, output_file=None, output_dir=None)
¶
Write a deepspeed config to the output directory.
Source code in src/ezpz/utils.py
452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 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 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 |
|
get_deepspeed_warmup_decay_scheduler_config_json(auto_config=True)
¶
Get the deepspeed warmup decay scheduler config json.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
auto_config
|
bool
|
Whether to use the auto config. Default: |
True
|
Returns:
Name | Type | Description |
---|---|---|
dict |
dict
|
Deepspeed warmup decay scheduler config. |
Source code in src/ezpz/utils.py
get_deepspeed_zero_config_json(zero_config)
¶
get_flops_profiler_config_json(enabled=True, profile_step=1, module_depth=-1, top_modules=1, detailed=True)
¶
Get the deepspeed flops profiler config json.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
enabled
|
bool
|
Whether to use the flops profiler. Default: |
True
|
profile_step
|
int
|
The step to profile. Default: |
1
|
module_depth
|
int
|
The depth of the module. Default: |
-1
|
top_modules
|
int
|
The number of top modules to show. Default: |
1
|
detailed
|
bool
|
Whether to show detailed profiling. Default: |
True
|
Returns:
Name | Type | Description |
---|---|---|
dict |
dict
|
Deepspeed flops profiler config. |
Source code in src/ezpz/utils.py
get_fp16_config_json(enabled=True)
¶
Get the deepspeed fp16 config json.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
enabled
|
bool
|
Whether to use fp16. Default: |
True
|
Returns:
Name | Type | Description |
---|---|---|
dict |
Deepspeed fp16 config. |
Source code in src/ezpz/utils.py
get_max_memory_allocated(device)
¶
Get the maximum memory allocated on the specified device.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
device
|
device
|
The device to check memory allocation for. |
required |
Source code in src/ezpz/utils.py
get_timestamp(fstr=None)
¶
model_summary(model, verbose=False, depth=1, input_size=None)
¶
Print a summary of the model using torchinfo.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
model
|
The model to summarize. |
required | |
verbose
|
bool
|
Whether to print the summary. Default: |
False
|
depth
|
int
|
The depth of the summary. Default: |
1
|
input_size
|
Optional[Sequence[int]]
|
The input size for the model. Default: |
None
|
Returns:
Type | Description |
---|---|
ModelStatistics | None
|
ModelStatistics | None: The model summary if torchinfo is available, otherwise None. |
Source code in src/ezpz/utils.py
summarize_dict(d, precision=6)
¶
Summarize a dictionary into a string with formatted key-value pairs.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
d
|
dict
|
The dictionary to summarize. |
required |
precision
|
int
|
The precision for floating point values. Default: |
6
|
Returns:
Name | Type | Description |
---|---|---|
str |
str
|
A string representation of the dictionary with formatted key-value pairs. |
Source code in src/ezpz/utils.py
write_deepspeed_zero12_auto_config(zero_stage=1, output_dir=None)
¶
Write a deepspeed zero1 auto config to the output directory.
Source code in src/ezpz/utils.py
write_deepspeed_zero3_auto_config(zero_stage=3, output_dir=None)
¶
Write a deepspeed zero1 auto config to the output directory.
Source code in src/ezpz/utils.py
write_generic_deepspeed_config(gradient_accumulation_steps=1, gradient_clipping='auto', steps_per_print=10, train_batch_size='auto', train_micro_batch_size_per_gpu='auto', wall_clock_breakdown=False, wandb=None, bf16=None, fp16=None, flops_profiler=None, optimizer=None, scheduler=None, zero_optimization=None)
¶
Write a generic deepspeed config to the output directory.