boryasbora commited on
Commit
bad6dd5
·
verified ·
1 Parent(s): 182f087

Create setup.py

Browse files
Files changed (1) hide show
  1. setup.py +41 -0
setup.py ADDED
@@ -0,0 +1,41 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ from pathlib import Path
3
+ from urllib.request import urlretrieve
4
+
5
+ HOME_DIR = Path.home()
6
+ APP_CACHE = HOME_DIR / "olmo_demo"
7
+
8
+ OLMO_MODEL_FILE = os.environ.get("OLMO_MODEL_FILE", "OLMo-7B-Instruct-Q4_K_M.gguf")
9
+ OLMO_MODEL = APP_CACHE / OLMO_MODEL_FILE
10
+
11
+ def download_olmo_model(model_file: str | None = None, force=False) -> Path:
12
+ """Download the OLMO model from the Hugging Face model hub.
13
+ Parameters
14
+ ----------
15
+ model_file : str | None, optional
16
+ The name of the model file to download, by default None
17
+ force : bool, optional
18
+ Whether to force the download even if the file already exists, by default False
19
+ Returns
20
+ -------
21
+ pathlib.Path
22
+ The path to the downloaded model file
23
+ """
24
+ if not OLMO_MODEL.exists() or force:
25
+ if model_file is None:
26
+ model_file = OLMO_MODEL_FILE
27
+ olmo_model = OLMO_MODEL
28
+ else:
29
+ olmo_model = APP_CACHE / model_file
30
+ olmo_model_url = f"https://huggingface.co/ssec-uw/OLMo-7B-Instruct-GGUF/resolve/main/{model_file}"
31
+ print(f"Downloading model from {olmo_model_url} to {olmo_model}")
32
+ urlretrieve(olmo_model_url, olmo_model)
33
+ print("Download complete!")
34
+ return olmo_model
35
+ else:
36
+ print(f"Model already exists at {OLMO_MODEL}")
37
+ return OLMO_MODEL
38
+
39
+ if __name__ == "__main__":
40
+ APP_CACHE.mkdir(parents=True, exist_ok=True)
41
+ download_olmo_model()