chansung's picture
Upload folder using huggingface_hub
80a1334 verified

A newer version of the Gradio SDK is available: 5.32.1

Upgrade
metadata
title: auto-diffuser-config
app_file: gradio_app.py
sdk: gradio
sdk_version: 5.31.0

Auto-Diffusers

An intelligent code generator that creates optimized diffusers library snippets based on your hardware specifications using Google's Gemini API.

Features

  • Hardware Detection: Automatically detects your system specs (CPU, GPU, VRAM) or allows manual input
  • Real-time Optimization: Fetches latest optimization techniques from HuggingFace documentation
  • Smart Code Generation: Uses Gemini API to generate hardware-optimized diffusers code
  • Multiple Profiles: Supports high-end GPU, mid-range GPU, low VRAM, Apple Silicon, and CPU-only configurations

Setup

  1. Create and activate conda environment:
conda create -n auto-diffusers python=3.11 -y
conda activate auto-diffusers
  1. Install dependencies:
pip install -r requirements.txt
  1. Set up Gemini API key:
export GEMINI_API_KEY="your_api_key_here"

Usage

Interactive Mode

python auto_diffusers.py

Hardware Detection Only

python hardware_detector.py

Programmatic Usage

from auto_diffusers import AutoDiffusersGenerator

generator = AutoDiffusersGenerator(api_key="your_key")
code = generator.generate_optimized_code(
    model_name="black-forest-labs/FLUX.1-schnell",
    prompt_text="A cat holding a sign that says hello world",
    image_size=(768, 1360),
    num_inference_steps=4
)
print(code)

Hardware Profiles

  • high_end_gpu: 20+ GB VRAM (RTX 4090, A100, etc.)
  • mid_range_gpu: 8-20 GB VRAM (RTX 3080, RTX 4070, etc.)
  • low_vram_gpu: <8 GB VRAM (GTX 1660, RTX 3060, etc.)
  • apple_silicon: M1/M2/M3 Macs with MPS support
  • cpu_only: No GPU acceleration

Optimization Techniques Applied

The generator automatically applies appropriate optimizations based on your hardware:

  • Memory optimizations (model offloading, attention slicing, VAE slicing)
  • Speed optimizations (torch.compile, optimal dtypes)
  • Hardware-specific optimizations (CUDA, MPS, CPU fallbacks)
  • Model-specific configurations (schedulers, inference parameters)

Example Output

import torch
from diffusers import FluxPipeline

# Optimized for Apple Silicon (MPS)
pipe = FluxPipeline.from_pretrained(
    "black-forest-labs/FLUX.1-schnell", 
    torch_dtype=torch.bfloat16
)
pipe.to("mps")
pipe.enable_attention_slicing()

prompt = "A cat holding a sign that says hello world"
out = pipe(
    prompt=prompt,
    guidance_scale=0.,
    height=768,
    width=1360,
    num_inference_steps=4,
    max_sequence_length=256,
).images[0]
out.save("image.png")