MCPcopy Create free account
hub / github.com/OpenSparseLLMs/MoM / benchmark_memory

Function benchmark_memory

benchmarks/ops/benchmark.py:258–268  ·  view source on GitHub ↗
(fn, *inputs, desc="", verbose=True, **kwinputs)

Source from the content-addressed store, hash-verified

256
257
258def benchmark_memory(fn, *inputs, desc="", verbose=True, **kwinputs):
259 torch.cuda.empty_cache()
260 torch.cuda.reset_peak_memory_stats()
261 torch.cuda.synchronize()
262 fn(*inputs, **kwinputs)
263 torch.cuda.synchronize()
264 mem = torch.cuda.max_memory_allocated() / ((2**20) * 1000)
265 if verbose:
266 print(f"{desc} max memory: {mem}GB")
267 torch.cuda.empty_cache()
268 return mem

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected