├── Dockerfile ├── README.md ├── Stable_Diffusion_v1_Model_Card.md ├── assets ├── sample.png └── void_screenshot.webp ├── code-of-conduct.md └── docker-compose.yml /Dockerfile: -------------------------------------------------------------------------------- 1 | FROM alpine/git:latest AS builder 2 | WORKDIR /opt 3 | RUN git clone --depth 1 https://github.com/AUTOMATIC1111/stable-diffusion-webui 4 | WORKDIR /opt/stable-diffusion-webui 5 | 6 | FROM rocm/pytorch:latest 7 | ENV DEBIAN_FRONTEND=noninteractive \ 8 | PYTHONUNBUFFERED=1 \ 9 | PYTHONIOENCODING=UTF-8 \ 10 | TORCH_COMMAND='pip install --upgrade torch torchvision --extra-index-url https://download.pytorch.org/whl/rocm5.1.1' \ 11 | REQS_FILE='requirements.txt' 12 | 13 | COPY --from=builder /opt/stable-diffusion-webui /sd 14 | WORKDIR /sd 15 | 16 | SHELL ["/bin/bash", "-c"] 17 | 18 | RUN apt-get update && \ 19 | apt-get install -y libglib2.0-0 wget && \ 20 | apt-get clean -y && \ 21 | rm -rf /var/lib/apt/lists/* && \ 22 | python -m venv venv && \ 23 | source venv/bin/activate && \ 24 | python -m pip install --upgrade pip wheel && \ 25 | python -m $TORCH_COMMAND && \ 26 | python -m pip install --force-reinstall httpcore==0.15 && \ 27 | echo "Downloading SDv1.4 Model File.." && \ 28 | curl -o models/Stable-diffusion/model.ckpt https://www.googleapis.com/storage/v1/b/aai-blog-files/o/sd-v1-4.ckpt?alt=media 29 | 30 | EXPOSE 7860 31 | 32 | ENTRYPOINT python launch.py --precision full --no-half 33 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | Stable Diffusion ROCm (Radeon OpenCompute) Dockerfile 2 | == 3 | Go from `docker pull; docker run; txt2img` on a Radeon ✨. 4 | 5 | Provides a Dockerfile that packages the [AUTOMATIC1111 fork Stable Diffusion WebUI](https://github.com/AUTOMATIC1111/stable-diffusion-webui) repository, preconfigured with dependencies to run on AMD Radeon GPUs (particularly 5xxx/6xxx desktop-class GPUs) via [AMD's ROCm platform](https://docs.amd.com/category/ROCm%E2%84%A2%20v5.x). 6 | 7 | screenshot of a Void Linux/AMD GPU machine using the Stable Diffusion WebUI 8 | 9 | Requirements 10 | -- 11 | - A compatible Radeon card (VEGA 56/64, Radeon RX 6600XT/67XX/68XX/69XX). Other cards may also function at some capacity. 12 | - Modern Linux kernel with ROCM module (Kernel 5.10+) 13 | - Docker 14 | - Approximately 50GB of drive space for docker installation 15 | 16 | Usage 17 | -- 18 | 19 | First, pull the Docker image locally: 20 | 21 | ``` 22 | docker pull l1naforever/stable-diffusion-rocm:latest 23 | ``` 24 | 25 | Now, create an alias which will be used to run the Docker container. This normally goes in your `~/.zshrc` or `~/.bashrc`: 26 | 27 | ``` 28 | alias drun='docker run -it --network=host --device=/dev/kfd --device=/dev/dri --group-add=video --ipc=host --cap-add=SYS_PTRACE --security-opt seccomp=unconfined -v $(pwd):/pwd' 29 | ``` 30 | 31 | Finally, run the container: 32 | 33 | ``` 34 | drun --name stable-diffusion l1naforever/stable-diffusion-rocm:latest 35 | ``` 36 | 37 | After a period of downloading models and dependencies, you should see the output printed: 38 | 39 | ``` 40 | Running on local URL: http://localhost:7860/ 41 | ``` 42 | 43 | Visit this URL in a browser to access the web UI. 44 | 45 | 46 | Troubleshooting 47 | -- 48 | **Container fails to start with `hipErrorNoBinaryForGpu: Unable to find code object for all current devices!`** 49 | 50 | See [issue #1](https://github.com/l1na-forever/stable-diffusion-rocm-docker/issues/1). HIP's libraries bundled with the docker image are failing to load the right kernel for the specific GPU being used (this is particularly true with RX6xxx mobile variants). Try setting an environment variable to force HIP to use the `gfx1030` kernel by passing the parameter `-e HSA_OVERRIDE_GFX_VERSION=10.3.0` to `docker run`, or updating the above `drun` alias. For example: 51 | 52 | ``` 53 | alias drun='docker run -e HSA_OVERRIDE_GFX_VERSION=10.3.0 -it --network=host --device=/dev/kfd --device=/dev/dri --group-add=video --ipc=host --cap-add=SYS_PTRACE --security-opt seccomp=unconfined -v $(pwd):/pwd' 54 | ``` 55 | -------------------------------------------------------------------------------- /Stable_Diffusion_v1_Model_Card.md: -------------------------------------------------------------------------------- 1 | # Stable Diffusion v1 Model Card 2 | This model card focuses on the model associated with the Stable Diffusion model, available [here](https://github.com/CompVis/stable-diffusion). 3 | 4 | ## Model Details 5 | - **Developed by:** Robin Rombach, Patrick Esser 6 | - **Model type:** Diffusion-based text-to-image generation model 7 | - **Language(s):** English 8 | - **License:** [Proprietary](LICENSE) 9 | - **Model Description:** This is a model that can be used to generate and modify images based on text prompts. It is a [Latent Diffusion Model](https://arxiv.org/abs/2112.10752) that uses a fixed, pretrained text encoder ([CLIP ViT-L/14](https://arxiv.org/abs/2103.00020)) as suggested in the [Imagen paper](https://arxiv.org/abs/2205.11487). 10 | - **Resources for more information:** [GitHub Repository](https://github.com/CompVis/stable-diffusion), [Paper](https://arxiv.org/abs/2112.10752). 11 | - **Cite as:** 12 | 13 | @InProceedings{Rombach_2022_CVPR, 14 | author = {Rombach, Robin and Blattmann, Andreas and Lorenz, Dominik and Esser, Patrick and Ommer, Bj\"orn}, 15 | title = {High-Resolution Image Synthesis With Latent Diffusion Models}, 16 | booktitle = {Proceedings of the IEEE/CVF Conference on Computer Vision and Pattern Recognition (CVPR)}, 17 | month = {June}, 18 | year = {2022}, 19 | pages = {10684-10695} 20 | } 21 | 22 | # Uses 23 | 24 | ## Direct Use 25 | The model is intended for research purposes only. Possible research areas and 26 | tasks include 27 | 28 | - Safe deployment of models which have the potential to generate harmful content. 29 | - Probing and understanding the limitations and biases of generative models. 30 | - Generation of artworks and use in design and other artistic processes. 31 | - Applications in educational or creative tools. 32 | - Research on generative models. 33 | 34 | Excluded uses are described below. 35 | 36 | ### Misuse, Malicious Use, and Out-of-Scope Use 37 | _Note: This section is taken from the [DALLE-MINI model card](https://huggingface.co/dalle-mini/dalle-mini), but applies in the same way to Stable Diffusion v1_. 38 | 39 | 40 | The model should not be used to intentionally create or disseminate images that create hostile or alienating environments for people. This includes generating images that people would foreseeably find disturbing, distressing, or offensive; or content that propagates historical or current stereotypes. 41 | #### Out-of-Scope Use 42 | The model was not trained to be factual or true representations of people or events, and therefore using the model to generate such content is out-of-scope for the abilities of this model. 43 | #### Misuse and Malicious Use 44 | Using the model to generate content that is cruel to individuals is a misuse of this model. This includes, but is not limited to: 45 | 46 | - Generating demeaning, dehumanizing, or otherwise harmful representations of people or their environments, cultures, religions, etc. 47 | - Intentionally promoting or propagating discriminatory content or harmful stereotypes. 48 | - Impersonating individuals without their consent. 49 | - Sexual content without consent of the people who might see it. 50 | - Mis- and disinformation 51 | - Representations of egregious violence and gore 52 | - Sharing of copyrighted or licensed material in violation of its terms of use. 53 | - Sharing content that is an alteration of copyrighted or licensed material in violation of its terms of use. 54 | 55 | ## Limitations and Bias 56 | 57 | ### Limitations 58 | 59 | - The model does not achieve perfect photorealism 60 | - The model cannot render legible text 61 | - The model does not perform well on more difficult tasks which involve compositionality, such as rendering an image corresponding to “A red cube on top of a blue sphere” 62 | - Faces and people in general may not be generated properly. 63 | - The model was trained mainly with English captions and will not work as well in other languages. 64 | - The autoencoding part of the model is lossy 65 | - The model was trained on a large-scale dataset 66 | [LAION-5B](https://laion.ai/blog/laion-5b/) which contains adult material 67 | and is not fit for product use without additional safety mechanisms and 68 | considerations. 69 | 70 | ### Bias 71 | While the capabilities of image generation models are impressive, they can also reinforce or exacerbate social biases. 72 | Stable Diffusion v1 was trained on subsets of [LAION-2B(en)](https://laion.ai/blog/laion-5b/), 73 | which consists of images that are primarily limited to English descriptions. 74 | Texts and images from communities and cultures that use other languages are likely to be insufficiently accounted for. 75 | This affects the overall output of the model, as white and western cultures are often set as the default. Further, the 76 | ability of the model to generate content with non-English prompts is significantly worse than with English-language prompts. 77 | 78 | 79 | ## Training 80 | 81 | **Training Data** 82 | The model developers used the following dataset for training the model: 83 | 84 | - LAION-2B (en) and subsets thereof (see next section) 85 | 86 | **Training Procedure** 87 | Stable Diffusion v1 is a latent diffusion model which combines an autoencoder with a diffusion model that is trained in the latent space of the autoencoder. During training, 88 | 89 | - Images are encoded through an encoder, which turns images into latent representations. The autoencoder uses a relative downsampling factor of 8 and maps images of shape H x W x 3 to latents of shape H/f x W/f x 4 90 | - Text prompts are encoded through a ViT-L/14 text-encoder. 91 | - The non-pooled output of the text encoder is fed into the UNet backbone of the latent diffusion model via cross-attention. 92 | - The loss is a reconstruction objective between the noise that was added to the latent and the prediction made by the UNet. 93 | 94 | We currently provide three checkpoints, `sd-v1-1.ckpt`, `sd-v1-2.ckpt` and `sd-v1-3.ckpt`, 95 | which were trained as follows, 96 | 97 | - `sd-v1-1.ckpt`: 237k steps at resolution `256x256` on [laion2B-en](https://huggingface.co/datasets/laion/laion2B-en). 98 | 194k steps at resolution `512x512` on [laion-high-resolution](https://huggingface.co/datasets/laion/laion-high-resolution) (170M examples from LAION-5B with resolution `>= 1024x1024`). 99 | - `sd-v1-2.ckpt`: Resumed from `sd-v1-1.ckpt`. 100 | 515k steps at resolution `512x512` on "laion-improved-aesthetics" (a subset of laion2B-en, 101 | filtered to images with an original size `>= 512x512`, estimated aesthetics score `> 5.0`, and an estimated watermark probability `< 0.5`. The watermark estimate is from the LAION-5B metadata, the aesthetics score is estimated using an [improved aesthetics estimator](https://github.com/christophschuhmann/improved-aesthetic-predictor)). 102 | - `sd-v1-3.ckpt`: Resumed from `sd-v1-2.ckpt`. 195k steps at resolution `512x512` on "laion-improved-aesthetics" and 10\% dropping of the text-conditioning to improve [classifier-free guidance sampling](https://arxiv.org/abs/2207.12598). 103 | 104 | 105 | - **Hardware:** 32 x 8 x A100 GPUs 106 | - **Optimizer:** AdamW 107 | - **Gradient Accumulations**: 2 108 | - **Batch:** 32 x 8 x 2 x 4 = 2048 109 | - **Learning rate:** warmup to 0.0001 for 10,000 steps and then kept constant 110 | 111 | ## Evaluation Results 112 | Evaluations with different classifier-free guidance scales (1.5, 2.0, 3.0, 4.0, 113 | 5.0, 6.0, 7.0, 8.0) and 50 PLMS sampling 114 | steps show the relative improvements of the checkpoints: 115 | 116 | ![pareto](assets/v1-variants-scores.jpg) 117 | 118 | Evaluated using 50 PLMS steps and 10000 random prompts from the COCO2017 validation set, evaluated at 512x512 resolution. Not optimized for FID scores. 119 | ## Environmental Impact 120 | 121 | **Stable Diffusion v1** **Estimated Emissions** 122 | Based on that information, we estimate the following CO2 emissions using the [Machine Learning Impact calculator](https://mlco2.github.io/impact#compute) presented in [Lacoste et al. (2019)](https://arxiv.org/abs/1910.09700). The hardware, runtime, cloud provider, and compute region were utilized to estimate the carbon impact. 123 | 124 | - **Hardware Type:** A100 PCIe 40GB 125 | - **Hours used:** 150000 126 | - **Cloud Provider:** AWS 127 | - **Compute Region:** US-east 128 | - **Carbon Emitted (Power consumption x Time x Carbon produced based on location of power grid):** 11250 kg CO2 eq. 129 | ## Citation 130 | @InProceedings{Rombach_2022_CVPR, 131 | author = {Rombach, Robin and Blattmann, Andreas and Lorenz, Dominik and Esser, Patrick and Ommer, Bj\"orn}, 132 | title = {High-Resolution Image Synthesis With Latent Diffusion Models}, 133 | booktitle = {Proceedings of the IEEE/CVF Conference on Computer Vision and Pattern Recognition (CVPR)}, 134 | month = {June}, 135 | year = {2022}, 136 | pages = {10684-10695} 137 | } 138 | 139 | *This model card was written by: Robin Rombach and Patrick Esser and is based on the [DALL-E Mini model card](https://huggingface.co/dalle-mini/dalle-mini).* 140 | 141 | -------------------------------------------------------------------------------- /assets/sample.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/l1na-forever/stable-diffusion-rocm-docker/c0ed77df4f9736004bc42ea80b997d4f34df865f/assets/sample.png -------------------------------------------------------------------------------- /assets/void_screenshot.webp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/l1na-forever/stable-diffusion-rocm-docker/c0ed77df4f9736004bc42ea80b997d4f34df865f/assets/void_screenshot.webp -------------------------------------------------------------------------------- /code-of-conduct.md: -------------------------------------------------------------------------------- 1 | # Contributor Covenant Code of Conduct 2 | 3 | ## Our Pledge 4 | 5 | In the interest of fostering an open and welcoming environment, we as 6 | contributors and maintainers pledge to making participation in our project and 7 | our community a harassment-free experience for everyone, regardless of age, body 8 | size, disability, ethnicity, sex characteristics, gender identity and expression, 9 | level of experience, education, socio-economic status, nationality, personal 10 | appearance, race, religion, or sexual identity and orientation. 11 | 12 | ## Our Standards 13 | 14 | Examples of behavior that contributes to creating a positive environment 15 | include: 16 | 17 | * Using welcoming and inclusive language 18 | * Being respectful of differing viewpoints and experiences 19 | * Gracefully accepting constructive criticism 20 | * Focusing on what is best for the community 21 | * Showing empathy towards other community members 22 | 23 | Examples of unacceptable behavior by participants include: 24 | 25 | * The use of sexualized language or imagery and unwelcome sexual attention or 26 | advances 27 | * Trolling, insulting/derogatory comments, and personal or political attacks 28 | * Public or private harassment 29 | * Publishing others' private information, such as a physical or electronic 30 | address, without explicit permission 31 | * Other conduct which could reasonably be considered inappropriate in a 32 | professional setting 33 | 34 | ## Our Responsibilities 35 | 36 | Project maintainers are responsible for clarifying the standards of acceptable 37 | behavior and are expected to take appropriate and fair corrective action in 38 | response to any instances of unacceptable behavior. 39 | 40 | Project maintainers have the right and responsibility to remove, edit, or 41 | reject comments, commits, code, wiki edits, issues, and other contributions 42 | that are not aligned to this Code of Conduct, or to ban temporarily or 43 | permanently any contributor for other behaviors that they deem inappropriate, 44 | threatening, offensive, or harmful. 45 | 46 | ## Scope 47 | 48 | This Code of Conduct applies both within project spaces and in public spaces 49 | when an individual is representing the project or its community. Examples of 50 | representing a project or community include using an official project e-mail 51 | address, posting via an official social media account, or acting as an appointed 52 | representative at an online or offline event. Representation of a project may be 53 | further defined and clarified by project maintainers. 54 | 55 | ## Enforcement 56 | 57 | Instances of abusive, harassing, or otherwise unacceptable behavior may be 58 | reported by contacting the project team at tylerneely@gmail.com. All 59 | complaints will be reviewed and investigated and will result in a response that 60 | is deemed necessary and appropriate to the circumstances. The project team is 61 | obligated to maintain confidentiality with regard to the reporter of an incident. 62 | Further details of specific enforcement policies may be posted separately. 63 | 64 | Project maintainers who do not follow or enforce the Code of Conduct in good 65 | faith may face temporary or permanent repercussions as determined by other 66 | members of the project's leadership. 67 | 68 | ## Attribution 69 | 70 | This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, 71 | available at https://www.contributor-covenant.org/version/1/4/code-of-conduct.html 72 | 73 | [homepage]: https://www.contributor-covenant.org 74 | 75 | -------------------------------------------------------------------------------- /docker-compose.yml: -------------------------------------------------------------------------------- 1 | version: "2" 2 | services: 3 | stable-diffusion-rocm-docker: 4 | cap_add: 5 | - SYS_PTRACE 6 | devices: 7 | - /dev/kfd:/dev/kfd 8 | - /dev/dri:/dev/dri 9 | environment: 10 | # VERY COMMON NEED ENVIRONMENT VARIABLE 11 | - HSA_OVERRIDE_GFX_VERSION=10.3.4 12 | image: 1naforever/stable-diffusion-rocm:latest 13 | ipc: host 14 | network_mode: "host" 15 | security_opt: 16 | - seccomp:unconfined 17 | volumes: 18 | - modules:/sd/modules 19 | - models:/sd/models 20 | - plugins:/sd/plugins 21 | - outputs:/sd/outputs 22 | volumes: 23 | modules: 24 | models: 25 | plugins: 26 | outputs: 27 | --------------------------------------------------------------------------------