|
--- |
|
title: Multi-Resolution Sampling/Scheduling Improves Image Consistency |
|
author: yoinked |
|
tags: image, diffusion, sampling, scheduler, sampler |
|
abstract: sampling at multiple resolutions in the sampler improves outputs at out-of-distribution resolution, effectively doubling |
|
date_published: 2024-09-24 |
|
paperid: 2024-0924.1 |
|
--- |
|
# Multi-Resolution Sampling/Scheduling Improves Image Consistency |
|
## 1. Abstract |
|
In this paper, we will present a novel technique for sampling diffusion models, in which the model's effective resolution can be doubled or even tripled. We also present a new series of schedulers which, can improve sampling efficiency by enhancing the sampler's strength in the middle steps of the generation process. These tools are presented in code samples available [here](https://gist.github.com/yoinked-h/c2f5eafcee5a1f8c962deac47a29ce6a). |
|
|
|
## 2. Methodology |
|
|
|
### 2.1 Sampler |
|
The sampler we present is based on DPM++ 2S Ancestral, with 2 modifications; the first is that we implement CFG++, which enables us to use a lower Classifier Free Guidance value for inference, which leads to better prompt adherence; the second modification is our novel method of improving the model's consistency at higher resolutions. The method involves down-sampling the base latent [denoted as `Lin`], which, while it is a "lossy" procedure, still enables for the model to understand those usable latents. Afterwards, we pass the down-sampled latent [denoted `LDW`] through the diffusion model, which, in higher resolution cases, will result in a more consistent latent, due to the model having been trained on that lower resolution. After the first model call, we up-sample `LDW` and merge it with `Lin` at a ratio of `M`, which is simply defined as the root of the current step number divided by the total number of steps. Once the latents are merged [denoted as `LM`], we pass that into the diffusion model again, to get rid of the up-sampling abnormalities and to refine it at the higher resolution whilst having a consistent base. [All denoted in the diagram below.] |
|
![image](https://huggingface.co/datasets/yoinked/blue-arxiv-papers/resolve/main/uploads/multires-diagram.png) |
|
|
|
### 2.2 Scheduler |
|
The schedulers we present help to assist the sampler mentioned above, by providing with a higher sigma value during middle steps, effectively increasing the strength of the model, whilst retaining the consistency of the multi-res sampling. The following 3 schedulers are the best schedulers for this sampler we've tested: |
|
|
|
#### Sinusoidal scheduler with scaling factor (sinsf) |
|
This scheduler is the "angriest" scheduler out of the 3, in other words, the scheduler that decreases the fastest at the start. While this attribute may sound un-optimal, some popular schedulers are also angry, most notably, the exponential scheduler. The scheduler is defined as `( ( ( sigma_min + ( sigma_max - sigma_min ) * ( 1 - sin( π / 2 * x ) ) ) / sigma_max ) ** sf ) * sigma_max`, in which `x` is defined as a list of numbers from [0 - 1] (inclusive) of length `N`, which is the number of steps, and in which `sf` is equal to the scaling factor provided, usually around 3 for `sinsf`. |
|
|
|
#### Inverse cosinusoidal scheduler with scaling factor (invsf) |
|
This scheduler is designed as being a mid-step between `sinsf` and `dynsf`, which attempts to be more like the most used Karras scheduler. The scheduler is defined as `( ( ( sigma_min + ( sigma_max - sigma_min ) * ( 0.5 * ( cos( x * π ) + 1 ) ) ) / sigma_max ) ** sf ) * sigma_max`, in which `x` is defined as a list of numbers from [0 - 1] (inclusive) of length `N`, which is the number of steps, and in which `sf` is equal to the scaling factor provided, usually around 3 for `invsf`. |
|
|
|
#### Reactive cosinusoidal scheduler with scaling factor (dynsf) |
|
This scheduler is the "calmest" scheduler out of the 3, in other words, the scheduler that decreases the slowest at the start. The scheduler is defined as `( ( ( sigma_min + ( sigma_max - sigma_min ) * ( cos( x * ( π/2 ) ) ) )/sigma_max ) ** sf ) * sigma_max`, in which `x` is defined as a list of numbers from [0 - 1] (inclusive) of length `N`, which is the number of steps, and in which `sf` is equal to the scaling factor provided, usually around 4 for `dynsf`. |
|
|
|
![image](https://huggingface.co/datasets/yoinked/blue-arxiv-papers/resolve/main/uploads/multires-schedulers.png) |
|
|
|
## 3. Results |
|
We tested the sampler by generating images outside of its "attention range" (for sd1.x it is 768x768 pixels), in this example, we ran a generation on an image of size 1024x1792; the sampler we used to compare against was DPM++ 2S Ancestral CFG++, so the only difference in the sampler should be the new internal up-sampling. We used `invsf` for our scheduler of choice, as it still helps non-internal samplers. |
|
![image](https://huggingface.co/datasets/yoinked/blue-arxiv-papers/resolve/main/uploads/multires-genexample.png) |
|
The deformities (multiple bodies/torsos) in the first image are caused due to the model not capturing enough in its "attention range" for it to understand how the main feature of the image should appear. |
|
|
|
## 4. Conclusion |
|
In conclusion, our proposed new sampler (labled `dpmpp_2s_ancestral_cfgpp_intern`) attempts to solve some shortcomings of regular Stable Diffusion models, in which the model "forgets" where parts of the main subject should go. We solved it by down-sampling latents before calling it to the model, this does leave the downside of suffering on smaller resolutions, as we would effectively down-sample too far and be left with near-unworkable latents once we up-sampled. We also presented 3 new schedulers, each with their use-cases, improving image quality on all samplers, but mainly on our proposed sampler. |