Implementation:AUTOMATIC1111 Stable diffusion webui Hypertile Script
| Knowledge Sources | |
|---|---|
| Domains | Performance_Optimization, Attention, U_Net, VAE |
| Last Updated | 2025-05-15 00:00 GMT |
Overview
A built-in extension script that integrates HyperTile optimization for self-attention layers in U-Net and VAE models, reducing computation time for image generation.
Description
ScriptHypertile is a Script subclass that hooks into the generation pipeline to apply HyperTile optimizations to both the U-Net and VAE models. HyperTile works by tiling the self-attention computation, which can reduce processing time by 1x to 4x, with larger generated images seeing greater benefit. The script configures HyperTile parameters (swap size, max depth, tile size) separately for U-Net and VAE via shared options. It supports separate first-pass and second-pass (hires fix) configurations for U-Net, and records all active HyperTile settings in the generation infotext metadata. The module also registers UI settings under a dedicated "Hypertile" section and adds XYZ grid axis options for parameter sweeping. The configure_hypertile helper function applies the hypertile_hook_model to both the first_stage_model (VAE) and the main model (U-Net), with SDXL awareness.
Usage
Enable HyperTile through Settings > Hypertile. Toggle "Enable Hypertile U-Net" and/or "Enable Hypertile VAE" and adjust max depth, max tile size, and swap size parameters. The optimization is applied automatically during generation. For hires fix workflows, a separate second-pass toggle allows enabling HyperTile only for the upscaling pass.
Code Reference
Source Location
- Repository: AUTOMATIC1111_Stable_diffusion_webui
- File: extensions-builtin/hypertile/scripts/hypertile_script.py
- Lines: 1-122
Signature
class ScriptHypertile(scripts.Script):
name = "Hypertile"
def title(self):
def show(self, is_img2img):
def process(self, p, *args):
def before_hr(self, p, *args):
def add_infotext(self, p, add_unet_params=False):
def configure_hypertile(width, height, enable_unet=True):
def on_ui_settings():
def add_axis_options():
Import
# Loaded automatically as a built-in extension script
# No direct import needed; registered via scripts.Script discovery
import hypertile
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| p | processing.StableDiffusionProcessing | Yes | The processing object containing generation parameters |
| width | int | Yes | Target image width for hypertile configuration |
| height | int | Yes | Target image height for hypertile configuration |
| enable_unet | bool | No | Whether to enable hypertile for U-Net (defaults to shared.opts value) |
Outputs
| Name | Type | Description |
|---|---|---|
| (side effect) | None | Hooks are applied to the model in-place; infotext parameters are added to p.extra_generation_params |
Usage Examples
# Enable via settings UI:
# Settings > Hypertile > Enable Hypertile U-Net = True
# Settings > Hypertile > U-Net max depth = 3
# Settings > Hypertile > U-Net max tile size = 256
# Settings > Hypertile > U-Net swap size = 3
# For XYZ grid parameter sweeps:
# Select "[Hypertile] Unet Max Tile Size" as an axis
# Enter values like "128, 256, 512"
# The script automatically applies during generation when enabled.