PhoGPT4BChat / app /model_loader.py
VietCat's picture
update prompt
ef13889
raw
history blame contribute delete
952 Bytes
from llama_cpp import Llama
import logging
model = None
def load_model(model_path: str):
global model
if model is not None:
return model
logging.info(f"📦 Tìm thấy mô hình: {model_path}")
model = Llama(
model_path=model_path,
n_ctx=1024, # giảm từ 2048 xuống 1024 → tăng tốc (đủ dùng cho câu hỏi ngắn)
n_batch=64, # bắt buộc ≥ GGML_KQ_MASK_PAD → giảm warning + tăng hiệu suất
n_threads=4, # HFS Free thường cấp 2–4 vCPU → để 4 là hợp lý
n_threads_batch=2, # tối ưu xử lý song song cho batch nhỏ
logits_all=False, # tiết kiệm RAM nếu không cần full logits
use_mlock=False, # giảm lỗi trên host không hỗ trợ mlock
verbose=False
)
logging.info("✅ Model Loader: Đã tải mô hình thành công.")
return model