How xugao97/attentiondistillation works
Purpose and Entry Points
This repository implements Attention Distillation for transferring visual characteristics in diffusion generation: texture synthesis, style/appearance transfer, and style-specific text-to-image generation. Primary interactive entry points are ad.ipynb, app.py, and the Flux notebook flux_ad/main.ipynb. VAE fine-tuning is launched through train_vae.py.
Diffusion Pipeline Layer
Custom Stable Diffusion pipelines encapsulate the denoising-time attention manipulation used by the method. pipeline_sd.py targets SD 1.5-class models; pipeline_sdxl.py provides the SDXL variant. These are the main model-runtime boundary over Hugging Face Diffusers and PyTorch.
Attention-Distillation Objectives
Loss definitions and shared computation utilities support optimization of visual characteristics from image references. losses.py is the central objective layer, while utils.py provides shared image/model utilities. The data inputs are organized by characteristic type under data/content, data/style, and data/texture.
Generation Workflows
The notebook-driven workflow in ad.ipynb exposes the three SD-based use cases: optimize or extract the target visual signal, then invoke the custom pipeline to generate an image matching it. SD and SDXL are selected through the separate pipeline implementations rather than through a single generic runtime.
Flux Workflow
A parallel Flux.1-dev implementation supports style-specific text-to-image generation. flux_ad/mypipeline.py is its custom pipeline layer, with supporting routines in flux_ad/utils.py; flux_ad/main.ipynb is its execution entry point. This is a distinct model-family boundary from the Diffusers SD/SDXL paths.
VAE Fine-Tuning
train_vae.py trains or fine-tunes a VAE from an image path and an existing VAE model path. The resulting VAE can improve reconstruction or generation behavior for the transfer workflow, but is operationally separate from inference pipelines.
Web UI Runtime
app.py starts a local UI server on port 7860. The UI is composed around task-specific tabs: webui/tab_texture_synthesis.py, webui/tab_style_transfer.py, and webui/tab_style_t2i.py. webui/runner.py is the likely execution bridge from UI inputs to model/pipeline calls. Material runtime dependencies are Python 3.10, PyTorch 2.5, and Diffusers 0.32; model weights are external inputs rather than repository-contained services.
Main entry points: losses.py Attention objectives · runner.py UI runner · ad.ipynb AD notebook · app.py UI server
Components 18
SD Attention Distillation
Stable Diffusion and SDXL optimization and inference.
- AD notebook · Runs texture, style transfer, and style-specific T2I workflows.
ad.ipynb - SD 1.5 pipeline · Denoising-time attention manipulation for SD 1.5-class models.
pipeline_sd.py - SDXL pipeline · SDXL-specific attention-distillation runtime.
pipeline_sdxl.py - Attention objectives · Central visual-characteristic optimization objectives.
losses.py - Shared utilities
utils.py - Content references
data/content - Style references
data/style - Texture references
data/texture
Web UI
Local task-oriented interface.
- UI server · Starts the local interface on port 7860.
app.py - Texture synthesis tab
webui/tab_texture_synthesis.py - Style transfer tab
webui/tab_style_transfer.py - Style T2I tab
webui/tab_style_t2i.py - UI runner · Routes UI task inputs to model workflows.
webui/runner.py
Flux Workflow
Separate Flux.1-dev model-family path.
- Flux notebook · Runs Flux style-specific text-to-image generation.
flux_ad/main.ipynb - Flux custom pipeline
flux_ad/mypipeline.py - Flux utilities
flux_ad/utils.py
VAE Fine-Tuning
Independent VAE training path.
- VAE training · Trains or fine-tunes a VAE from images and an existing VAE.
train_vae.py
Other components
- External model weights · Diffusion and VAE weights are supplied outside the repository.
Connections 21
- AD notebook → Attention objectives: optimizes
- AD notebook → SD 1.5 pipeline: generates with
- AD notebook → SDXL pipeline: generates with
- Attention objectives → Shared utilities: uses
- Attention objectives → Content references: reads
- Attention objectives → Style references: reads
- Attention objectives → Texture references: reads
- SD 1.5 pipeline → External model weights: loads
- SDXL pipeline → External model weights: loads
- UI server → Texture synthesis tab: hosts
- UI server → Style transfer tab: hosts
- UI server → Style T2I tab: hosts
- Texture synthesis tab → UI runner: submits to
- Style transfer tab → UI runner: submits to
- Style T2I tab → UI runner: submits to
- UI runner → SD 1.5 pipeline: invokes
- UI runner → SDXL pipeline: invokes
- Flux notebook → Flux custom pipeline: runs
- Flux custom pipeline → Flux utilities: uses
- Flux custom pipeline → External model weights: loads
- VAE training → External model weights: loads and produces · Consumes an existing VAE and produces fine-tuned weights.