MCPcopy Create free account
hub / github.com/pytorch/tutorials / memory_hook

Function memory_hook

recipes_source/debug_mode_tutorial.py:222–226  ·  view source on GitHub ↗
(func, types, args, kwargs, result)

Source from the content-addressed store, hash-verified

220MB = 1024 * 1024.0
221
222def memory_hook(func, types, args, kwargs, result):
223 mem = torch.cuda.memory_allocated() / MB if torch.cuda.is_available() else 0.0
224 peak = torch.cuda.max_memory_allocated() / MB if torch.cuda.is_available() else 0.0
225 torch.cuda.reset_peak_memory_stats() if torch.cuda.is_available() else None
226 return {"mem": f"{mem:.3f} MB", "peak": f"{peak:.3f} MB"}
227
228with (
229 DebugMode() as dm,

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected