Home

Awesome

Stable Diffusion Infinity Grid Generator

img

Concept

Extension for the AUTOMATIC1111 Stable Diffusion WebUI that generates infinite-dimensional grids.

An "infinite axis grid" is like an X/Y plot grid, but with, well, more axes on it. Of course, monitors are 2D, so this is implemented in practice by generating a webpage that lets you select which two primary axes to display, and then choose the current value for each of the other axes.

Goals and Use Cases

The primary goal is to let people generate their own fancy grids to explore how different settings affect their renders in a convenient form.

Another goal of this system is to develop educational charts, to provide a universal answer to the classic question of "what does (X) setting do? But what about with (Y)?" - The MegaGrid. There is a built in ability to add description text to fields, for the specific purpose of enhancing educational page output.

Pros/Cons

The advantage of this design is it allows you to rapidly compare the results of different combinations of settings, without having to wait to for generation times for each specific sub-grid as-you-go - you just run it all once in advance (perhaps overnight for a large run), and then after that browse through it in realtime.

The disadvantage is that time to generate a grid is exponential - if you have 5 samplers, 5 seeds, 5 step counts, 5 CFG scales... that's 5^4, or 625 images. Add another variable with 5 options and now it's 3125 images. You can see how this quickly jumps from a two minute render to a two hour render.


Table of Contents


Examples

Here's a big MegaGrid using almost every mode option in one, with detailed educational descriptions on every part: https://sd.mcmonkey.org/megagrid/

Here's a very small web demo you can try to test how the output looks and works: https://mcmonkeyprojects.github.io/short_example and you can view the generated asset files for that demo here.

img


Status

Current overall project status (as of December 2023): Works well, actively maintained. Has been generally well tested. The core has been ported to other environments and stress-tested for multiple real projects that depend on large grids and rapid grid analysis.

A version of this project is also available for StableSwarmUI, here which also lets you use it with Comfy and other backends


Installation


Basic Usage

img


Advanced Usage

Usage comes in three main steps:


1: Grid Definition File

img

If you do not want to follow an example file:

Micro example:

grid:
    title: Tiny example
    author: someone
    description: This is just to show core format. View the example `.yml` files in assets for better examples.
    format: jpg
axes:
    sampler: Euler, DDIM
    seed: 1, 2, 3

Settings supported for parameters

NameTypeExampleNotes
SamplerNamedDDIM, euler, ...
ModelFilenamesd-v1-5Note that Model and VAE are global settings, and as such you should not have an axis where some values specify one of those params but others don't, as this will cause an unpredictable model selection for the values that lack specificity.
VAEFilenamekl-f8-anime2See note on Model above
PromptTexta cat
Negative PromptTextgross, weird, bad
Prompt ReplaceText-Pairsome_tag = new text hereNote the = symbol to separate the original text with the new text. That will change a prompt of for example my prompt with some_tag stuff to my prompt with new text here stuff.<br>Unlike other modes, the PromptReplace is case-sensitive - if you use capitals in your prompt, you need capitals in your replace matcher.<br>If you want multiple replacements in one value, you can number them, like Prompt Replace 1 and Prompt Replace 2 and etc.<br>When building a simple list in UI, you can just do eg cat, dog, waffle and it will understand to replace cat in the base prompt first with cat, then dog, then waffle (ie you can skip the = for simple usages).
StylesTextphoto, cartoon, ...Automatically includes UI styles to your prompt. Can use comma-separated list to have multiple. Note this means in the UI you can do for example `photo, cinematic
SeedInteger1, 2, 3, ...
StepsInteger20, 50, ...
CFG ScaleDecimal5, 7.5, 12, ...
WidthInteger512, 768, ...Initial generation width.
HeightInteger512, 768, ...Initial generation height.
Out WidthInteger512, 768, ...What resolution to save the image as (if unspecified, uses Width). Useful to save filespace.
Out HeightInteger512, 768, ...Refer to Out Width.
Clip SkipInteger1, 2Use 2 for NAI-like models, 1 for the rest.
Var SeedInteger0, 1, ...Variation seed, use with Var Strength.
Var StrengthDecimal0, 0.5, ..., 1Variation seed strength.
Restore FacesNamedtrue, false, GFPGan, CodeFormerLimited to the given example inputs only.
CodeFormer WeightDecimal0, 0.5, ..., 1Only applicable if Restore Faces is set to CodeFormer.
DenoisingDecimal0, 0.5, ..., 1Denoising strength for img2img or HR fix.
ETADecimal0, 0.5, ..., 1?
ETA Noise Seed DeltaInteger0, 31337use 31337 to replicate NovelAI results, use 0 for anything else. Not very useful.
Sigma ChurnDecimal0, 0.5, ..., 1Sampler parameter, rarely used.
Sigma TminDecimal0, 0.5, ..., 1Sampler parameter, rarely used.
Sigma TmaxDecimal0, 0.5, ..., 1Sampler parameter, rarely used.
Sigma NoiseDecimal0, 0.5, ..., 1Sampler parameter, rarely used.
TilingBooleantrue, falseUseful for textures.
Image Mask WeightDecimal0, 0.5, ..., 1Conditional image mask weight. Only applies to img2img or HR fix.
Enable Highres FixBooleantrue, falseRequired for other HR settings to work. Defaults denoising strength to 0.75 if not specified. Only valid in txt2img.
Highres ScaleDecimal2, 2.5, ..., 16How much to scale by for HR fix.
Highres StepsInteger20, 50, ...Secondary steps for HR fix.
Highres UpscalerNamedNone, Latent, ...Upscaler mode to use prior to running Highres Fix.
Highres Resize WidthInteger512, 768, ...Resolution to target as final output size for Highres Fix, overrides Highres Scale.
Highres Resize HeightInteger512, 768, ...See Highres Resize Width above.
Highres Upscale To WidthInteger512, 768, ...Resolution to upscale to prior to running Highres Fix.
Highres Upscale To HeightInteger512, 768, ...See Highres Upscale To Height above.
Image CFG ScaleDecimal5, 7.5, 12, ...Image CFG Scale, for Instruct pix2pix usage.
Use Result IndexInteger0, 1, ...Special trick to get a non-zero result image index, eg for ControlNet secondary output image.

Supported Extensions

Dynamic Thresholding (CFG Scale Fix)

Extension docs: https://github.com/mcmonkeyprojects/sd-dynamic-thresholding

NameTypeExampleNotes
DynamicThreshold EnableBooleantrue, false
DynamicThreshold Mimic ScaleDecimal5, 7.5, 12, ...
DynamicThreshold Threshold PercentileDecimal0, 0.5, ..., 1.0
DynamicThreshold Mimic ModeNamedConstant, Linear Down, Cosine Down, Half Cosine Down, Linear Up, Cosine Up, Half Cosine Up, Power Up
DynamicThreshold CFG ModeNamedConstant, Linear Down, Cosine Down, Half Cosine Down, Linear Up, Cosine Up, Half Cosine Up, Power Up
DynamicThreshold Mimic Scale MinimumDecimal5, 7.5, 12, ...
DynamicThreshold CFG Scale MinimumDecimal5, 7.5, 12, ...
DynamicThreshold Power ValueDecimal2, 4, ...For Power Up mode only.
DynamicThreshold Scaling StartpointNamedZERO, MEAN
DynamicThreshold Variability MeasureNamedSTD, AD
DynamicThreshold Interpolate PhiDecimal0, 0.5, ..., 1.0
DynamicThreshold Separate Feature ChannelsBooleantrue, false

ControlNet

Extension docs: https://github.com/Mikubill/sd-webui-controlnet

Note: must enable Allow other script to control this extension in Settings -> ControlNet

NameTypeExampleNotes
ControlNet EnableBooleantrue, false
ControlNet PreprocessorNamednone, canny, depth, hed, mlsd, normal_map, openpose, openpose_hand, pidinet, scribble, fake_scribble, segmentation
ControlNet ModelNameddiff_control_sd15_canny_fp16, ...
ControlNet WeightDecimal0.0, 0.5, ..., 2.0
ControlNet Guidance StrengthDecimal0.0, 0.5, ..., 1.0
ControlNet Annotator ResolutionInteger64, 512, ..., 2048
ControlNet Threshold AInteger64, 512, ..., 256
ControlNet Threshold BInteger64, 512, ..., 256
ControlNet ImageTextpose.png, otherpose.jpg, ...Put image files in (EXTENSION FOLDER)/assets/images/, as png, jpg, or webp. Subfolders allowed.

Other Extensions

# Verify grid extension is present
import importlib
if importlib.util.find_spec("gridgencore") is not None:
    import gridgencore
    from gridgencore import GridSettingMode
    # p is the SD processing object, v is the value
    def apply(p, v):
        p.some_setting_here = v
    # dry: bool, type: str, apply: callable, min: float = None, max: float = None, clean: callable = None
    gridgencore.registerMode("mySettingNameHere", GridSettingMode(True, "text", apply))
    # for apply if the param is a 'p' field, you can use gridgencore.apply_field("fieldname")

2: Grid Content Generation via WebUI

img


3: Using The Output

img


4: Expanding Later

If you want to add more content to a grid you already made, you can do that:


Credits


Common Issues

  File "stable-diffusion-webui\modules\images.py", line 508, in _atomically_save_image
    image_format = Image.registered_extensions()[extension]
KeyError: '.jpg'

If you have this error, just hit generate again. I'm not sure why it happens, it just does at random sometimes on the first time the WebUI starts up. It seems to happen when you use OutWidth/OutHeight settings and is prevented by running any generation without a custom out-resolution. Might be some required initialization is getting skipped when an image is rescaled?


Licensing pre-note:

This is an open source project, provided entirely freely, for everyone to use and contribute to.

If you make any changes that could benefit the community as a whole, please contribute upstream.

The short of the license is:

You can do basically whatever you want, except you may not hold any developer liable for what you do with the software.

The long version of the license follows:

The MIT License (MIT)

Copyright (c) 2022-2023 Alex "mcmonkey" Goodwin

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.