Skip to content

Commit

Permalink
Avoid checking for model updates
Browse files Browse the repository at this point in the history
  • Loading branch information
jncraton committed Aug 29, 2024
1 parent f6d046e commit 9857154
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 3 deletions.
6 changes: 6 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changelog

## 0.21

### Changed

- Skip checking for model updates

## 0.20 - 2024-04-25

### Changed
Expand Down
22 changes: 19 additions & 3 deletions languagemodels/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,25 @@ def initialize_tokenizer(model_type, model_name):
def initialize_model(model_type, model_name):
model_info = get_model_info(model_type)

path = snapshot_download(
model_info["path"], max_workers=1, allow_patterns=["*.bin", "*.txt", "*.json"]
)
allowed = ["*.bin", "*.txt", "*.json"]
rev = model_info.get("revision", None)

# snapshot_download checks for updates by default
# This can cause significant lag in offline usecases or high latency networks
# To avoid this penalty, we try to use the local cache first.
# If the files are not available, then we attempt a download
try:
path = snapshot_download(
model_info["path"],
max_workers=1,
allow_patterns=allowed,
revision=rev,
local_files_only=True,
)
except FileNotFoundError:
path = snapshot_download(
model_info["path"], max_workers=1, allow_patterns=allowed, revision=rev
)

if model_info["architecture"] == "encoder-only-transformer":
return ctranslate2.Encoder(
Expand Down

0 comments on commit 9857154

Please sign in to comment.