MCPcopy
hub / github.com/deepspeedai/DeepSpeedExamples / filename_to_url

Function filename_to_url

BingBertSquad/turing/file_utils.py:57–80  ·  view source on GitHub ↗

Return the url and etag (which may be ``None``) stored for `filename`. Raise ``EnvironmentError`` if `filename` or its stored metadata do not exist.

(filename, cache_dir=None)

Source from the content-addressed store, hash-verified

55
56
57def filename_to_url(filename, cache_dir=None):
58 """
59 Return the url and etag (which may be ``None``) stored for `filename`.
60 Raise ``EnvironmentError`` if `filename` or its stored metadata do not exist.
61 """
62 if cache_dir is None:
63 cache_dir = PYTORCH_PRETRAINED_BERT_CACHE
64 if sys.version_info[0] == 3 and isinstance(cache_dir, Path):
65 cache_dir = str(cache_dir)
66
67 cache_path = os.path.join(cache_dir, filename)
68 if not os.path.exists(cache_path):
69 raise EnvironmentError("file {} not found".format(cache_path))
70
71 meta_path = cache_path + '.json'
72 if not os.path.exists(meta_path):
73 raise EnvironmentError("file {} not found".format(meta_path))
74
75 with open(meta_path, encoding="utf-8") as meta_file:
76 metadata = json.load(meta_file)
77 url = metadata['url']
78 etag = metadata['etag']
79
80 return url, etag
81
82
83def cached_path(url_or_filename, cache_dir=None):

Callers

nothing calls this directly

Calls 2

existsMethod · 0.45
loadMethod · 0.45

Tested by

no test coverage detected