Qwen3Embedding4B / app /model_loader.py
VietCat's picture
fix ValueError: Out of range float values are not JSON compliant
a03dcc1
raw
history blame contribute delete
864 Bytes
from llama_cpp import Llama
import logging
import os
model = None
def load_model(model_path: str):
global model
if model is not None:
return model
if not os.path.isfile(model_path):
raise FileNotFoundError(f"Không tìm thấy mô hình tại đường dẫn: {model_path}")
logging.info(f"📦 Đang tải mô hình từ: {model_path}")
model = Llama(
model_path=model_path,
embedding=True,
n_ctx=1024,
n_batch=16, # ✅ Giảm batch size để tránh lỗi bộ nhớ
n_threads=4,
n_threads_batch=2,
n_gpu_layers=0, # ✅ Chạy thuần CPU để tránh crash nếu không có GPU
logits_all=False,
use_mlock=False,
verbose=False
)
logging.info("✅ Model Loader: Đã tải mô hình thành công.")
return model