-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
only download safetensors when available (#25)
Fixes #24 * also adds more threads when there are more files
- Loading branch information
Showing
3 changed files
with
42 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,31 @@ | ||
from typing import List | ||
|
||
def filter_pytorch_model(files: List[str]) -> List[str]: | ||
return list(filter(lambda f: not f.startswith("pytorch_model") and not f == "pytorch_model.bin.index.json", files)) | ||
|
||
def filter_tensorflow_model(files: List[str]) -> List[str]: | ||
return list(filter(lambda f: not f.startswith("tf_model") and not f == "tf_model.h5.index.json", files)) | ||
|
||
def filter_flax_model(files: List[str]) -> List[str]: | ||
return list(filter(lambda f: not f.startswith("flax_model") and not f == "flax_model.msgpack.index.json", files)) | ||
|
||
|
||
def filter_files(files: List[str]) -> List[str]: | ||
files = list(filter(lambda f: not f.startswith("coreml/"), files)) | ||
has_pytorch_model = any([f.startswith("pytorch_model") for f in files]) | ||
has_tensorflow_model = any([f.startswith("tf_model") for f in files]) | ||
has_safetensors = any([f.endswith(".safetensors") for f in files]) | ||
if has_safetensors: | ||
files = filter_pytorch_model(files) | ||
files = filter_tensorflow_model(files) | ||
files = filter_flax_model(files) | ||
return files | ||
if has_pytorch_model: | ||
# filter out safetensors | ||
files = list(filter(lambda f: not f.endswith(".safetensors"), files)) | ||
# filter out tensorflow model | ||
files = list(filter(lambda f: not f.startswith("tf_model"), files)) | ||
files = filter_tensorflow_model(files) | ||
files = filter_flax_model(files) | ||
return files | ||
if has_tensorflow_model: | ||
files = filter_flax_model(files) | ||
return files | ||
return files | ||
|