st192011 commited on
Commit
a7a2a4c
·
verified ·
1 Parent(s): 0b3994a

Update Dockerfile

Browse files
Files changed (1) hide show
  1. Dockerfile +32 -16
Dockerfile CHANGED
@@ -1,16 +1,18 @@
1
  # Use an official Python runtime as a parent image
2
  FROM python:3.12-slim
3
 
4
- # Prevent interactive prompts during installation
5
  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
12
 
13
- # Install system dependencies needed to compile BitNet AND process audio (ffmpeg)
 
14
  RUN apt-get update && apt-get install -y --no-install-recommends \
15
  cmake \
16
  clang \
@@ -20,46 +22,60 @@ RUN apt-get update && apt-get install -y --no-install-recommends \
20
  curl \
21
  && rm -rf /var/lib/apt/lists/*
22
 
23
- # Set up working directory
24
  WORKDIR /app
25
 
26
- # Clone BitNet and checkout the rock-solid June commit (404980e)
27
- # Then initialize submodules at that exact point in time
 
 
 
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
 
36
  RUN pip install --no-cache-dir -r requirements.txt
37
  RUN pip install --no-cache-dir gradio huggingface_hub "edge-tts>=7.3.1" gTTS transformers openai-whisper
38
 
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
59
  USER user
60
 
61
- # Expose standard Hugging Face port
62
  EXPOSE 7860
63
 
64
- # Run the Gradio interface
65
  CMD ["python3", "app.py"]
 
1
  # Use an official Python runtime as a parent image
2
  FROM python:3.12-slim
3
 
4
+ # Prevent interactive prompts during installation and buffer Python output
5
  ENV DEBIAN_FRONTEND=noninteractive
6
  ENV PYTHONUNBUFFERED=1
7
+
8
+ # Set environment variables for clang compilation and Gradio server
9
  ENV CC=clang
10
  ENV CXX=clang++
 
11
  ENV GRADIO_SERVER_NAME="0.0.0.0"
12
  ENV GRADIO_SERVER_PORT=7860
13
 
14
+ # Install system dependencies needed to compile BitNet, process audio (ffmpeg),
15
+ # and for downloading (curl)
16
  RUN apt-get update && apt-get install -y --no-install-recommends \
17
  cmake \
18
  clang \
 
22
  curl \
23
  && rm -rf /var/lib/apt/lists/*
24
 
25
+ # Set up working directory inside the container
26
  WORKDIR /app
27
 
28
+ # Clone the Microsoft BitNet repository
29
+ # IMPORTANT: Checking out a specific, known-stable commit from June 2024 (404980e)
30
+ # This commit is known to work with the i2_s quantization without kernel regressions
31
+ # that caused abnormal output (e.g., token repetition, freezing).
32
+ # Then, initialize and update submodules at this specific state.
33
  RUN git clone https://github.com/microsoft/BitNet.git . && \
34
  git checkout 404980eecae38affa4871c3e419eae3f44536a95 && \
35
  git submodule update --init --recursive
36
 
37
+ # Install CPU-optimized PyTorch first
38
+ # This saves significant disk space (~3GB) and download time compared to CUDA versions,
39
+ # as BitNet runs purely on the CPU.
40
  RUN pip install --no-cache-dir torch torchaudio --index-url https://download.pytorch.org/whl/cpu
41
 
42
+ # Install BitNet's Python requirements followed by your application's specific dependencies.
43
+ # "edge-tts>=7.3.1" is specified to prevent HTTP 403 errors with Microsoft's TTS API.
44
  RUN pip install --no-cache-dir -r requirements.txt
45
  RUN pip install --no-cache-dir gradio huggingface_hub "edge-tts>=7.3.1" gTTS transformers openai-whisper
46
 
47
+ # Pre-download the BitNet quantized model into the build layer.
48
+ # This ensures the model is available immediately when the container starts.
49
  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')"
50
 
51
+ # Pre-download the Whisper ASR model.
52
+ # This prevents a significant delay (1-2 minutes) at runtime while Whisper downloads,
53
+ # making your Hugging Face Space boot instantly.
54
  RUN python3 -c "from transformers import pipeline; pipeline('automatic-speech-recognition', model='openai/whisper-base', device=-1)"
55
 
56
+ # Compile the high-performance BitNet kernels.
57
+ # These kernels are specific to the i2_s quantization and are built against the
58
+ # pinned commit to ensure stability.
59
  RUN python3 setup_env.py -md models/BitNet-b1.58-2B-4T -q i2_s
60
 
61
+ # Copy your local app.py into the container's working directory.
62
  COPY app.py .
63
 
64
+ # Create a non-root user (UID 1000) for Hugging Face Spaces compatibility.
65
+ # Hugging Face Spaces runs containers as UID 1000, so setting up this user
66
+ # and granting appropriate permissions prevents PermissionError issues
67
+ # when the application tries to write temporary files or access caches.
68
  RUN useradd -m -u 1000 user && \
69
  chown -R user:user /app && \
70
  mkdir -p /home/user/.cache && \
71
  chown -R user:user /home/user/.cache && \
72
  chmod -R 777 /app /tmp
73
 
74
+ # Switch to the non-root user.
75
  USER user
76
 
77
+ # Expose the standard port Hugging Face Spaces expects Gradio applications to run on.
78
  EXPOSE 7860
79
 
80
+ # Define the command to run your Gradio application when the container starts.
81
  CMD ["python3", "app.py"]