Skip to content

Commit 1584e61

Browse files
committed
feat: log some basic cuda memory stats
1 parent 88869a4 commit 1584e61

1 file changed

Lines changed: 54 additions & 0 deletions

File tree

dmlcloud/core/callbacks/cuda.py

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,60 @@ def pre_run(self, pipe):
6969
if pipe.run_dir and is_root():
7070
self._save(pipe.run_dir / 'diagnostics' / 'cuda_devices.json', all_infos)
7171

72+
def post_step(self, stage):
73+
if is_root():
74+
stats = torch.cuda.memory_stats(stage.device)
75+
stage.log(
76+
'misc/cuda/allocated_bytes_peak',
77+
stats['allocated_bytes.all.peak'],
78+
prefixed=False,
79+
synchronize=False,
80+
reduction='max',
81+
)
82+
stage.log(
83+
'misc/cuda/reserved_bytes_peak',
84+
stats['reserved_bytes.all.peak'],
85+
prefixed=False,
86+
synchronize=False,
87+
reduction='max',
88+
)
89+
stage.log(
90+
'misc/cuda/active_bytes_peak',
91+
stats['active_bytes.all.peak'],
92+
prefixed=False,
93+
synchronize=False,
94+
reduction='max',
95+
)
96+
stage.log(
97+
'misc/cuda/requested_bytes_peak',
98+
stats['requested_bytes.all.peak'],
99+
prefixed=False,
100+
synchronize=False,
101+
reduction='max',
102+
)
103+
stage.log(
104+
'misc/cuda/num_alloc_retries',
105+
stats['num_alloc_retries'],
106+
prefixed=False,
107+
synchronize=False,
108+
reduction='max',
109+
)
110+
stage.log(
111+
'misc/cuda/num_device_alloc',
112+
stats['num_device_alloc'],
113+
prefixed=False,
114+
synchronize=False,
115+
reduction='max',
116+
)
117+
stage.log(
118+
'misc/cuda/num_device_free',
119+
stats['num_device_free'],
120+
prefixed=False,
121+
synchronize=False,
122+
reduction='max',
123+
)
124+
torch.cuda.reset_peak_memory_stats(stage.device)
125+
72126
def _save(self, path, all_infos):
73127
with open(path, 'w') as f:
74128
dct = {f'rank_{i}': info for i, info in enumerate(all_infos)}

0 commit comments

Comments
 (0)