knoxel commited on
Commit
ef06b39
Β·
verified Β·
1 Parent(s): 622c714

fix: single-stage build, download model at runtime to avoid timeout

Browse files
Files changed (1) hide show
  1. Dockerfile +23 -27
Dockerfile CHANGED
@@ -1,48 +1,44 @@
1
- FROM python:3.11-slim AS builder
2
 
3
- # Install build dependencies
4
  RUN apt-get update && apt-get install -y \
5
- git cmake clang build-essential wget curl \
6
  && rm -rf /var/lib/apt/lists/*
7
 
8
- # Clone bitnet.cpp
9
- RUN git clone --recursive https://github.com/microsoft/BitNet.git /opt/BitNet
10
 
11
- # Install BitNet Python deps (needed for setup_env.py)
12
  RUN pip install --no-cache-dir -r /opt/BitNet/requirements.txt
13
 
14
- # Build bitnet.cpp with i2_s kernel support
15
- # setup_env.py does the cmake build and downloads the GGUF model
16
- RUN cd /opt/BitNet && python setup_env.py \
17
- --hf-repo microsoft/bitnet-b1.58-2B-4T-gguf \
18
- -q i2_s
19
-
20
- # ─── Runtime stage ───────────────────────────────────────────────────────────
21
- FROM python:3.11-slim
22
-
23
- RUN apt-get update && apt-get install -y \
24
- libgomp1 curl \
25
- && rm -rf /var/lib/apt/lists/*
26
 
27
- # Create non-root user (required by HF Spaces)
28
  RUN useradd -ms /bin/bash user
29
  WORKDIR /home/user/app
30
 
31
- # Copy built binaries and model from builder
32
- COPY --from=builder /opt/BitNet/build/bin /home/user/app/bin
33
- COPY --from=builder /opt/BitNet/models /home/user/app/models
 
34
 
35
- # Install Python app dependencies
36
  COPY requirements.txt .
37
  RUN pip install --no-cache-dir -r requirements.txt
38
 
39
  # Copy app files
40
- COPY app.py .
41
- COPY start.sh .
42
  RUN chmod +x start.sh
43
 
44
- # Fix permissions
45
- RUN chown -R user:user /home/user/app
 
46
 
47
  USER user
48
 
 
1
+ FROM python:3.11-slim
2
 
3
+ # Install build + runtime dependencies in one layer
4
  RUN apt-get update && apt-get install -y \
5
+ git cmake clang build-essential curl libgomp1 \
6
  && rm -rf /var/lib/apt/lists/*
7
 
8
+ # Clone bitnet.cpp (shallow clone for speed)
9
+ RUN git clone --depth 1 --recursive https://github.com/microsoft/BitNet.git /opt/BitNet
10
 
11
+ # Install BitNet Python deps
12
  RUN pip install --no-cache-dir -r /opt/BitNet/requirements.txt
13
 
14
+ # Build bitnet.cpp WITHOUT downloading the model (just compile the binary)
15
+ # We use cmake directly instead of setup_env.py to avoid the model download
16
+ RUN cd /opt/BitNet && \
17
+ cmake -B build -DCMAKE_BUILD_TYPE=Release \
18
+ -DGGML_BITNET_ARM_TL1=OFF \
19
+ -DGGML_BITNET_X86_TL2=OFF && \
20
+ cmake --build build --config Release -j$(nproc) --target llama-server llama-cli
 
 
 
 
 
21
 
22
+ # Create non-root user
23
  RUN useradd -ms /bin/bash user
24
  WORKDIR /home/user/app
25
 
26
+ # Copy just the binaries we need
27
+ RUN cp /opt/BitNet/build/bin/llama-server /home/user/app/ && \
28
+ cp /opt/BitNet/build/bin/llama-cli /home/user/app/ && \
29
+ rm -rf /opt/BitNet
30
 
31
+ # Install Python app deps
32
  COPY requirements.txt .
33
  RUN pip install --no-cache-dir -r requirements.txt
34
 
35
  # Copy app files
36
+ COPY app.py start.sh ./
 
37
  RUN chmod +x start.sh
38
 
39
+ # Create model directory
40
+ RUN mkdir -p /home/user/app/models && \
41
+ chown -R user:user /home/user/app
42
 
43
  USER user
44