ezpz.utilsΒΆ
- See ezpz/
utils
ezpz/utils/init.py
DistributedPdb
ΒΆ
Bases: Pdb
Supports using PDB from inside a multiprocessing child process.
Usage: DistributedPdb().set_trace()
Source code in src/ezpz/utils/__init__.py
DummyTqdmFile
ΒΆ
Dummy file-like wrapper that forwards writes to tqdm.
Source code in src/ezpz/utils/__init__.py
ForkedPdb
ΒΆ
Bases: Pdb
PDB subclass for debugging multi-processed code.
Source code in src/ezpz/utils/__init__.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/__init__.py
format_pair(k, v, precision=6)
ΒΆ
Format a key-value pair (supports nested dict/list/tuple/set).
Nested dicts become dotted keys: key.subkey=value Sequences become indexed keys: key[0]=value
Returns a newline-joined string if multiple leaf pairs are produced.
Source code in src/ezpz/utils/__init__.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/__init__.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/__init__.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/__init__.py
851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 | |
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/__init__.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/__init__.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 |
dict[str, bool]
|
Deepspeed fp16 config. |
Source code in src/ezpz/utils/__init__.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/__init__.py
get_timestamp(fstr=None)
ΒΆ
Get formatted timestamp.
Returns the current date and time as a formatted string. By default, returns a timestamp in the format 'YYYY-MM-DD-HHMMSS'. A custom format string can be provided to change the output format.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
fstr
|
str
|
Format string for strftime. If None, uses default format '%Y-%m-%d-%H%M%S'. Defaults to None. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
Formatted timestamp string. |
Examples:
Source code in src/ezpz/utils/__init__.py
grab_tensor(x, force=False)
ΒΆ
Convert various tensor/array-like objects to numpy arrays.
This function converts different types of array-like objects (tensors, lists, etc.) to numpy arrays for consistent handling. Supports PyTorch tensors, numpy arrays, and nested lists.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
Any
|
The object to convert to a numpy array. Can be None, scalar values, lists, numpy arrays, or PyTorch tensors. |
required |
force
|
bool
|
Force conversion even if it requires copying data. Defaults to False. |
False
|
Returns:
| Type | Description |
|---|---|
Union[ndarray, ScalarLike, None]
|
Union[np.ndarray, ScalarLike, None]: Numpy array representation of the input, or the original scalar value, or None if input was None. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If unable to convert a list to array. |
Examples:
Source code in src/ezpz/utils/__init__.py
model_summary(model, verbose=False, depth=1, input_size=None)
ΒΆ
Print a summary of the model using torchinfo.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
Any
|
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/__init__.py
summarize_dict(d, precision=6, keys_to_skip=None)
ΒΆ
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/__init__.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/__init__.py
984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 | |
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/__init__.py
1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 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 | |
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.