MCPcopy
hub / github.com/p-e-w/heretic / empty_cache

Function empty_cache

src/heretic/system.py:26–47  ·  view source on GitHub ↗

Clears the backend cache and collects garbage.

()

Source from the content-addressed store, hash-verified

24
25
26def empty_cache():
27 """Clears the backend cache and collects garbage."""
28
29 # Collecting garbage is not an idempotent operation, and to avoid OOM errors,
30 # gc.collect() has to be called both before and after emptying the backend cache.
31 # See https://github.com/p-e-w/heretic/pull/17 for details.
32 gc.collect()
33
34 if torch.cuda.is_available():
35 torch.cuda.empty_cache()
36 elif is_xpu_available():
37 torch.xpu.empty_cache()
38 elif is_mlu_available():
39 torch.mlu.empty_cache() # ty:ignore[unresolved-attribute]
40 elif is_sdaa_available():
41 torch.sdaa.empty_cache() # ty:ignore[unresolved-attribute]
42 elif is_musa_available():
43 torch.musa.empty_cache() # ty:ignore[unresolved-attribute]
44 elif torch.backends.mps.is_available():
45 torch.mps.empty_cache()
46
47 gc.collect()
48
49
50def get_nvidia_driver_version() -> str | None:

Callers 5

runFunction · 0.85
__init__Method · 0.85
reset_modelMethod · 0.85
get_residualsMethod · 0.85
get_logprobsMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected