st192011 commited on
Commit
e9e0645
·
verified ·
1 Parent(s): e98b568

Update Dockerfile

Browse files
Files changed (1) hide show
  1. Dockerfile +13 -9
Dockerfile CHANGED
@@ -6,6 +6,8 @@ ENV DEBIAN_FRONTEND=noninteractive
6
  ENV PYTHONUNBUFFERED=1
7
  ENV CC=clang
8
  ENV CXX=clang++
 
 
9
  # Hugging Face Spaces port configuration
10
  ENV GRADIO_SERVER_NAME="0.0.0.0"
11
  ENV GRADIO_SERVER_PORT=7860
@@ -23,13 +25,17 @@ RUN apt-get update && apt-get install -y --no-install-recommends \
23
  # Set up working directory
24
  WORKDIR /app
25
 
26
- # Clone BitNet and checkout the verified stable June commit (404980e)
27
- # Initializing submodules *after* checkout ensures llama.cpp is pinned to June as well
28
  RUN git clone https://github.com/microsoft/BitNet.git . && \
29
  git checkout 404980eecae38affa4871c3e419eae3f44536a95 && \
30
  git submodule update --init --recursive
31
 
32
- # Install CPU-optimized PyTorch first (saves ~3GB of disk and download time)
 
 
 
 
 
33
  RUN pip install --no-cache-dir torch torchaudio --index-url https://download.pytorch.org/whl/cpu
34
 
35
  # Install BitNet requirements followed by app dependencies
@@ -39,20 +45,18 @@ RUN pip install --no-cache-dir gradio huggingface_hub "edge-tts>=7.3.1" gTTS tra
39
  # Pre-download the BitNet quantized model into the build layer
40
  RUN python3 -c "from huggingface_hub import hf_hub_download; hf_hub_download(repo_id='microsoft/bitnet-b1.58-2B-4T-gguf', filename='ggml-model-i2_s.gguf', local_dir='models/BitNet-b1.58-2B-4T')"
41
 
42
- # Pre-download Whisper model so the Space boots instantly without downloading at runtime
43
  RUN python3 -c "from transformers import pipeline; pipeline('automatic-speech-recognition', model='openai/whisper-base', device=-1)"
44
 
45
- # Compile the high-performance BitNet kernels using June's clean build logic
46
- RUN python3 setup_env.py -md models/BitNet-b1.58-2B-4T -q i2_s
47
 
48
  # Copy your local app code into the container
49
  COPY app.py .
50
 
51
- # Create HF Spaces user (UID 1000) and grant necessary permissions to /app and cache
52
  RUN useradd -m -u 1000 user && \
53
  chown -R user:user /app && \
54
- mkdir -p /home/user/.cache && \
55
- chown -R user:user /home/user/.cache && \
56
  chmod -R 777 /app /tmp
57
 
58
  # Switch to non-root user for Hugging Face Spaces compatibility
 
6
  ENV PYTHONUNBUFFERED=1
7
  ENV CC=clang
8
  ENV CXX=clang++
9
+ # Centralize Hugging Face cache inside /app for permission compatibility
10
+ ENV HF_HOME="/app/.cache"
11
  # Hugging Face Spaces port configuration
12
  ENV GRADIO_SERVER_NAME="0.0.0.0"
13
  ENV GRADIO_SERVER_PORT=7860
 
25
  # Set up working directory
26
  WORKDIR /app
27
 
28
+ # Clone BitNet, checkout the stable June release, and initialize submodules
 
29
  RUN git clone https://github.com/microsoft/BitNet.git . && \
30
  git checkout 404980eecae38affa4871c3e419eae3f44536a95 && \
31
  git submodule update --init --recursive
32
 
33
+ # Patch the known Clang const-correctness compiler bug in June's src/ggml-bitnet-mad.cpp
34
+ RUN if [ -f src/ggml-bitnet-mad.cpp ]; then \
35
+ sed -i 's/int8_t[[:space:]]*\*[[:space:]]*y_col[[:space:]]*=[[:space:]]*y/const int8_t * y_col = y/g' src/ggml-bitnet-mad.cpp; \
36
+ fi
37
+
38
+ # Install CPU-optimized PyTorch first (saves ~3GB of disk and build time)
39
  RUN pip install --no-cache-dir torch torchaudio --index-url https://download.pytorch.org/whl/cpu
40
 
41
  # Install BitNet requirements followed by app dependencies
 
45
  # Pre-download the BitNet quantized model into the build layer
46
  RUN python3 -c "from huggingface_hub import hf_hub_download; hf_hub_download(repo_id='microsoft/bitnet-b1.58-2B-4T-gguf', filename='ggml-model-i2_s.gguf', local_dir='models/BitNet-b1.58-2B-4T')"
47
 
48
+ # Pre-download Whisper model into /app/.cache so it boots instantly
49
  RUN python3 -c "from transformers import pipeline; pipeline('automatic-speech-recognition', model='openai/whisper-base', device=-1)"
50
 
51
+ # Compile the high-performance BitNet kernels
52
+ RUN python3 setup_env.py -md models/BitNet-b1.58-2B-4T -q i2_s || test -f build/bin/llama-cli
53
 
54
  # Copy your local app code into the container
55
  COPY app.py .
56
 
57
+ # Create HF Spaces user (UID 1000) and grant necessary permissions to /app and /tmp
58
  RUN useradd -m -u 1000 user && \
59
  chown -R user:user /app && \
 
 
60
  chmod -R 777 /app /tmp
61
 
62
  # Switch to non-root user for Hugging Face Spaces compatibility