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

Function cached_path

BingBertSquad/turing/file_utils.py:83–110  ·  view source on GitHub ↗

Given something that might be a URL (or might be a local path), determine which. If it's a URL, download the file and cache it, and return the path to the cached file. If it's already a local path, make sure the file exists and then return the path.

(url_or_filename, cache_dir=None)

Source from the content-addressed store, hash-verified

81
82
83def cached_path(url_or_filename, cache_dir=None):
84 """
85 Given something that might be a URL (or might be a local path),
86 determine which. If it's a URL, download the file and cache it, and
87 return the path to the cached file. If it's already a local path,
88 make sure the file exists and then return the path.
89 """
90 if cache_dir is None:
91 cache_dir = PYTORCH_PRETRAINED_BERT_CACHE
92 if sys.version_info[0] == 3 and isinstance(url_or_filename, Path):
93 url_or_filename = str(url_or_filename)
94 if sys.version_info[0] == 3 and isinstance(cache_dir, Path):
95 cache_dir = str(cache_dir)
96
97 parsed = urlparse(url_or_filename)
98
99 if parsed.scheme in ('http', 'https', 's3'):
100 # URL, so get it from the cache (downloading if necessary)
101 return get_from_cache(url_or_filename, cache_dir)
102 elif os.path.exists(url_or_filename):
103 # File, and it exists.
104 return url_or_filename
105 elif parsed.scheme == '':
106 # File, but it doesn't exist.
107 raise EnvironmentError("file {} not found".format(url_or_filename))
108 else:
109 # Something unknown
110 raise ValueError("unable to parse {} as a URL or as a local path".format(url_or_filename))
111
112
113def split_s3_path(url):

Callers 1

from_pretrainedMethod · 0.90

Calls 2

get_from_cacheFunction · 0.70
existsMethod · 0.45

Tested by

no test coverage detected