ivanm151 commited on
Commit
fe749bd
·
1 Parent(s): deed5a7
Files changed (4) hide show
  1. Dockerfile +5 -6
  2. models.py +9 -19
  3. weights/best.pt +3 -0
  4. weights/file +0 -0
Dockerfile CHANGED
@@ -1,5 +1,6 @@
1
  FROM python:3.11-slim
2
 
 
3
  RUN apt-get update && apt-get install -y --no-install-recommends \
4
  build-essential \
5
  libopenblas-dev \
@@ -10,20 +11,18 @@ RUN useradd -m -u 1000 user
10
  USER user
11
  ENV HOME=/home/user \
12
  PATH=/home/user/.local/bin:$PATH \
13
- HF_HOME=/tmp/hf
 
14
 
15
  WORKDIR $HOME/app
16
 
17
- # Сначала requirements для кэша слоёв
18
  COPY --chown=user requirements.txt .
19
  RUN pip install --no-cache-dir --user -r requirements.txt
20
 
21
- # Важно: компилируем llama-cpp-python с BLAS
22
- RUN CMAKE_ARGS="-DLLAMA_BLAS=ON -DLLAMA_BLAS_VENDOR=OpenBLAS" \
23
- FORCE_CMAKE=1 \
24
  pip install --no-cache-dir --user llama-cpp-python --upgrade --force-reinstall --no-cache-dir
25
 
26
- # Копируем весь проект, включая weights/
27
  COPY --chown=user . .
28
 
29
  CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860", "--workers", "1"]
 
1
  FROM python:3.11-slim
2
 
3
+ # Устанавливаем зависимости для BLAS и компиляции llama-cpp-python
4
  RUN apt-get update && apt-get install -y --no-install-recommends \
5
  build-essential \
6
  libopenblas-dev \
 
11
  USER user
12
  ENV HOME=/home/user \
13
  PATH=/home/user/.local/bin:$PATH \
14
+ HF_HOME=/tmp/hf \
15
+ LLAMA_CPP_NO_OPENMP=0
16
 
17
  WORKDIR $HOME/app
18
 
 
19
  COPY --chown=user requirements.txt .
20
  RUN pip install --no-cache-dir --user -r requirements.txt
21
 
22
+ # Важно: FORCE_CMAKE=1 для лучшей компиляции с BLAS
23
+ RUN CMAKE_ARGS="-DLLAMA_BLAS=ON -DLLAMA_BLAS_VENDOR=OpenBLAS" FORCE_CMAKE=1 \
 
24
  pip install --no-cache-dir --user llama-cpp-python --upgrade --force-reinstall --no-cache-dir
25
 
 
26
  COPY --chown=user . .
27
 
28
  CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860", "--workers", "1"]
models.py CHANGED
@@ -1,29 +1,19 @@
1
  from llama_cpp import Llama
2
- import os
3
 
4
- # Путь к файлу GGUF внутри контейнера
5
- WEIGHTS_DIR = "/home/user/app/weights"
6
- MODEL_FILE = "Qwen2.5-7B.gguf" # qwen2.5-7b-instruct-q5_k_m.gguf
7
-
8
- GGUF_PATH = os.path.join(WEIGHTS_DIR, MODEL_FILE)
9
 
10
  llm = None
11
 
12
-
13
  def load_model():
14
  global llm
15
- if not os.path.exists(GGUF_PATH):
16
- raise FileNotFoundError(f"GGUF файл не найден: {GGUF_PATH}. Проверь имя файла и наличие в weights/")
17
-
18
- print(f"Загружаем модель: {GGUF_PATH}")
19
-
20
  llm = Llama(
21
- model_path=GGUF_PATH,
22
- n_ctx=8192, # контекст — достаточно для длинных описаний
23
- n_threads=0, # 0 = использовать все доступные ядра CPU
24
- n_gpu_layers=0, # строго CPU
25
- n_batch=512,
26
- verbose=True # чтобы видеть загрузку и токены/сек в логах
27
  )
28
- print("Модель загружена успешно")
29
  return llm
 
1
  from llama_cpp import Llama
 
2
 
3
+ # Выбери подходящий квант (поменяй по вкусу)
4
+ GGUF_MODEL = "https://huggingface.co/bartowski/Qwen2.5-7B-Instruct-GGUF/resolve/main/Qwen2.5-7B-Instruct-Q5_K_M.gguf"
5
+ # Или локально: "./weights/Qwen2.5-7B-Instruct-Q5_K_M.gguf" — но в HF Spaces лучше скачивать с HF
 
 
6
 
7
  llm = None
8
 
 
9
  def load_model():
10
  global llm
 
 
 
 
 
11
  llm = Llama(
12
+ model_path=GGUF_MODEL, # или локальный путь
13
+ n_ctx=8192, # контекст — хватит для описаний + промпта
14
+ n_threads=0, # 0 = все доступные CPU-ядра
15
+ n_gpu_layers=0, # 0 = чистый CPU
16
+ n_batch=512, # батч для промпта
17
+ verbose=False
18
  )
 
19
  return llm
weights/best.pt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:abecca16bf2464d7ac0679d2ec1921779a2264d6d69b2a1ce3b2259977bad107
3
+ size 6252842
weights/file DELETED
File without changes