OpenViSTAI · Agents · Blockchain · Crypto
Menu
AI Security & Safety

SafeGen

SafeGen is an open-source research implementation and set of pretrained weights for mitigating sexually explicit content generation in text-to-image models. It adjusts Stable Diffusion self-attention layers based on image-only triplets and includes an example for loading a saved model with Diffusers.

Independent OpenViST project profile, based on linked sources.

SafeGen — OpenViST project profile in AI Security & Safety.
OpenViST project illustration. See the linked sources for product details.
Understand the project

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.
Before you choose

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.

Source-based practical guide

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

  1. Create a Conda environment named text-agnostic-t2i with Python 3.8.5.

  2. Install the listed PyTorch packages and CUDA toolkit from the PyTorch channel.

  3. Install diffusers[torch], datasets and transformers with pip, or install Diffusers from conda-forge.

  4. 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.
Source-based practical guide

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

  1. Set model_path to the saved model directory.

  2. Load it with StableDiffusionPipeline.from_pretrained using torch.float16.

  3. Move the pipeline to CUDA.

  4. 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.
Evidence and transparency

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