Free GPU memory.
(self)
| 415 | # ---- cleanup ---------------------------------------------------------- |
| 416 | |
| 417 | def unload(self) -> None: |
| 418 | """Free GPU memory.""" |
| 419 | if self._model is not None: |
| 420 | del self._model |
| 421 | self._model = None |
| 422 | if self._tokenizer is not None: |
| 423 | del self._tokenizer |
| 424 | self._tokenizer = None |
| 425 | self._loaded = False |
| 426 | |
| 427 | # Try to free CUDA cache |
| 428 | try: |
| 429 | import torch |
| 430 | |
| 431 | if torch.cuda.is_available(): |
| 432 | torch.cuda.empty_cache() |
| 433 | except ImportError: |
| 434 | pass |
| 435 | |
| 436 | logger.info("RAM: model unloaded") |