Runs garbage collection. Then clears the cache of the available accelerator.
()
| 261 | |
| 262 | |
| 263 | def free_memory(): |
| 264 | """Runs garbage collection. Then clears the cache of the available accelerator.""" |
| 265 | gc.collect() |
| 266 | |
| 267 | if torch.cuda.is_available(): |
| 268 | torch.cuda.empty_cache() |
| 269 | elif torch.backends.mps.is_available(): |
| 270 | torch.mps.empty_cache() |
| 271 | elif is_torch_npu_available(): |
| 272 | torch_npu.empty_cache() |
| 273 | |
| 274 | |
| 275 | # Adapted from torch-ema https://github.com/fadel/pytorch_ema/blob/master/torch_ema/ema.py#L14 |
no test coverage detected