| 901 | |
| 902 | |
| 903 | def see_memory_usage(message, force=False): |
| 904 | if not force: |
| 905 | return |
| 906 | if dist.is_initialized() and not dist.get_rank() == 0: |
| 907 | return |
| 908 | |
| 909 | # python doesn't do real-time garbage collection so do it explicitly to get the correct RAM reports |
| 910 | gc.collect() |
| 911 | |
| 912 | # Print message except when distributed but not rank 0 |
| 913 | print(message) |
| 914 | print(f"MA {round(get_accelerator().memory_allocated() / (1024 * 1024 * 1024),2 )} GB \ |
| 915 | Max_MA {round(get_accelerator().max_memory_allocated() / (1024 * 1024 * 1024),2)} GB \ |
| 916 | CA {round(torch_memory_reserved() / (1024 * 1024 * 1024),2)} GB \ |
| 917 | Max_CA {round(torch_max_memory_reserved() / (1024 * 1024 * 1024))} GB ") |
| 918 | |
| 919 | vm_stats = psutil.virtual_memory() |
| 920 | used_GB = round(((vm_stats.total - vm_stats.available) / (1024**3)), 2) |
| 921 | print(f'CPU Virtual Memory: used = {used_GB} GB, percent = {vm_stats.percent}%') |
| 922 | |
| 923 | # get the peak memory to report correct data, so reset the counter for the next call |
| 924 | get_accelerator().reset_peak_memory_stats() |
| 925 | |
| 926 | |
| 927 | def call_to_str(base, *args, **kwargs): |