nulltron commited on
Commit
72082f2
·
verified ·
1 Parent(s): e7480b6

Create model_loader.py

Browse files
Files changed (1) hide show
  1. model_loader.py +27 -0
model_loader.py ADDED
@@ -0,0 +1,27 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ from huggingface_hub import hf_hub_download
3
+ from llama_cpp import Llama
4
+
5
+ # Quantized GGUF Model tracking paths
6
+ REPO_ID = "Qwen/Qwen2.5-7B-Instruct-GGUF"
7
+ MODEL_FILENAME = "qwen2.5-7b-instruct-q4_k_m.gguf"
8
+
9
+ print("[SYSTEM] Fetching quantized model files from HuggingFace Hub cluster...")
10
+ model_path = hf_hub_download(repo_id=REPO_ID, filename=MODEL_FILENAME)
11
+ print(f"[SYSTEM] Model secured safely at: {model_path}")
12
+
13
+ def get_local_llm_instance():
14
+ """
15
+ Initializes LlamaCpp instance allocated to optimal CPU thread counts.
16
+ Context size restricted to 2048 to drastically speed up processing on 15GB RAM.
17
+ """
18
+ print("[SYSTEM] Loading weights inside internal RAM parameters...")
19
+ llm = Llama(
20
+ model_path=model_path,
21
+ n_ctx=2048, # Optimized context tracking limit
22
+ n_threads=4, # Standard core optimizations for HuggingFace Free Tier
23
+ n_batch=512, # Batch sequence calculation limit
24
+ verbose=False
25
+ )
26
+ print("[SYSTEM] Model weights successfully attached!")
27
+ return llm