created ROCm-compatible docker image for automatic1111's stablediffusion webui
This commit is contained in:
+110
@@ -0,0 +1,110 @@
|
||||
# Stable Diffusion WebUI with AMD ROCm Support
|
||||
# Base image: Ubuntu 22.04 for best ROCm compatibility
|
||||
|
||||
FROM ubuntu:22.04 AS builder
|
||||
|
||||
# Set environment variables
|
||||
ENV DEBIAN_FRONTEND=noninteractive \
|
||||
PYTHON_VERSION=3.10 \
|
||||
ROCM_VERSION=5.7 \
|
||||
HSA_OVERRIDE_GFX_VERSION=11.0.0 \
|
||||
HIP_VISIBLE_DEVICES=0 \
|
||||
HIP_PATH=/opt/rocm \
|
||||
PATH=/opt/rocm/bin:$PATH \
|
||||
LD_LIBRARY_PATH=/opt/rocm/lib:/opt/rocm/hip/lib:/opt/rocm/opencl/lib/x86_64 \
|
||||
PYTORCH_ROCM_ARCH=gfx1100
|
||||
|
||||
# Update and install system dependencies
|
||||
RUN apt-get update && apt-get upgrade -y && \
|
||||
apt-get install -y --no-install-recommends \
|
||||
wget \
|
||||
git \
|
||||
curl \
|
||||
ca-certificates \
|
||||
gnupg \
|
||||
lsb-release \
|
||||
software-properties-common \
|
||||
build-essential \
|
||||
python3 \
|
||||
python3-pip \
|
||||
python3-venv \
|
||||
libgl1 \
|
||||
libglib2.0-0 \
|
||||
libsm6 \
|
||||
libxrender1 \
|
||||
libxext6 \
|
||||
libfontconfig1 \
|
||||
libfreetype6 \
|
||||
libgl1-mesa-glx \
|
||||
libglib2.0-0 \
|
||||
libsm6 \
|
||||
libxrender1 \
|
||||
libxext6 \
|
||||
libfontconfig1 \
|
||||
libfreetype6 \
|
||||
&& rm -rf /var/lib/apt/lists/*
|
||||
|
||||
# Install ROCm 5.7
|
||||
RUN mkdir -p /tmp/rocm && cd /tmp/rocm && \
|
||||
wget https://repo.radeon.com/amdgpu-install/5.7/ubuntu/jammy/amdgpu-install_5.7.50700-1_all.deb && \
|
||||
apt-get install -y ./amdgpu-install_5.7.50700-1_all.deb && \
|
||||
apt-get update && \
|
||||
DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \
|
||||
rocm-device-libs rocm-hip-runtime rocm-opencl-runtime rocminfo && \
|
||||
rm -rf /tmp/rocm
|
||||
|
||||
# Verify ROCm installation
|
||||
RUN rocminfo | grep "Agent" || echo "ROCm installation verification"
|
||||
|
||||
# Install Python 3.10 and create virtual environment
|
||||
RUN apt-get update && apt-get install -y --no-install-recommends \
|
||||
python3.10 \
|
||||
python3.10-dev \
|
||||
python3.10-venv \
|
||||
&& rm -rf /var/lib/apt/lists/*
|
||||
|
||||
# Create and activate virtual environment
|
||||
RUN python3.10 -m venv /opt/venv
|
||||
ENV PATH=/opt/venv/bin:$PATH
|
||||
|
||||
# Install PyTorch with ROCm support
|
||||
RUN pip install --upgrade pip && \
|
||||
pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/rocm5.7
|
||||
|
||||
# Install project dependencies
|
||||
WORKDIR /app
|
||||
COPY requirements.txt .
|
||||
RUN pip install -r requirements.txt
|
||||
|
||||
# Install xformers with ROCm support or handle gracefully
|
||||
RUN pip install xformers --index-url https://download.pytorch.org/whl/rocm5.7 || \
|
||||
(echo "xformers with ROCm support failed, installing without ROCm acceleration" && \
|
||||
pip install xformers --no-deps && \
|
||||
echo "xformers installed but may not have full ROCm acceleration")
|
||||
|
||||
# Clone the upstream repository
|
||||
RUN git clone https://github.com/AUTOMATIC1111/stable-diffusion-webui.git /app/webui && \
|
||||
cd /app/webui && \
|
||||
git checkout v1.7.0
|
||||
|
||||
# Install additional dependencies that might be needed
|
||||
RUN apt-get update && apt-get install -y --no-install-recommends \
|
||||
libgl1-mesa-glx \
|
||||
libglib2.0-0 \
|
||||
libsm6 \
|
||||
libxrender1 \
|
||||
libxext6 \
|
||||
libfontconfig1 \
|
||||
libfreetype6 \
|
||||
&& rm -rf /var/lib/apt/lists/*
|
||||
|
||||
# Set working directory and expose port
|
||||
WORKDIR /app/webui
|
||||
EXPOSE 7860
|
||||
|
||||
# Create entrypoint script
|
||||
COPY docker/docker-entrypoint.sh /docker-entrypoint.sh
|
||||
RUN chmod +x /docker-entrypoint.sh
|
||||
|
||||
ENTRYPOINT ["/docker-entrypoint.sh"]
|
||||
CMD ["python", "launch.py", "--listen", "--port", "7860", "--opt-sdp-attention", "--no-half-vae"]
|
||||
@@ -0,0 +1,128 @@
|
||||
# Stable Diffusion WebUI Docker with AMD ROCm Support
|
||||
|
||||
This Docker setup provides a containerized version of Stable Diffusion WebUI with full AMD ROCm GPU acceleration support.
|
||||
|
||||
## Features
|
||||
|
||||
- **AMD ROCm 5.7** support for GPU acceleration
|
||||
- **gfx1100 (ROCm 11.0.0)** GPU target configuration
|
||||
- **PyTorch 2.0** with ROCm compatibility
|
||||
- **Docker Compose** for easy deployment
|
||||
- **Persistent storage** for models, outputs, and configurations
|
||||
- **Optimized** Docker build with multi-stage construction
|
||||
|
||||
## Requirements
|
||||
|
||||
- Docker Engine (20.10+ recommended)
|
||||
- Docker Compose (v2+ recommended)
|
||||
- AMD GPU with ROCm support (RDNA2/RDNA3 recommended)
|
||||
- Linux host system (for proper GPU passthrough)
|
||||
|
||||
## Quick Start
|
||||
|
||||
### 1. Build the Docker image
|
||||
|
||||
```bash
|
||||
docker-compose build
|
||||
```
|
||||
|
||||
### 2. Start the container
|
||||
|
||||
```bash
|
||||
docker-compose up -d
|
||||
```
|
||||
|
||||
### 3. Access the Web UI
|
||||
|
||||
Open your browser to: `http://localhost:7860`
|
||||
|
||||
## Configuration
|
||||
|
||||
### Environment Variables
|
||||
|
||||
You can customize the setup using environment variables in the `docker-compose.yml` file:
|
||||
|
||||
- `HSA_OVERRIDE_GFX_VERSION`: GPU target version (default: `11.0.0` for gfx1100)
|
||||
- `HIP_VISIBLE_DEVICES`: Which GPU devices to use (default: `0`)
|
||||
- `PYTORCH_ROCM_ARCH`: PyTorch ROCm architecture (default: `gfx1100`)
|
||||
- `CLI_ARGS`: Additional command line arguments for launch.py
|
||||
|
||||
### Volumes
|
||||
|
||||
The following directories are persisted as Docker volumes:
|
||||
|
||||
- `./models` - Model files
|
||||
- `./outputs` - Generated images and outputs
|
||||
- `./extensions` - WebUI extensions
|
||||
- `./config.json` - Configuration file
|
||||
|
||||
### GPU Configuration
|
||||
|
||||
The Docker setup automatically configures:
|
||||
|
||||
- `/dev/kfd` - AMD KFD device for GPU acceleration
|
||||
- `/dev/dri` - Direct Rendering Infrastructure for display
|
||||
- Proper group permissions (video, render)
|
||||
|
||||
## Customization
|
||||
|
||||
### Change GPU Target
|
||||
|
||||
To use a different GPU target (e.g., gfx1030 for Navi 2x):
|
||||
|
||||
1. Edit `docker/docker-compose.yml`
|
||||
2. Change `HSA_OVERRIDE_GFX_VERSION` to your target version
|
||||
3. Change `PYTORCH_ROCM_ARCH` accordingly
|
||||
|
||||
### Add Custom Arguments
|
||||
|
||||
Modify the `CLI_ARGS` environment variable in `docker-compose.yml` to add custom launch arguments:
|
||||
|
||||
```yaml
|
||||
environment:
|
||||
- CLI_ARGS=--listen --port 7860 --xformers --opt-sdp-attention --your-custom-arg
|
||||
```
|
||||
|
||||
## Building for Different ROCm Versions
|
||||
|
||||
To use a different ROCm version:
|
||||
|
||||
1. Edit `docker/Dockerfile`
|
||||
2. Change the `ROCM_VERSION` environment variable
|
||||
3. Update the PyTorch installation command to match the ROCm version
|
||||
4. Rebuild the container
|
||||
|
||||
## Troubleshooting
|
||||
|
||||
### GPU Not Detected
|
||||
|
||||
- Ensure your host system has ROCm properly installed
|
||||
- Check that the `video` and `render` groups exist on your host
|
||||
- Verify that `/dev/kfd` and `/dev/dri` devices exist
|
||||
|
||||
### Build Failures
|
||||
|
||||
- Ensure you have enough disk space (ROCm installation requires ~5GB)
|
||||
- Check your internet connection for downloading ROCm packages
|
||||
- Try cleaning the Docker build cache: `docker system prune -a`
|
||||
|
||||
### Performance Issues
|
||||
|
||||
- Make sure your GPU is properly supported by ROCm 5.7
|
||||
- Check that the correct `HSA_OVERRIDE_GFX_VERSION` is set for your GPU
|
||||
- Monitor GPU usage with `rocm-smi` on the host system
|
||||
|
||||
## Updating
|
||||
|
||||
To update to the latest version:
|
||||
|
||||
```bash
|
||||
docker-compose down
|
||||
git pull
|
||||
docker-compose build --no-cache
|
||||
docker-compose up -d
|
||||
```
|
||||
|
||||
## License
|
||||
|
||||
This Docker configuration is provided under the same license as the Stable Diffusion WebUI project (AGPL-3.0).
|
||||
@@ -0,0 +1,26 @@
|
||||
services:
|
||||
stable-diffusion-webui:
|
||||
build:
|
||||
context: .
|
||||
dockerfile: Dockerfile
|
||||
deploy:
|
||||
resources:
|
||||
limits:
|
||||
memory: 16G
|
||||
cpus: 16
|
||||
container_name: stable-diffusion-webui
|
||||
restart: unless-stopped
|
||||
environment:
|
||||
- HSA_OVERRIDE_GFX_VERSION=11.0.0
|
||||
- HIP_VISIBLE_DEVICES=0
|
||||
- PYTORCH_ROCM_ARCH=gfx1100
|
||||
- CLI_ARGS=--listen --port 7860 --opt-sdp-attention --no-half-vae --skip-torch-cuda-test
|
||||
ports:
|
||||
- "7860:7860"
|
||||
volumes:
|
||||
- ./models:/app/models
|
||||
- ./outputs:/app/outputs
|
||||
- ./extensions:/app/extensions
|
||||
devices:
|
||||
- "/dev/kfd:/dev/kfd"
|
||||
- "/dev/dri:/dev/dri"
|
||||
Executable
+61
@@ -0,0 +1,61 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Docker entrypoint script for Stable Diffusion WebUI with AMD ROCm support
|
||||
|
||||
set -e
|
||||
|
||||
# Set up environment variables for ROCm
|
||||
export HSA_OVERRIDE_GFX_VERSION=${HSA_OVERRIDE_GFX_VERSION:-11.0.0}
|
||||
export HIP_VISIBLE_DEVICES=${HIP_VISIBLE_DEVICES:-0}
|
||||
export PYTORCH_ROCM_ARCH=${PYTORCH_ROCM_ARCH:-gfx1100}
|
||||
export HIP_PATH=/opt/rocm
|
||||
export PATH=/opt/rocm/bin:$PATH
|
||||
export LD_LIBRARY_PATH=/opt/rocm/lib:/opt/rocm/hip/lib:/opt/rocm/opencl/lib/x86_64:$LD_LIBRARY_PATH
|
||||
|
||||
echo "=========================================="
|
||||
echo "Stable Diffusion WebUI Docker Entrypoint"
|
||||
echo "=========================================="
|
||||
echo "ROCm Version: 5.7"
|
||||
echo "GPU Target: gfx1100 (${HSA_OVERRIDE_GFX_VERSION})"
|
||||
echo "PyTorch: ROCm 5.7 compatible"
|
||||
echo "=========================================="
|
||||
|
||||
# Check if ROCm is properly installed
|
||||
if command -v rocminfo &> /dev/null; then
|
||||
echo "ROCm is installed:"
|
||||
rocminfo | grep -E "Agent|Name" | head -5
|
||||
else
|
||||
echo "Warning: ROCm not found in PATH"
|
||||
fi
|
||||
|
||||
# Check if GPU devices are accessible
|
||||
if [ -c /dev/kfd ]; then
|
||||
echo "AMD KFD device found"
|
||||
else
|
||||
echo "Warning: /dev/kfd not found"
|
||||
fi
|
||||
|
||||
if [ -c /dev/dri/card0 ]; then
|
||||
echo "DRM device found"
|
||||
else
|
||||
echo "Warning: /dev/dri/card0 not found"
|
||||
fi
|
||||
|
||||
# Activate virtual environment
|
||||
if [ -d "/opt/venv" ]; then
|
||||
echo "Activating Python virtual environment..."
|
||||
source /opt/venv/bin/activate
|
||||
else
|
||||
echo "Warning: Virtual environment not found at /opt/venv"
|
||||
fi
|
||||
|
||||
# Set default command line arguments if not provided
|
||||
DEFAULT_ARGS="--api --listen --port 7860 --opt-sdp-attention --no-half-vae"
|
||||
CLI_ARGS=${CLI_ARGS:-$DEFAULT_ARGS}
|
||||
|
||||
echo "Starting Stable Diffusion WebUI with arguments: $CLI_ARGS"
|
||||
echo "Web UI will be available at http://localhost:7860"
|
||||
echo "=========================================="
|
||||
|
||||
# Execute the command
|
||||
exec python launch.py $CLI_ARGS
|
||||
Reference in New Issue
Block a user