-
-
Notifications
You must be signed in to change notification settings - Fork 11
/
bootstrap_models.py
executable file
·58 lines (44 loc) · 1.53 KB
/
bootstrap_models.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
import sys
import os
import subprocess
DEFAULT_EMBEDDINGS_MODEL ="sentence-transformers/all-MiniLM-L6-v2"
DEFAULT_MODEL = "openlm-research/open_llama_3b"
MODEL_DIR = "./models"
def _download_if_not_exists(model):
models_dir = os.path.join(MODEL_DIR, model)
if os.path.exists(models_dir):
print(f"Directory {models_dir} already exists! Skpping download!")
else:
print(f"Downloading model {model} to {models_dir}")
print("Please note that if model is large this may take a while.")
process = subprocess.run(["python3", "download-model.py", model, "--output", MODEL_DIR], capture_output=True)
process.check_returncode()
def main(model, embeddings_model):
print(f"""Your choices:
MODEL: {model}
EMBEDDINGS MODEL: {embeddings_model}
""")
try:
os.mkdir(MODEL_DIR)
except FileExistsError:
pass
_download_if_not_exists(embeddings_model)
_download_if_not_exists(model)
print("Success!")
if __name__ == "__main__":
model = None
embeddings = None
if len(sys.argv) > 2:
embeddings = sys.argv[2]
if len(sys.argv) > 1:
model = sys.argv[1]
if len(sys.argv) == 1:
print(
"NOTE: You can change the default downloaded model by passing an additional argument:"
+ f"{sys.argv[0]} [hugging-face-llm-model-name] [hugging-face-embeddings-model-name]"
)
if not embeddings:
embeddings = DEFAULT_EMBEDDINGS_MODEL
if not model:
model = DEFAULT_MODEL
main(model, embeddings)