Skip to content

Commit 3be3cdb

Browse files
Merge branch 'fix/macos-tokenizer-cache-download' into fix/float128-platform-crash-and-fstring-error-msg
2 parents 7c369a6 + 57cabe0 commit 3be3cdb

1 file changed

Lines changed: 15 additions & 3 deletions

File tree

gemma/gm/utils/_file_cache.py

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,24 @@ def maybe_get_from_cache(
2828
remote_file_path: epath.PathLike,
2929
cache_subdir: str,
3030
) -> epath.Path:
31-
"""Returns the cached file if exists, otherwise returns the remote file path."""
32-
filename = epath.Path(remote_file_path).name
31+
"""Returns the cached file if exists, otherwise downloads it and returns local path."""
32+
remote_path_str = str(remote_file_path)
33+
filename = epath.Path(remote_path_str).name
3334

34-
cache_filepath = _get_cache_dir() / cache_subdir / filename
35+
cache_dir = _get_cache_dir() / cache_subdir
36+
cache_filepath = cache_dir / filename
3537
if cache_filepath.exists():
3638
return cache_filepath
39+
40+
if remote_path_str.startswith('gs://'):
41+
cache_dir.mkdir(parents=True, exist_ok=True)
42+
http_url = remote_path_str.replace('gs://', 'https://storage.googleapis.com/')
43+
print(f"Downloading {filename} to {cache_filepath}...")
44+
45+
import urllib.request
46+
urllib.request.urlretrieve(http_url, str(cache_filepath))
47+
return cache_filepath
48+
3749
return epath.Path(remote_file_path)
3850

3951

0 commit comments

Comments
 (0)