Spaces:
Running
on
A100
Running
on
A100
Gong Junmin
commited on
Commit
·
bdee37a
1
Parent(s):
d85b31b
fix data permission
Browse files- Dockerfile +23 -15
- app.py +34 -2
Dockerfile
CHANGED
|
@@ -1,11 +1,11 @@
|
|
| 1 |
-
#
|
|
|
|
| 2 |
FROM python:3.11-slim
|
| 3 |
|
| 4 |
# Set environment variables
|
| 5 |
-
ENV PYTHONDONTWRITEBYTECODE=1
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
ENV GRADIO_SERVER_PORT=7860
|
| 9 |
|
| 10 |
# Install system dependencies
|
| 11 |
RUN apt-get update && apt-get install -y --no-install-recommends \
|
|
@@ -14,27 +14,35 @@ RUN apt-get update && apt-get install -y --no-install-recommends \
|
|
| 14 |
libsndfile1 \
|
| 15 |
&& rm -rf /var/lib/apt/lists/*
|
| 16 |
|
| 17 |
-
#
|
| 18 |
RUN useradd -m -u 1000 user
|
| 19 |
-
USER user
|
| 20 |
-
ENV HOME=/home/user
|
| 21 |
-
ENV PATH=/home/user/.local/bin:$PATH
|
| 22 |
|
| 23 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 24 |
WORKDIR $HOME/app
|
| 25 |
|
| 26 |
-
# Copy requirements first for better caching
|
| 27 |
COPY --chown=user:user requirements.txt .
|
| 28 |
|
| 29 |
# Copy the local nano-vllm package
|
| 30 |
-
COPY --chown=user:user acestep/third_parts/nano-vllm
|
|
|
|
|
|
|
|
|
|
| 31 |
|
| 32 |
-
# Install
|
| 33 |
-
# This includes torch and pre-built flash-attn wheel
|
| 34 |
RUN pip install --no-cache-dir --user -r requirements.txt
|
| 35 |
|
| 36 |
# Install nano-vllm with --no-deps since all dependencies are already installed
|
| 37 |
-
RUN pip install --no-cache-dir --user --no-deps
|
| 38 |
|
| 39 |
# Copy the rest of the application
|
| 40 |
COPY --chown=user:user . .
|
|
|
|
| 1 |
+
# HuggingFace Space Docker SDK
|
| 2 |
+
# Use slim Python image - HuggingFace GPU Spaces provide CUDA runtime
|
| 3 |
FROM python:3.11-slim
|
| 4 |
|
| 5 |
# Set environment variables
|
| 6 |
+
ENV PYTHONDONTWRITEBYTECODE=1 \
|
| 7 |
+
PYTHONUNBUFFERED=1 \
|
| 8 |
+
DEBIAN_FRONTEND=noninteractive
|
|
|
|
| 9 |
|
| 10 |
# Install system dependencies
|
| 11 |
RUN apt-get update && apt-get install -y --no-install-recommends \
|
|
|
|
| 14 |
libsndfile1 \
|
| 15 |
&& rm -rf /var/lib/apt/lists/*
|
| 16 |
|
| 17 |
+
# Set up a new user named "user" with user ID 1000 (HuggingFace Space requirement)
|
| 18 |
RUN useradd -m -u 1000 user
|
|
|
|
|
|
|
|
|
|
| 19 |
|
| 20 |
+
# Create /data directory with proper permissions for persistent storage
|
| 21 |
+
RUN mkdir -p /data && chown user:user /data && chmod 755 /data
|
| 22 |
+
|
| 23 |
+
# Set environment variables for user
|
| 24 |
+
ENV HOME=/home/user \
|
| 25 |
+
PATH=/home/user/.local/bin:$PATH \
|
| 26 |
+
GRADIO_SERVER_NAME=0.0.0.0 \
|
| 27 |
+
GRADIO_SERVER_PORT=7860
|
| 28 |
+
|
| 29 |
+
# Set the working directory
|
| 30 |
WORKDIR $HOME/app
|
| 31 |
|
| 32 |
+
# Copy requirements first for better Docker layer caching
|
| 33 |
COPY --chown=user:user requirements.txt .
|
| 34 |
|
| 35 |
# Copy the local nano-vllm package
|
| 36 |
+
COPY --chown=user:user acestep/third_parts/nano-vllm ./acestep/third_parts/nano-vllm
|
| 37 |
+
|
| 38 |
+
# Switch to user before installing packages
|
| 39 |
+
USER user
|
| 40 |
|
| 41 |
+
# Install dependencies from requirements.txt (includes PyTorch with CUDA from --extra-index-url)
|
|
|
|
| 42 |
RUN pip install --no-cache-dir --user -r requirements.txt
|
| 43 |
|
| 44 |
# Install nano-vllm with --no-deps since all dependencies are already installed
|
| 45 |
+
RUN pip install --no-cache-dir --user --no-deps ./acestep/third_parts/nano-vllm
|
| 46 |
|
| 47 |
# Copy the rest of the application
|
| 48 |
COPY --chown=user:user . .
|
app.py
CHANGED
|
@@ -45,11 +45,43 @@ def get_gpu_memory_gb():
|
|
| 45 |
return 0
|
| 46 |
|
| 47 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 48 |
def main():
|
| 49 |
"""Main entry point for HuggingFace Space"""
|
| 50 |
|
| 51 |
-
#
|
| 52 |
-
persistent_storage_path =
|
| 53 |
|
| 54 |
# Detect GPU memory for auto-configuration
|
| 55 |
gpu_memory_gb = get_gpu_memory_gb()
|
|
|
|
| 45 |
return 0
|
| 46 |
|
| 47 |
|
| 48 |
+
def get_persistent_storage_path():
|
| 49 |
+
"""
|
| 50 |
+
Detect and return a writable persistent storage path.
|
| 51 |
+
|
| 52 |
+
HuggingFace Space persistent storage requirements:
|
| 53 |
+
1. Must be enabled in Space settings
|
| 54 |
+
2. Path is typically /data for Docker SDK
|
| 55 |
+
3. Falls back to app directory if /data is not writable
|
| 56 |
+
"""
|
| 57 |
+
# Try HuggingFace Space persistent storage first
|
| 58 |
+
hf_data_path = "/data"
|
| 59 |
+
|
| 60 |
+
# Check if /data exists and is writable
|
| 61 |
+
if os.path.exists(hf_data_path):
|
| 62 |
+
try:
|
| 63 |
+
test_file = os.path.join(hf_data_path, ".write_test")
|
| 64 |
+
with open(test_file, 'w') as f:
|
| 65 |
+
f.write("test")
|
| 66 |
+
os.remove(test_file)
|
| 67 |
+
print(f"Using HuggingFace persistent storage: {hf_data_path}")
|
| 68 |
+
return hf_data_path
|
| 69 |
+
except (PermissionError, OSError) as e:
|
| 70 |
+
print(f"Warning: /data exists but is not writable: {e}")
|
| 71 |
+
|
| 72 |
+
# Fall back to app directory (non-persistent but works without special config)
|
| 73 |
+
fallback_path = os.path.join(current_dir, "data")
|
| 74 |
+
os.makedirs(fallback_path, exist_ok=True)
|
| 75 |
+
print(f"Using local storage (non-persistent): {fallback_path}")
|
| 76 |
+
print("Note: To enable persistent storage, configure it in HuggingFace Space settings")
|
| 77 |
+
return fallback_path
|
| 78 |
+
|
| 79 |
+
|
| 80 |
def main():
|
| 81 |
"""Main entry point for HuggingFace Space"""
|
| 82 |
|
| 83 |
+
# Get persistent storage path (auto-detect)
|
| 84 |
+
persistent_storage_path = get_persistent_storage_path()
|
| 85 |
|
| 86 |
# Detect GPU memory for auto-configuration
|
| 87 |
gpu_memory_gb = get_gpu_memory_gb()
|