Go to file
layerdiffusion 447f261154 fix
2024-08-15 01:56:21 -07:00
backend disable xformers for t5 2024-08-15 00:55:49 -07:00
embeddings add embeddings dir 2022-09-30 14:16:26 +03:00
extensions delete the submodule dir (why do you keep doing this) 2022-10-29 09:02:02 +03:00
extensions-builtin revise 2024-08-13 15:13:39 -07:00
html Gradio 4 + WebUI 1.10 2024-07-26 12:02:46 -07:00
javascript resolve t2i upscale button #882 #874 2024-07-28 07:59:53 -06:00
k_diffusion link k-diffusion to backend 2024-08-07 18:44:53 -07:00
localizations Remove old localizations from the main repo. 2022-11-08 10:01:27 +03:00
models Create text encoder folder 2024-08-05 21:30:24 -07:00
modules fix 2024-08-15 01:56:21 -07:00
modules_forge fix 2024-08-15 01:56:21 -07:00
packages_3rdparty remove unused files 2024-08-15 01:47:59 -07:00
scripts Gradio 4 + WebUI 1.10 2024-07-26 12:02:46 -07:00
_typos.toml Gradio 4 + WebUI 1.10 2024-07-26 12:02:46 -07:00
.eslintignore Ignore ControlNet extension in eslint (#136) 2024-02-08 19:48:49 -05:00
.eslintrc.js Gradio 4 + WebUI 1.10 2024-07-26 12:02:46 -07:00
.git-blame-ignore-revs Add .git-blame-ignore-revs 2023-05-19 12:34:06 +03:00
.gitignore Update .gitignore 2024-07-29 17:55:44 -06:00
.pylintrc Add basic Pylint to catch syntax errors on PRs 2022-10-15 16:26:07 +03:00
CHANGELOG.md sync change log 2024-07-27 06:47:04 -07:00
CITATION.cff citation mk2 2023-08-21 15:27:04 +03:00
CODEOWNERS Update CODEOWNERS 2024-01-25 17:02:35 -08:00
download_supported_configs.py upload Schnell support files 2024-08-11 17:31:12 -07:00
environment-wsl2.yaml update xformers 2023-04-03 15:23:35 -04:00
launch.py Add --forge-ref-a1111-home cmd arg to reference existing A1111 checkout (#203) 2024-02-11 21:22:31 -05:00
LICENSE.txt license 2024-08-08 20:51:12 -07:00
package.json Add basic ESLint configuration for formatting 2023-05-17 16:09:06 +03:00
pyproject.toml Gradio 4 + WebUI 1.10 2024-07-26 12:02:46 -07:00
README.md Update README.md 2024-08-13 22:31:38 -07:00
requirements_versions.txt integrate llama3's GGUF 2024-08-15 01:45:29 -07:00
script.js Gradio 4 + WebUI 1.10 2024-07-26 12:02:46 -07:00
style.css support all flux models 2024-08-13 05:42:17 -07:00
styles_integrated.csv forge 2.0.0 2024-08-10 19:24:19 -07:00
webui-macos-env.sh Gradio 4 + WebUI 1.10 2024-07-26 12:02:46 -07:00
webui-user.bat Fix command line arguments format in webui-user.bat (#135) 2024-02-08 19:47:42 -05:00
webui-user.sh Vendor in the single module used from taming_transformers; remove taming_transformers dependency 2023-05-30 12:47:57 +03:00
webui.bat Gradio 4 + WebUI 1.10 2024-07-26 12:02:46 -07:00
webui.py Gradio 4 + WebUI 1.10 2024-07-26 12:02:46 -07:00
webui.sh Gradio 4 + WebUI 1.10 2024-07-26 12:02:46 -07:00

Stable Diffusion WebUI Forge

Stable Diffusion WebUI Forge is a platform on top of Stable Diffusion WebUI (based on Gradio ) to make development easier, optimize resource management, speed up inference, and study experimental features.

The name "Forge" is inspired from "Minecraft Forge". This project is aimed at becoming SD WebUI's Forge.

Forge is currently based on SD-WebUI 1.10.1 at this commit. (Because original SD-WebUI is almost static now, Forge will sync with original WebUI every 90 days, or when important fixes.)

Installing Forge

If you are proficient in Git and you want to install Forge as another branch of SD-WebUI, please see here. In this way, you can reuse all SD checkpoints and all extensions you installed previously in your OG SD-WebUI, but you should know what you are doing.

If you know what you are doing, you can install Forge using same method as SD-WebUI. (Install Git, Python, Git Clone the forge repo https://github.com/lllyasviel/stable-diffusion-webui-forge.git and then run webui-user.bat).

Or you can just use this one-click installation package (with git and python included).

>>> Click Here to Download One-Click Package (CUDA 12.1 + Pytorch 2.3.1) <<<

Some other CUDA/Torch Versions:

Forge with CUDA 12.1 + Pytorch 2.3.1 <- Recommended

Forge with CUDA 12.4 + Pytorch 2.4 <- Fastest, but MSVC may be broken, xformers may not work

Forge with CUDA 12.1 + Pytorch 2.1 <- the previously used old environments

After you download, you uncompress, use update.bat to update, and use run.bat to run.

Note that running update.bat is important, otherwise you may be using a previous version with potential bugs unfixed.

image

Previous Versions

You can download previous versions here.

Forge Status

Based on manual test one-by-one:

Component Status Last Test
Basic Diffusion Normal 2024 July 27
GPU Memory Management System Normal 2024 July 27
LoRAs Normal 2024 July 27
All Preprocessors Normal 2024 July 27
All ControlNets Normal 2024 July 27
All IP-Adapters Normal 2024 July 27
All Instant-IDs Normal 2024 July 27
All Reference-only Methods Normal 2024 July 27
All Integrated Extensions Normal 2024 July 27
Popular Extensions (Adetailer, etc) Normal 2024 July 27
Gradio 4 UIs Normal 2024 July 27
Gradio 4 Forge Canvas Normal 2024 July 27
LoRA/Checkpoint Selection UI for Gradio 4 Normal 2024 July 27
Photopea/OpenposeEditor/etc for ControlNet Normal 2024 July 27
Wacom 128 level touch pressure support for Canvas Normal 2024 July 15
Microsoft Surface touch pressure support for Canvas Broken, pending fix 2024 July 29

Feel free to open issue if anything is broken and I will take a look every several days. If I do not update this "Forge Status" then it means I cannot reproduce any problem. In that case, fresh re-install should help most.

UnetPatcher

Below are self-supported single file of all codes to implement FreeU V2.

See also extension-builtin/sd_forge_freeu/scripts/forge_freeu.py:

import torch
import gradio as gr

from modules import scripts


def Fourier_filter(x, threshold, scale):
    # FFT
    x_freq = torch.fft.fftn(x.float(), dim=(-2, -1))
    x_freq = torch.fft.fftshift(x_freq, dim=(-2, -1))

    B, C, H, W = x_freq.shape
    mask = torch.ones((B, C, H, W), device=x.device)

    crow, ccol = H // 2, W // 2
    mask[..., crow - threshold:crow + threshold, ccol - threshold:ccol + threshold] = scale
    x_freq = x_freq * mask

    # IFFT
    x_freq = torch.fft.ifftshift(x_freq, dim=(-2, -1))
    x_filtered = torch.fft.ifftn(x_freq, dim=(-2, -1)).real

    return x_filtered.to(x.dtype)


def patch_freeu_v2(unet_patcher, b1, b2, s1, s2):
    model_channels = unet_patcher.model.diffusion_model.config["model_channels"]
    scale_dict = {model_channels * 4: (b1, s1), model_channels * 2: (b2, s2)}
    on_cpu_devices = {}

    def output_block_patch(h, hsp, transformer_options):
        scale = scale_dict.get(h.shape[1], None)
        if scale is not None:
            hidden_mean = h.mean(1).unsqueeze(1)
            B = hidden_mean.shape[0]
            hidden_max, _ = torch.max(hidden_mean.view(B, -1), dim=-1, keepdim=True)
            hidden_min, _ = torch.min(hidden_mean.view(B, -1), dim=-1, keepdim=True)
            hidden_mean = (hidden_mean - hidden_min.unsqueeze(2).unsqueeze(3)) / (hidden_max - hidden_min).unsqueeze(2).unsqueeze(3)

            h[:, :h.shape[1] // 2] = h[:, :h.shape[1] // 2] * ((scale[0] - 1) * hidden_mean + 1)

            if hsp.device not in on_cpu_devices:
                try:
                    hsp = Fourier_filter(hsp, threshold=1, scale=scale[1])
                except:
                    print("Device", hsp.device, "does not support the torch.fft.")
                    on_cpu_devices[hsp.device] = True
                    hsp = Fourier_filter(hsp.cpu(), threshold=1, scale=scale[1]).to(hsp.device)
            else:
                hsp = Fourier_filter(hsp.cpu(), threshold=1, scale=scale[1]).to(hsp.device)

        return h, hsp

    m = unet_patcher.clone()
    m.set_model_output_block_patch(output_block_patch)
    return m


class FreeUForForge(scripts.Script):
    sorting_priority = 12  # It will be the 12th item on UI.

    def title(self):
        return "FreeU Integrated"

    def show(self, is_img2img):
        # make this extension visible in both txt2img and img2img tab.
        return scripts.AlwaysVisible

    def ui(self, *args, **kwargs):
        with gr.Accordion(open=False, label=self.title()):
            freeu_enabled = gr.Checkbox(label='Enabled', value=False)
            freeu_b1 = gr.Slider(label='B1', minimum=0, maximum=2, step=0.01, value=1.01)
            freeu_b2 = gr.Slider(label='B2', minimum=0, maximum=2, step=0.01, value=1.02)
            freeu_s1 = gr.Slider(label='S1', minimum=0, maximum=4, step=0.01, value=0.99)
            freeu_s2 = gr.Slider(label='S2', minimum=0, maximum=4, step=0.01, value=0.95)

        return freeu_enabled, freeu_b1, freeu_b2, freeu_s1, freeu_s2

    def process_before_every_sampling(self, p, *script_args, **kwargs):
        # This will be called before every sampling.
        # If you use highres fix, this will be called twice.

        freeu_enabled, freeu_b1, freeu_b2, freeu_s1, freeu_s2 = script_args

        if not freeu_enabled:
            return

        unet = p.sd_model.forge_objects.unet

        unet = patch_freeu_v2(unet, freeu_b1, freeu_b2, freeu_s1, freeu_s2)

        p.sd_model.forge_objects.unet = unet

        # Below codes will add some logs to the texts below the image outputs on UI.
        # The extra_generation_params does not influence results.
        p.extra_generation_params.update(dict(
            freeu_enabled=freeu_enabled,
            freeu_b1=freeu_b1,
            freeu_b2=freeu_b2,
            freeu_s1=freeu_s1,
            freeu_s2=freeu_s2,
        ))

        return

See also Forge's Unet Implementation.

Under Construction

WebUI Forge is now under some constructions, and docs / UI / functionality may change with updates.