Skip to content

Commit 7051c5f

Browse files
authored
Remove deprecated get_cached_models (#35809)
* Remove deprecated get_cached_models * imports
1 parent 97fbaf0 commit 7051c5f

File tree

3 files changed

+1
-43
lines changed

3 files changed

+1
-43
lines changed

src/transformers/file_utils.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,6 @@
7171
copy_func,
7272
default_cache_path,
7373
define_sagemaker_information,
74-
get_cached_models,
7574
get_file_from_repo,
7675
get_torch_version,
7776
has_file,

src/transformers/utils/__init__.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,6 @@
9191
define_sagemaker_information,
9292
download_url,
9393
extract_commit_hash,
94-
get_cached_models,
9594
get_file_from_repo,
9695
has_file,
9796
http_user_agent,

src/transformers/utils/hub.py

Lines changed: 1 addition & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
import warnings
2626
from concurrent import futures
2727
from pathlib import Path
28-
from typing import Dict, List, Optional, Tuple, Union
28+
from typing import Dict, List, Optional, Union
2929
from urllib.parse import urlparse
3030
from uuid import uuid4
3131

@@ -60,7 +60,6 @@
6060
hf_raise_for_status,
6161
send_telemetry,
6262
)
63-
from huggingface_hub.utils._deprecation import _deprecate_method
6463
from requests.exceptions import HTTPError
6564

6665
from . import __version__, logging
@@ -165,45 +164,6 @@ def is_remote_url(url_or_filename):
165164
return parsed.scheme in ("http", "https")
166165

167166

168-
# TODO: remove this once fully deprecated
169-
# TODO? remove from './examples/research_projects/lxmert/utils.py' as well
170-
# TODO? remove from './examples/research_projects/visual_bert/utils.py' as well
171-
@_deprecate_method(version="4.39.0", message="This method is outdated and does not support the new cache system.")
172-
def get_cached_models(cache_dir: Union[str, Path] = None) -> List[Tuple]:
173-
"""
174-
Returns a list of tuples representing model binaries that are cached locally. Each tuple has shape `(model_url,
175-
etag, size_MB)`. Filenames in `cache_dir` are use to get the metadata for each model, only urls ending with *.bin*
176-
are added.
177-
178-
Args:
179-
cache_dir (`Union[str, Path]`, *optional*):
180-
The cache directory to search for models within. Will default to the transformers cache if unset.
181-
182-
Returns:
183-
List[Tuple]: List of tuples each with shape `(model_url, etag, size_MB)`
184-
"""
185-
if cache_dir is None:
186-
cache_dir = TRANSFORMERS_CACHE
187-
elif isinstance(cache_dir, Path):
188-
cache_dir = str(cache_dir)
189-
if not os.path.isdir(cache_dir):
190-
return []
191-
192-
cached_models = []
193-
for file in os.listdir(cache_dir):
194-
if file.endswith(".json"):
195-
meta_path = os.path.join(cache_dir, file)
196-
with open(meta_path, encoding="utf-8") as meta_file:
197-
metadata = json.load(meta_file)
198-
url = metadata["url"]
199-
etag = metadata["etag"]
200-
if url.endswith(".bin"):
201-
size_MB = os.path.getsize(meta_path.strip(".json")) / 1e6
202-
cached_models.append((url, etag, size_MB))
203-
204-
return cached_models
205-
206-
207167
def define_sagemaker_information():
208168
try:
209169
instance_data = requests.get(os.environ["ECS_CONTAINER_METADATA_URI"]).json()

0 commit comments

Comments
 (0)