Skip to content

Commit 0314921

Browse files
Merge pull request #7 from MASSIVEMAGNETICS/copilot/add-weight-packaging-support
Add HF Hub integration for model weight distribution with Docker runtime download and CI upload
2 parents 21a7a5f + f76bfe0 commit 0314921

7 files changed

Lines changed: 981 additions & 0 deletions

File tree

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
name: Push Model Weights to Hugging Face
2+
3+
on:
4+
workflow_dispatch:
5+
inputs:
6+
repo_id:
7+
description: 'Hugging Face repository ID'
8+
required: true
9+
default: 'MASSIVEMAGNETICS/SongBloom-weights'
10+
type: string
11+
weights_path:
12+
description: 'Path to weights directory in repo'
13+
required: true
14+
default: 'weights_to_upload'
15+
type: string
16+
commit_message:
17+
description: 'Commit message for the upload'
18+
required: false
19+
default: 'Upload model weights from CI'
20+
type: string
21+
22+
jobs:
23+
upload-weights:
24+
runs-on: ubuntu-latest
25+
permissions:
26+
contents: read
27+
28+
steps:
29+
- name: Checkout repository
30+
uses: actions/checkout@v4
31+
32+
- name: Set up Python
33+
uses: actions/setup-python@v4
34+
with:
35+
python-version: '3.8'
36+
37+
- name: Install dependencies
38+
run: |
39+
python -m pip install --upgrade pip
40+
pip install huggingface-hub
41+
42+
- name: Verify weights directory exists
43+
run: |
44+
if [ ! -d "${{ inputs.weights_path }}" ]; then
45+
echo "❌ Error: Weights directory '${{ inputs.weights_path }}' not found"
46+
echo "Please ensure the directory exists and contains model files"
47+
exit 1
48+
fi
49+
50+
echo "✓ Weights directory found"
51+
echo "Files to upload:"
52+
find "${{ inputs.weights_path }}" -type f | head -20
53+
54+
- name: Upload weights to Hugging Face
55+
env:
56+
HUGGING_FACE_HUB_TOKEN: ${{ secrets.HUGGING_FACE_HUB_TOKEN }}
57+
run: |
58+
cd SongBloom-master
59+
python scripts/upload_weights.py \
60+
--source-dir "../${{ inputs.weights_path }}" \
61+
--repo-id "${{ inputs.repo_id }}" \
62+
--commit-message "${{ inputs.commit_message }}" \
63+
--yes
64+
65+
- name: Summary
66+
if: success()
67+
run: |
68+
echo "### ✅ Upload Successful" >> $GITHUB_STEP_SUMMARY
69+
echo "" >> $GITHUB_STEP_SUMMARY
70+
echo "Model weights uploaded to: https://huggingface.co/${{ inputs.repo_id }}" >> $GITHUB_STEP_SUMMARY
71+
echo "" >> $GITHUB_STEP_SUMMARY
72+
echo "**Repository:** \`${{ inputs.repo_id }}\`" >> $GITHUB_STEP_SUMMARY
73+
echo "**Source Path:** \`${{ inputs.weights_path }}\`" >> $GITHUB_STEP_SUMMARY
74+
echo "**Commit Message:** ${{ inputs.commit_message }}" >> $GITHUB_STEP_SUMMARY

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,10 @@ streamlit_outputs/
4545
*.mp3
4646
*.ogg
4747

48+
# Model weights staging directory
49+
weights_to_upload/
50+
models/songbloom/
51+
4852
# Temporary files
4953
tmp/
5054
temp/
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
# SongBloom Runtime Docker Image
2+
# Optimized for runtime with on-demand model weight downloads
3+
FROM nvidia/cuda:11.8.0-cudnn8-runtime-ubuntu22.04
4+
5+
# Set environment variables
6+
ENV DEBIAN_FRONTEND=noninteractive
7+
ENV PYTHONUNBUFFERED=1
8+
ENV CUDA_HOME=/usr/local/cuda
9+
10+
# Install system dependencies
11+
RUN apt-get update && apt-get install -y \
12+
python3.10 \
13+
python3-pip \
14+
git \
15+
wget \
16+
libsndfile1 \
17+
ffmpeg \
18+
&& rm -rf /var/lib/apt/lists/*
19+
20+
# Set working directory
21+
WORKDIR /app
22+
23+
# Copy requirements first for better caching
24+
COPY requirements.txt .
25+
26+
# Install Python dependencies
27+
RUN pip3 install --no-cache-dir --upgrade pip && \
28+
pip3 install --no-cache-dir torch==2.2.0 torchaudio==2.2.0 --index-url https://download.pytorch.org/whl/cu118 && \
29+
pip3 install --no-cache-dir -r requirements.txt
30+
31+
# Copy application code
32+
COPY . .
33+
34+
# Create necessary directories
35+
RUN mkdir -p /app/models/songbloom /app/cache /app/output /app/gradio_outputs /app/api_outputs /app/api_prompts
36+
37+
# Expose ports for API and Gradio
38+
EXPOSE 7860 8000
39+
40+
# Create entrypoint script that downloads weights if missing
41+
RUN echo '#!/bin/bash\n\
42+
set -e\n\
43+
\n\
44+
# Check if model weights exist\n\
45+
if [ ! -d "/app/models/songbloom" ] || [ -z "$(ls -A /app/models/songbloom 2>/dev/null)" ]; then\n\
46+
echo "🔍 Model weights not found, downloading..."\n\
47+
python3 scripts/download_weights.py || {\n\
48+
echo "❌ Failed to download model weights"\n\
49+
echo "💡 You can:"\n\
50+
echo " 1. Mount weights at /app/models/songbloom"\n\
51+
echo " 2. Set HUGGING_FACE_HUB_TOKEN for private repos"\n\
52+
exit 1\n\
53+
}\n\
54+
else\n\
55+
echo "✓ Model weights found"\n\
56+
fi\n\
57+
\n\
58+
# Execute the provided command\n\
59+
exec python3 "$@"\n\
60+
' > /entrypoint.sh && chmod +x /entrypoint.sh
61+
62+
# Set entrypoint
63+
ENTRYPOINT ["/entrypoint.sh"]
64+
65+
# Default command (can be overridden)
66+
CMD ["app.py", "--server-name", "0.0.0.0", "--server-port", "7860"]

0 commit comments

Comments
 (0)