Empties the cache of the available torch device. This function checks for the availability of different torch devices (XPU, MLU, NPU, CUDA) and empties the cache of the first available device it finds. If none of the specific devices are available, it defaults to emptying the CUDA cach
()
| 1191 | |
| 1192 | |
| 1193 | def empty_cache() -> None: |
| 1194 | """Empties the cache of the available torch device. |
| 1195 | |
| 1196 | This function checks for the availability of different torch devices (XPU, MLU, NPU, CUDA) and empties the cache of |
| 1197 | the first available device it finds. |
| 1198 | |
| 1199 | If none of the specific devices are available, it defaults to emptying the CUDA cache. |
| 1200 | """ |
| 1201 | if is_torch_xpu_available(): |
| 1202 | torch.xpu.empty_cache() |
| 1203 | elif is_torch_mlu_available(): |
| 1204 | torch.mlu.empty_cache() |
| 1205 | elif is_torch_npu_available(): |
| 1206 | torch.npu.empty_cache() |
| 1207 | else: |
| 1208 | torch.cuda.empty_cache() |
| 1209 | |
| 1210 | |
| 1211 | def decode_and_strip_padding(inputs: torch.Tensor, tokenizer: PreTrainedTokenizerBase) -> list[str]: |
no outgoing calls
no test coverage detected