Spaces:
Runtime error
Runtime error
Update Dockerfile
Browse files- Dockerfile +32 -19
Dockerfile
CHANGED
|
@@ -24,7 +24,6 @@ RUN mkdir -p /app/models/sentence_transformer && \
|
|
| 24 |
ENV HF_HOME="/.cache/huggingface"
|
| 25 |
ENV TORCH_HOME="/.cache/torch"
|
| 26 |
ENV SENTENCE_TRANSFORMERS_HOME="/app/models/sentence_transformer"
|
| 27 |
-
ENV TRANSFORMERS_OFFLINE=1
|
| 28 |
|
| 29 |
# Install Python dependencies
|
| 30 |
RUN pip install --no-cache-dir \
|
|
@@ -42,27 +41,41 @@ RUN pip install --no-cache-dir \
|
|
| 42 |
accelerate>=0.26.0
|
| 43 |
|
| 44 |
# Create a script to download models
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
from
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
tokenizer.
|
| 59 |
-
|
| 60 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 61 |
|
| 62 |
# Download models during build
|
| 63 |
-
RUN python download_models.py
|
|
|
|
|
|
|
|
|
|
| 64 |
|
| 65 |
-
#
|
| 66 |
COPY main.py /app/main.py
|
| 67 |
RUN sed -i 's|"sentence-transformers/all-mpnet-base-v2"|"/app/models/sentence_transformer"|g' main.py && \
|
| 68 |
sed -i 's|"Qwen/Qwen2.5-1.5B-Instruct"|"/app/models/qwen"|g' main.py
|
|
|
|
| 24 |
ENV HF_HOME="/.cache/huggingface"
|
| 25 |
ENV TORCH_HOME="/.cache/torch"
|
| 26 |
ENV SENTENCE_TRANSFORMERS_HOME="/app/models/sentence_transformer"
|
|
|
|
| 27 |
|
| 28 |
# Install Python dependencies
|
| 29 |
RUN pip install --no-cache-dir \
|
|
|
|
| 41 |
accelerate>=0.26.0
|
| 42 |
|
| 43 |
# Create a script to download models
|
| 44 |
+
COPY <<EOF /app/download_models.py
|
| 45 |
+
import os
|
| 46 |
+
from sentence_transformers import SentenceTransformer
|
| 47 |
+
from transformers import AutoTokenizer, AutoModelForCausalLM
|
| 48 |
+
import torch
|
| 49 |
+
|
| 50 |
+
# Download and save sentence transformer model
|
| 51 |
+
print("Downloading sentence transformer model...")
|
| 52 |
+
model = SentenceTransformer("sentence-transformers/all-mpnet-base-v2")
|
| 53 |
+
model.save("/app/models/sentence_transformer")
|
| 54 |
+
print("Sentence transformer model saved successfully!")
|
| 55 |
+
|
| 56 |
+
# Download and save Qwen model and tokenizer
|
| 57 |
+
print("Downloading Qwen model and tokenizer...")
|
| 58 |
+
model_name = "Qwen/Qwen2.5-1.5B-Instruct"
|
| 59 |
+
tokenizer = AutoTokenizer.from_pretrained(model_name, trust_remote_code=True)
|
| 60 |
+
model = AutoModelForCausalLM.from_pretrained(
|
| 61 |
+
model_name,
|
| 62 |
+
trust_remote_code=True,
|
| 63 |
+
torch_dtype=torch.float16,
|
| 64 |
+
device_map=None
|
| 65 |
+
)
|
| 66 |
+
|
| 67 |
+
tokenizer.save_pretrained("/app/models/qwen")
|
| 68 |
+
model.save_pretrained("/app/models/qwen")
|
| 69 |
+
print("Qwen model and tokenizer saved successfully!")
|
| 70 |
+
EOF
|
| 71 |
|
| 72 |
# Download models during build
|
| 73 |
+
RUN python /app/download_models.py
|
| 74 |
+
|
| 75 |
+
# Only set TRANSFORMERS_OFFLINE after downloading models
|
| 76 |
+
ENV TRANSFORMERS_OFFLINE=1
|
| 77 |
|
| 78 |
+
# Copy the main.py and modify it to use local paths
|
| 79 |
COPY main.py /app/main.py
|
| 80 |
RUN sed -i 's|"sentence-transformers/all-mpnet-base-v2"|"/app/models/sentence_transformer"|g' main.py && \
|
| 81 |
sed -i 's|"Qwen/Qwen2.5-1.5B-Instruct"|"/app/models/qwen"|g' main.py
|