torch_clear_memory.py 187 B

1234567891011
  1. import torch
  2. import gc
  3. def torch_clear_memory():
  4. try:
  5. if torch.cuda.is_available():
  6. torch.cuda.empty_cache()
  7. except Exception:
  8. pass
  9. gc.collect()