Bogdan Radchenko
commited on
Update Dockerfile
Browse files- Dockerfile +34 -3
Dockerfile
CHANGED
|
@@ -1,3 +1,31 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
RUN useradd -m -u 1000 user
|
| 2 |
USER user
|
| 3 |
ENV HOME=/home/user \
|
|
@@ -5,16 +33,19 @@ ENV HOME=/home/user \
|
|
| 5 |
|
| 6 |
WORKDIR $HOME/app
|
| 7 |
|
| 8 |
-
#
|
|
|
|
|
|
|
|
|
|
| 9 |
RUN pip install --no-cache-dir --upgrade pip
|
| 10 |
COPY --chown=user requirements.txt $HOME/app/
|
| 11 |
RUN pip install -r requirements.txt
|
| 12 |
|
| 13 |
-
#
|
| 14 |
COPY --chown=user app.py $HOME/app/
|
| 15 |
|
| 16 |
# Port
|
| 17 |
EXPOSE 7860
|
| 18 |
|
| 19 |
-
# HTTP/S
|
| 20 |
CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860"]
|
|
|
|
| 1 |
+
# Downloading model
|
| 2 |
+
FROM python:3.10-slim AS builder
|
| 3 |
+
|
| 4 |
+
WORKDIR /tmp
|
| 5 |
+
|
| 6 |
+
RUN pip install --no-cache-dir huggingface_hub[cli] hf-transfer transformers torch bitsandbytes accelerate
|
| 7 |
+
|
| 8 |
+
ENV HF_TOKEN=your_hf_token_here
|
| 9 |
+
ENV HF_HUB_ENABLE_HF_TRANSFER=1
|
| 10 |
+
|
| 11 |
+
# Downloading model in cache
|
| 12 |
+
RUN python -c "
|
| 13 |
+
import os
|
| 14 |
+
from huggingface_hub import login
|
| 15 |
+
login(os.getenv('HF_TOKEN'))
|
| 16 |
+
from transformers import AutoTokenizer, AutoModelForCausalLM, BitsAndBytesConfig
|
| 17 |
+
import torch
|
| 18 |
+
bnb_config = BitsAndBytesConfig(load_in_4bit=True, bnb_4bit_use_double_quant=True, bnb_4bit_quant_type='nf4', bnb_4bit_compute_dtype=torch.bfloat16)
|
| 19 |
+
model_name = 'google/gemma-3-270m'
|
| 20 |
+
tokenizer = AutoTokenizer.from_pretrained(model_name, trust_remote_code=True)
|
| 21 |
+
model = AutoModelForCausalLM.from_pretrained(model_name, quantization_config=bnb_config, device_map='cpu', trust_remote_code=True, torch_dtype=torch.bfloat16)
|
| 22 |
+
print('Model cached!')
|
| 23 |
+
"
|
| 24 |
+
|
| 25 |
+
# Runtime
|
| 26 |
+
FROM python:3.10-slim
|
| 27 |
+
|
| 28 |
+
# Creating user 1000
|
| 29 |
RUN useradd -m -u 1000 user
|
| 30 |
USER user
|
| 31 |
ENV HOME=/home/user \
|
|
|
|
| 33 |
|
| 34 |
WORKDIR $HOME/app
|
| 35 |
|
| 36 |
+
# Cache copy
|
| 37 |
+
COPY --from=builder --chown=user /root/.cache/huggingface $HOME/.cache/huggingface
|
| 38 |
+
|
| 39 |
+
# installing requirements
|
| 40 |
RUN pip install --no-cache-dir --upgrade pip
|
| 41 |
COPY --chown=user requirements.txt $HOME/app/
|
| 42 |
RUN pip install -r requirements.txt
|
| 43 |
|
| 44 |
+
# Code copy
|
| 45 |
COPY --chown=user app.py $HOME/app/
|
| 46 |
|
| 47 |
# Port
|
| 48 |
EXPOSE 7860
|
| 49 |
|
| 50 |
+
# HTTP/S server launching
|
| 51 |
CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860"]
|