MCPcopy Index your code
hub / github.com/THUDM/GLM / cached_path

Function cached_path

data_utils/file_utils.py:84–111  ·  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

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

Callers 2

from_pretrainedMethod · 0.90
from_pretrainedMethod · 0.85

Calls 2

get_from_cacheFunction · 0.85
existsMethod · 0.45

Tested by

no test coverage detected