Spaces:
Paused
Paused
Georg commited on
Commit ·
cc1a738
1
Parent(s): d0b92e0
cleanup
Browse files- BUILD.md +0 -171
- build_base.sh +0 -20
BUILD.md
DELETED
|
@@ -1,171 +0,0 @@
|
|
| 1 |
-
# Two-Stage Docker Build
|
| 2 |
-
|
| 3 |
-
FoundationPose requires CUDA C++ extensions that must be compiled with a GPU present. To enable local development and avoid build failures, we use a two-stage build process:
|
| 4 |
-
|
| 5 |
-
## Architecture
|
| 6 |
-
|
| 7 |
-
```
|
| 8 |
-
┌─────────────────────────────────────────────────┐
|
| 9 |
-
│ Stage 1: Base Image (Local, No GPU) │
|
| 10 |
-
│ - Install system dependencies │
|
| 11 |
-
│ - Install PyTorch + Python packages │
|
| 12 |
-
│ - Clone FoundationPose repository │
|
| 13 |
-
│ - Patch setup.py for C++17 │
|
| 14 |
-
│ Build locally → Push to DockerHub │
|
| 15 |
-
└─────────────────────────────────────────────────┘
|
| 16 |
-
↓
|
| 17 |
-
┌─────────────────────────────────────────────────┐
|
| 18 |
-
│ Stage 2: Final Image (HuggingFace, GPU) │
|
| 19 |
-
│ FROM gpue/foundationpose-base:latest │
|
| 20 |
-
│ - Compile mycuda C++ extension (needs GPU) │
|
| 21 |
-
│ - Compile mycpp C++ extension │
|
| 22 |
-
│ - Download model weights │
|
| 23 |
-
│ Build on HuggingFace Spaces with GPU │
|
| 24 |
-
└─────────────────────────────────────────────────┘
|
| 25 |
-
```
|
| 26 |
-
|
| 27 |
-
## Files
|
| 28 |
-
|
| 29 |
-
- **Dockerfile.base** - Stage 1: Base image without GPU compilation
|
| 30 |
-
- **Dockerfile** - Stage 2: Final image that compiles CUDA extensions
|
| 31 |
-
- **build_base.sh** - Build base image only
|
| 32 |
-
- **deploy.sh** - Full two-stage deployment
|
| 33 |
-
|
| 34 |
-
## Quick Start
|
| 35 |
-
|
| 36 |
-
### Option 1: Automated Deployment
|
| 37 |
-
|
| 38 |
-
```bash
|
| 39 |
-
cd /Users/georgpuschel/repos/robot-ml/foundationpose
|
| 40 |
-
|
| 41 |
-
# Login to DockerHub
|
| 42 |
-
docker login
|
| 43 |
-
|
| 44 |
-
# Run full deployment (builds base, pushes to DockerHub, deploys to HF, follows logs)
|
| 45 |
-
./deploy.sh
|
| 46 |
-
```
|
| 47 |
-
|
| 48 |
-
The script will:
|
| 49 |
-
1. Build the base image for linux/amd64
|
| 50 |
-
2. Push to DockerHub as `gpue/foundationpose-base:latest`
|
| 51 |
-
3. Commit and push changes to HuggingFace
|
| 52 |
-
4. Automatically follow the HuggingFace build logs (press Ctrl+C to stop)
|
| 53 |
-
|
| 54 |
-
**Prerequisites**:
|
| 55 |
-
- Docker login credentials for DockerHub
|
| 56 |
-
- HuggingFace token in `../training/.env.local` (for following logs)
|
| 57 |
-
|
| 58 |
-
### Option 2: Manual Steps
|
| 59 |
-
|
| 60 |
-
#### Step 1: Build and Push Base Image
|
| 61 |
-
|
| 62 |
-
```bash
|
| 63 |
-
# Build for linux/amd64 (HuggingFace platform)
|
| 64 |
-
docker build --platform linux/amd64 -f Dockerfile.base -t gpue/foundationpose-base:latest .
|
| 65 |
-
|
| 66 |
-
# Push to DockerHub
|
| 67 |
-
docker login
|
| 68 |
-
docker push gpue/foundationpose-base:latest
|
| 69 |
-
```
|
| 70 |
-
|
| 71 |
-
#### Step 2: Deploy to HuggingFace
|
| 72 |
-
|
| 73 |
-
```bash
|
| 74 |
-
# Add the git remote (if not already added)
|
| 75 |
-
git remote add hf https://huggingface.co/spaces/gpue/foundationpose
|
| 76 |
-
|
| 77 |
-
# Push updated Dockerfile to HuggingFace
|
| 78 |
-
git add Dockerfile Dockerfile.base
|
| 79 |
-
git commit -m "Two-stage build: base image + GPU compilation"
|
| 80 |
-
git push hf main
|
| 81 |
-
```
|
| 82 |
-
|
| 83 |
-
HuggingFace will automatically:
|
| 84 |
-
1. Pull `gpue/foundationpose-base:latest` from DockerHub
|
| 85 |
-
2. Compile C++ extensions with GPU present
|
| 86 |
-
3. Download model weights
|
| 87 |
-
4. Start the application
|
| 88 |
-
|
| 89 |
-
## Why Two Stages?
|
| 90 |
-
|
| 91 |
-
**Problem**: CUDA C++ extensions fail to compile without a GPU:
|
| 92 |
-
```
|
| 93 |
-
TypeError: expected string or bytes-like object
|
| 94 |
-
torch.version.cuda returns None when no GPU is present
|
| 95 |
-
```
|
| 96 |
-
|
| 97 |
-
**Solution**:
|
| 98 |
-
- Stage 1 (Base): Everything except GPU compilation - can build anywhere
|
| 99 |
-
- Stage 2 (Final): Only GPU-dependent compilation - builds on HuggingFace with GPU
|
| 100 |
-
|
| 101 |
-
**Benefits**:
|
| 102 |
-
- ✓ Build base image locally without GPU
|
| 103 |
-
- ✓ Faster HuggingFace builds (base layers cached)
|
| 104 |
-
- ✓ Easy to iterate on application code (stage 2 is small)
|
| 105 |
-
- ✓ Base image can be reused across multiple projects
|
| 106 |
-
|
| 107 |
-
## Troubleshooting
|
| 108 |
-
|
| 109 |
-
### Platform Mismatch
|
| 110 |
-
|
| 111 |
-
If you're on Apple Silicon (M1/M2/M3), you must specify `--platform linux/amd64`:
|
| 112 |
-
|
| 113 |
-
```bash
|
| 114 |
-
docker build --platform linux/amd64 -f Dockerfile.base -t gpue/foundationpose-base:latest .
|
| 115 |
-
```
|
| 116 |
-
|
| 117 |
-
### DockerHub Authentication
|
| 118 |
-
|
| 119 |
-
```bash
|
| 120 |
-
docker login
|
| 121 |
-
# Enter username: gpue
|
| 122 |
-
# Enter password: <your-dockerhub-token>
|
| 123 |
-
```
|
| 124 |
-
|
| 125 |
-
### Verify Base Image
|
| 126 |
-
|
| 127 |
-
Test the base image locally (without GPU compilation):
|
| 128 |
-
|
| 129 |
-
```bash
|
| 130 |
-
docker run --rm -it gpue/foundationpose-base:latest bash
|
| 131 |
-
|
| 132 |
-
# Inside container:
|
| 133 |
-
python3 -c "import torch; print(torch.__version__)"
|
| 134 |
-
ls /app/FoundationPose
|
| 135 |
-
cat /app/FoundationPose/bundlesdf/mycuda/setup.py | grep "c++17"
|
| 136 |
-
```
|
| 137 |
-
|
| 138 |
-
### HuggingFace Build Logs
|
| 139 |
-
|
| 140 |
-
Monitor the build on HuggingFace:
|
| 141 |
-
|
| 142 |
-
```bash
|
| 143 |
-
curl -H "Authorization: Bearer $HF_TOKEN" \
|
| 144 |
-
"https://huggingface.co/api/spaces/gpue/foundationpose/logs/build"
|
| 145 |
-
```
|
| 146 |
-
|
| 147 |
-
## Updating the Base Image
|
| 148 |
-
|
| 149 |
-
When you need to change dependencies or system packages:
|
| 150 |
-
|
| 151 |
-
1. Edit `Dockerfile.base`
|
| 152 |
-
2. Rebuild and push:
|
| 153 |
-
```bash
|
| 154 |
-
./build_base.sh
|
| 155 |
-
docker push gpue/foundationpose-base:latest
|
| 156 |
-
```
|
| 157 |
-
3. Rebuild on HuggingFace (will pull updated base automatically)
|
| 158 |
-
|
| 159 |
-
## Local Testing (Without GPU)
|
| 160 |
-
|
| 161 |
-
To test the base image without GPU compilation:
|
| 162 |
-
|
| 163 |
-
```bash
|
| 164 |
-
# Build base
|
| 165 |
-
docker build -f Dockerfile.base -t foundationpose-base-test .
|
| 166 |
-
|
| 167 |
-
# Run without compiling extensions
|
| 168 |
-
docker run --rm -p 7860:7860 foundationpose-base-test python3 app.py
|
| 169 |
-
```
|
| 170 |
-
|
| 171 |
-
The app will run in placeholder mode (no real inference) but you can test the UI and API endpoints.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
build_base.sh
DELETED
|
@@ -1,20 +0,0 @@
|
|
| 1 |
-
#!/bin/bash
|
| 2 |
-
# Build and push the base image to DockerHub
|
| 3 |
-
|
| 4 |
-
set -e
|
| 5 |
-
|
| 6 |
-
IMAGE_NAME="gpue/foundationpose-base"
|
| 7 |
-
TAG="latest"
|
| 8 |
-
PLATFORM="linux/amd64" # HuggingFace Spaces use x86_64
|
| 9 |
-
|
| 10 |
-
echo "Building base image for ${PLATFORM}: ${IMAGE_NAME}:${TAG}"
|
| 11 |
-
docker build --platform ${PLATFORM} -f Dockerfile.base -t ${IMAGE_NAME}:${TAG} .
|
| 12 |
-
|
| 13 |
-
echo ""
|
| 14 |
-
echo "✓ Base image built successfully for ${PLATFORM}"
|
| 15 |
-
echo ""
|
| 16 |
-
echo "To push to DockerHub:"
|
| 17 |
-
echo " docker login"
|
| 18 |
-
echo " docker push ${IMAGE_NAME}:${TAG}"
|
| 19 |
-
echo ""
|
| 20 |
-
echo "After pushing, the HuggingFace Space will use this base image."
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|