hypeconqueror1 commited on
Commit
68668af
·
verified ·
1 Parent(s): f2d0061

Create LoadLLM.py

Browse files
Files changed (1) hide show
  1. LoadLLM.py +24 -0
LoadLLM.py ADDED
@@ -0,0 +1,24 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from langchain_community.llms import LlamaCpp
2
+ from langchain.callbacks.manager import CallbackManager
3
+ from langchain.callbacks.streaming_stdout import StreamingStdOutCallbackHandler
4
+
5
+ model_path = 'llama-2-7b-chat.Q5_K_M.gguf'
6
+
7
+
8
+ class Loadllm:
9
+ @staticmethod
10
+ def load_llm():
11
+ callback_manager = CallbackManager([StreamingStdOutCallbackHandler()])
12
+ # Prepare the LLM
13
+
14
+ llm = LlamaCpp(
15
+ model_path=model_path,
16
+ n_gpu_layers=40,
17
+ n_batch=512,
18
+ n_ctx=2048,
19
+ f16_kv=True, # MUST set to True, otherwise you will run into problem after a couple of calls
20
+ callback_manager=callback_manager,
21
+ verbose=True,
22
+ )
23
+
24
+ return llm