Docker platform now configurable. No longer Mac-specific

This commit is contained in:
Armando C. Santisbon 2022-09-11 15:36:09 -05:00
parent 19fb66f3d5
commit 585b47fdd1
2 changed files with 15 additions and 7 deletions

View File

@ -4,7 +4,7 @@ Table of Contents
* [Step 1 - Get the Model](#step-1---get-the-model)
* [Step 2 - Installation](#step-2---installation)
* [Option A - On a Linux container with Docker for Apple silicon](#option-a---on-a-linux-container-with-docker-for-apple-silicon)
* [Option A - On a Linux container with Docker](#option-a---on-a-linux-container-with-docker-for-apple-silicon)
* [Prerequisites](#prerequisites)
* [Setup](#setup)
* [Option B - Directly on Apple silicon](#option-b---directly-on-apple-silicon)
@ -23,7 +23,8 @@ You'll need to create an account but it's quick and free.
# Step 2 - Installation
## Option A - On a Linux container with Docker for Apple silicon
## Option A - On a Linux container
This example uses a Mac M2 but you can specify the platform and architecture as parameters when building the image and running the container.
You [can't access the Macbook M1/M2 GPU cores from the Docker containers](https://github.com/pytorch/pytorch/issues/81224) so performance is reduced but for development purposes it's fine.
### Prerequisites
@ -59,9 +60,13 @@ wget https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-aarch64.sh -O a
```
Build the Docker image. Give it any tag ```-t``` that you want.
Tip: Make sure your shell session has the env variable set (above) with ```echo $GITHUB_STABLE_DIFFUSION```.
Tip: Check that your shell session has the env variable set (above) with ```echo $GITHUB_STABLE_DIFFUSION```.
Base image will be arm64v8/debian on a macOS host.
```condaarch``` will restrict the conda environment to the right architecture when installing packages. It can take on: ```linux-64```, ```osx-64```, ```osx-arm64```. M1/M2 is ARM-based. On macOS you could also conda install ```nomkl``` but setting the environment appropriately is cleaner.
```Shell
docker build -t santisbon/stable-diffusion \
--platform linux/arm64 \
--build-arg condaarch="osx-arm64" \
--build-arg gsd=$GITHUB_STABLE_DIFFUSION \
--build-arg sdreq="requirements-linux-arm64.txt" \
.

View File

@ -1,10 +1,14 @@
FROM arm64v8/debian
FROM debian
ARG gsd
ENV GITHUB_STABLE_DIFFUSION $gsd
ARG sdreq="requirements-linux-arm64.txt"
ENV SD_REQ $sdreq
ARG condaarch
ENV ARCH $condaarch
WORKDIR /
# TODO: Optimize image size
@ -30,10 +34,9 @@ WORKDIR /stable-diffusion
# SD env 2.3 GB !!!
RUN PIP_EXISTS_ACTION="w" \
# restrict the Conda environment to only use ARM packages. M1/M2 is ARM-based. You could also conda install nomkl.
&& CONDA_SUBDIR="osx-arm64" \
# Create the environment, activate it, install requirements.
&& CONDA_SUBDIR=$ARCH \
&& source ~/.bashrc && conda create -y --name ldm && conda activate ldm \
&& conda config --env --set subdir $ARCH \
&& pip3 install -r $SD_REQ \
&& mkdir models/ldm/stable-diffusion-v1