Really-Amazing commited on
Commit
42844de
·
verified ·
1 Parent(s): 71b180c

Update Dockerfile

Browse files
Files changed (1) hide show
  1. Dockerfile +36 -16
Dockerfile CHANGED
@@ -1,35 +1,55 @@
1
- FROM python:3.10-slim
 
 
 
2
 
3
- # Install Rust + build tools
4
  RUN apt-get update && apt-get install -y --no-install-recommends \
5
  build-essential curl git rustc cargo \
6
  && rm -rf /var/lib/apt/lists/*
7
 
8
- WORKDIR /app
9
-
10
- # 1. Clone rustbpe and build it
11
  RUN git clone https://github.com/karpathy/rustbpe.git \
12
  && pip install --no-cache-dir maturin \
13
- && cd rustbpe && maturin build --release --out dist \
14
- && pip install dist/*.whl
 
 
 
 
 
 
 
 
 
15
 
16
- # 2. Install requirements
 
 
 
 
17
  COPY requirements.txt .
18
  RUN pip install --no-cache-dir -r requirements.txt \
19
  && pip install --no-cache-dir torch --index-url https://download.pytorch.org/whl/cpu
20
 
21
- # 3. Copy your project files
22
  COPY . .
23
 
24
- # --- THE PRO FIX START ---
25
- # Create the specific directory the library is hunting for
26
- # and move the uploaded tokenizer.pkl into it.
27
- RUN mkdir -p /root/.cache/nanochat/tokenizer/ \
28
- && mv tokenizer.pkl /root/.cache/nanochat/tokenizer/tokenizer.pkl
29
- # --- THE PRO FIX END ---
30
 
31
- RUN pip cache purge
 
 
 
 
32
 
 
 
33
  EXPOSE 7860
34
  ENV GRADIO_SERVER_NAME="0.0.0.0"
35
 
 
1
+ # STAGE 1: The Builder (Heavy Lifting)
2
+ FROM python:3.10-slim AS builder
3
+
4
+ WORKDIR /build
5
 
6
+ # Install build dependencies
7
  RUN apt-get update && apt-get install -y --no-install-recommends \
8
  build-essential curl git rustc cargo \
9
  && rm -rf /var/lib/apt/lists/*
10
 
11
+ # Build Karpathy's rustbpe
 
 
12
  RUN git clone https://github.com/karpathy/rustbpe.git \
13
  && pip install --no-cache-dir maturin \
14
+ && cd rustbpe && maturin build --release --out dist
15
+
16
+ # STAGE 2: The Final App (Slim & Fast)
17
+ FROM python:3.10-slim
18
+
19
+ WORKDIR /app
20
+
21
+ # Install only runtime dependencies
22
+ RUN apt-get update && apt-get install -y --no-install-recommends \
23
+ libstdc++6 \
24
+ && rm -rf /var/lib/apt/lists/*
25
 
26
+ # Copy the wheel from the builder and install it
27
+ COPY --from=builder /build/rustbpe/dist/*.whl .
28
+ RUN pip install *.whl && rm *.whl
29
+
30
+ # Install requirements (Optimized for CPU/Space)
31
  COPY requirements.txt .
32
  RUN pip install --no-cache-dir -r requirements.txt \
33
  && pip install --no-cache-dir torch --index-url https://download.pytorch.org/whl/cpu
34
 
35
+ # Copy project files
36
  COPY . .
37
 
38
+ # --- THE PRO FIX (Correcting the paths) ---
39
+ # Note: Hugging Face Spaces run as user "user" (UID 1000), not root.
40
+ # We create the cache for both potential users to be safe.
41
+ RUN mkdir -p /root/.cache/nanochat/tokenizer/ && \
42
+ cp tokenizer.pkl /root/.cache/nanochat/tokenizer/tokenizer.pkl && \
43
+ cp token_bytes.pt /root/.cache/nanochat/tokenizer/token_bytes.pt
44
 
45
+ # Set permissions for the HF "user"
46
+ RUN mkdir -p /.cache/nanochat/tokenizer/ && \
47
+ chmod -R 777 /.cache && \
48
+ cp tokenizer.pkl /.cache/nanochat/tokenizer/tokenizer.pkl && \
49
+ cp token_bytes.pt /.cache/nanochat/tokenizer/token_bytes.pt
50
 
51
+ # Clean up and finish
52
+ RUN pip cache purge
53
  EXPOSE 7860
54
  ENV GRADIO_SERVER_NAME="0.0.0.0"
55