DenCT commited on
Commit
2f28750
·
verified ·
1 Parent(s): 7e0089d

Create load_model_from_hub.py

Browse files
Files changed (1) hide show
  1. utils/load_model_from_hub.py +20 -0
utils/load_model_from_hub.py ADDED
@@ -0,0 +1,20 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from llama_cpp import Llama
2
+ from huggingface_hub import hf_hub_download
3
+
4
+
5
+ def load_model() -> Llama:
6
+ """Downlaod model from Huggingface Hub and load it."""
7
+ try:
8
+ model = Llama(
9
+ model_path=hf_hub_download(
10
+ repo_id="microsoft/Phi-3-mini-4k-instruct-gguf",
11
+ filename="Phi-3-mini-4k-instruct-q4.gguf",
12
+ ),
13
+ n_ctx=4096,
14
+ n_threads=8,
15
+ n_gpu_layers=0,
16
+ stop=["\n", " Q:"],
17
+ )
18
+ return model
19
+ except Exception as e:
20
+ raise Exception(f"Failed to load model: {e}")