MCPcopy Index your code
hub / github.com/huggingface/diffusers / free_memory

Function free_memory

src/diffusers/training_utils.py:405–418  ·  view source on GitHub ↗

Runs garbage collection. Then clears the cache of the available accelerator.

()

Source from the content-addressed store, hash-verified

403
404
405def free_memory():
406 """
407 Runs garbage collection. Then clears the cache of the available accelerator.
408 """
409 gc.collect()
410
411 if torch.cuda.is_available():
412 torch.cuda.empty_cache()
413 elif torch.backends.mps.is_available():
414 torch.mps.empty_cache()
415 elif is_torch_npu_available():
416 torch_npu.npu.empty_cache()
417 elif hasattr(torch, "xpu") and torch.xpu.is_available():
418 torch.xpu.empty_cache()
419
420
421@contextmanager

Callers 15

tearDownMethod · 0.90
log_validationFunction · 0.90
mainFunction · 0.90
log_validationFunction · 0.90
mainFunction · 0.90
log_validationFunction · 0.90
mainFunction · 0.90
log_validationFunction · 0.90
mainFunction · 0.90
log_validationFunction · 0.90
mainFunction · 0.90
log_validationFunction · 0.90

Calls 1

is_torch_npu_availableFunction · 0.85

Tested by 1

tearDownMethod · 0.72

Used in the wild real call sites across dependent graphs

searching dependent graphs…