|
1 |
| -import shutil |
2 |
| -import traceback |
3 |
| - |
4 | 1 | from pathlib import Path
|
5 |
| -from types import TracebackType |
6 |
| -from typing import Union, Callable, Any, Type |
| 2 | +from typing import Union |
7 | 3 |
|
8 | 4 |
|
9 | 5 | def delete_model_cache(model_dir: Union[str, Path]) -> None:
|
10 |
| - """Delete the model cache directory. |
11 |
| -
|
12 |
| - If a model was downloaded from the HuggingFace model hub, then _model_dir is the dir to snapshots, removing |
13 |
| - it won't help to release the memory, because data is in blobs directory. |
14 |
| - If a model was downloaded from GCS, then we can just remove model_dir |
15 |
| -
|
16 |
| - Args: |
17 |
| - model_dir (Union[str, Path]): The path to the model cache directory. |
18 |
| - """ |
19 |
| - |
20 |
| - def on_error( |
21 |
| - func: Callable[..., Any], |
22 |
| - path: str, |
23 |
| - exc_info: tuple[Type[BaseException], BaseException, TracebackType], |
24 |
| - ) -> None: |
25 |
| - print("Failed to remove: ", path) |
26 |
| - print("Exception: ", exc_info) |
27 |
| - traceback.print_exception(*exc_info) |
28 |
| - |
29 |
| - if isinstance(model_dir, str): |
30 |
| - model_dir = Path(model_dir) |
31 |
| - |
32 |
| - if model_dir.parent.parent.name.startswith("models--"): |
33 |
| - model_dir = model_dir.parent.parent |
34 |
| - |
35 |
| - if model_dir.exists(): |
36 |
| - # todo: PermissionDenied is raised on blobs removal in Windows, with blobs > 2GB |
37 |
| - shutil.rmtree(model_dir, onerror=on_error) |
| 6 | + # """Delete the model cache directory. |
| 7 | + |
| 8 | + # If a model was downloaded from the HuggingFace model hub, then _model_dir is the dir to snapshots, removing |
| 9 | + # it won't help to release the memory, because data is in blobs directory. |
| 10 | + # If a model was downloaded from GCS, then we can just remove model_dir |
| 11 | + |
| 12 | + # Args: |
| 13 | + # model_dir (Union[str, Path]): The path to the model cache directory. |
| 14 | + # """ |
| 15 | + |
| 16 | + # def on_error( |
| 17 | + # func: Callable[..., Any], |
| 18 | + # path: str, |
| 19 | + # exc_info: tuple[Type[BaseException], BaseException, TracebackType], |
| 20 | + # ) -> None: |
| 21 | + # print("Failed to remove: ", path) |
| 22 | + # print("Exception: ", exc_info) |
| 23 | + # traceback.print_exception(*exc_info) |
| 24 | + |
| 25 | + # if isinstance(model_dir, str): |
| 26 | + # model_dir = Path(model_dir) |
| 27 | + |
| 28 | + # if model_dir.parent.parent.name.startswith("models--"): |
| 29 | + # model_dir = model_dir.parent.parent |
| 30 | + |
| 31 | + # if model_dir.exists(): |
| 32 | + # # todo: PermissionDenied is raised on blobs removal in Windows, with blobs > 2GB |
| 33 | + # shutil.rmtree(model_dir, onerror=on_error) |
| 34 | + pass |
0 commit comments