Practical overview
When it fits
Use SafeGen when you need research code and weights for experimenting with a Stable Diffusion mitigation against sexually explicit generation, rather than a hosted generation product.
Who it is for
- Researchers studying sexually explicit content generation in text-to-image systems.
- Developers adapting Stable Diffusion pipelines with a model-level safety mitigation.
- Teams evaluating prompt-based risks in text-to-image models.
Documented uses
- Adjust Stable Diffusion self-attention layers as part of a content-mitigation experiment.
- Load a saved regulated model through Diffusers and generate an image.
- Prepare image-only data using the separately described Anti-DeepNude workflow.
- Request access to the adversarial textual prompt benchmark images for scholarly research.
Requirements & limits
The repository is public and licensed under Apache-2.0. The pretrained weights are linked from Hugging Face. Access to the Anti-DeepNude code and weights requires an approved academic-purpose request, and access to benchmark images is restricted to scholarly use with a non-redistribution commitment.
- The implementation adjusts Stable Diffusion self-attention layers and is presented as an integration example for Diffusers.
- The default configuration is described for one NVIDIA A100 40GB; the README advises a small training batch size to avoid out-of-memory errors.
- Main model adjustment uses a PyTorch environment, while the Anti-DeepNude data-preparation component requires a separate TensorFlow 1.13 environment with Python 3.7 or earlier.
- The benchmark includes more than 50,000 adversarial prompts, but its associated images have restricted access.
Check current requirements in the official documentation. Source-based guidance does not mean OpenViST has run or independently tested this project.
Set up SafeGen’s PyTorch and Diffusers environment
Prepare the main environment documented for adjusting Stable Diffusion self-attention layers.
Before you start
- Conda
- Python 3.8.5
- PyTorch 1.12.1, torchvision 0.13.1, torchaudio 0.12.1 and CUDA toolkit 11.3
- Diffusers with Torch, datasets and transformers, or the documented Conda Diffusers package
Steps
Create a Conda environment named text-agnostic-t2i with Python 3.8.5.
Install the listed PyTorch packages and CUDA toolkit from the PyTorch channel.
Install diffusers[torch], datasets and transformers with pip, or install Diffusers from conda-forge.
Alternatively, create the environment from environment_pytorch.yaml.
Expected outcome
A prepared PyTorch and Diffusers environment for the repository’s Stable Diffusion adjustment work.
Guide limitations
- The README describes one NVIDIA A100 40GB for its default configuration and advises a small training batch size to avoid out-of-memory errors.
- This covers environment setup only, not a verified training run.
Load a saved regulated model for Diffusers inference
Use the repository’s documented Python example to generate an image with a saved model.
Before you start
- A saved model at the output path
- Diffusers and PyTorch
- CUDA, as used in the repository’s example
Steps
Set model_path to the saved model directory.
Load it with StableDiffusionPipeline.from_pretrained using torch.float16.
Move the pipeline to CUDA.
Pass a prompt to the pipeline and save the first returned image.
Expected outcome
The example writes a generated image to a local file using the saved model.
Guide limitations
- The README provides an example rather than a tested compatibility guarantee.
- This inference example assumes a model has already been saved; it does not cover training or acquiring the pretrained weights.
Sources & review
Source record details
- Source availability
- Active
- Sources checked
- 16 October 2026
- Original website title
- LetterLiGo/SafeGen_CCS2024 · Official homepage title · retained in its source language

