stable-diffusion-webui-sonar
Wrapped k-diffuison samplers with tricks to improve the generated image quality, extension script for AUTOMATIC1111/stable-diffusion-webui
The core idea of Sonar is to search for similar (yet even better!) images in the neighborhood of some known image generated by a normal denoising process. Technically to do this, we hack into the samplers and sampling processing, do some tricks like:
- momentum on latent difference
- sample-wise optimzaton on prompt condition and image latent
- txt2img under hard guidance of another given image (yet another img2img-like in a shallow fusion manner...)
to get image latents with higher quality (~perhaps!), and just pray again for good results
Change Log
- 2022/11/27: add momentum on
Euler
, add hard ref-image guidance onNaive
- 2022/11/20: add an Euler-like
Naive
, the simplest difference-estimation-based sampler with momentum & gradient - 2022/11/18: add momentum on
Euler a
Options
- prompt: (string)
- base_sampler: (categorical)
Eular a
:Eular
with ancestral noise samplingEular
:Eular
the originalNaive
: a so simple, sometimes naive sampler but to start anything from
- momentum_*
- momentum: (float), momentum of current latent difference
- the larger, approving the current difference, (set
1.0
to disable momentum mechanism) - the smaller, approving the history difference momentum
- the larger, approving the current difference, (set
- momentum_hist: (float), momentum of memorized difference history
- the larger, approving current history
- the smaller, approving former histories
- momentum_hist_init: (float), init value of history, aka. the genesis
zero
: use the first denoised latentrand_init
: just use the init latent noiserand_new
: use a new guassian noise
- momentum_sign: (categorical), momentum direction to apply correction
pos
: correct by direction of history momentum, affirming the historyneg
: correct by opposite direction of history momentum, denying the historyrand
: random choose from above at each sampling step- NOTE: option
neg
andpos_neg
works well only ifmomentum_hist
is enough large (~0.9
)
- momentum: (float), momentum of current latent difference
- grad_*
- grad_w_cond: (float), loss weight for optimizing prompt condition
- grad_c_iter: (int), optimizing step count per sampling step for condition
- grad_c_alpha: (float), optimizing step size for condition
- grad_c_skip: (int), skip cond optimizing for the first n-steps
- grad_w_latent: (float), loss weight for optimizing image latent
- grad_x_iter: (int), optimizing step count for latent (this is NOT per sampling step)
- grad_x_alpha: (float), optimizing step size for latent
- grad_fuzzy: (bool), use fuzzy gradient for both
- ref_*
- ref_img: (file), reference image file
- ref_meth: (categorical)
linear
: linear interpolate between current and ref latenteuler
: make an eular step from current to ref latent
- ref_start_step: (float)
- ref_stop_step: (float)
- sampling step range which enables the ref guidance mechanism (kind of scheduling)
- if > 1, parse as step number; if <= 1, parse as percentage of total steps
Developers
This repo allows your to quickly implement your own k-diffusion samplers, follow to do this:
- creart a sampling procedure
sample_<name>()
, you can refer to the skeleton samplersample_naive()
- add a
SamplerData
entry inall_samplers_sonar
- design ui components for your sampler hparams in
ui()
, then modifyswith_sampler()
to show/hide related tabs - restart webui and play with your own sampler~
Installation
Easiest way to install it is to:
- Go to the "Extensions" tab in the webui, switch to the "Install from URL" tab
- Paste https://github.com/Kahsolt/stable-diffusion-webui-sonar.git into "URL for extension's git repository", click "install" button
- Go to the "Installed" tab, click "Apply and Restart UI" button
Manual install:
- Copy this repo folder to the 'extensions' folder of https://github.com/AUTOMATIC1111/stable-diffusion-webui
- Go to the "Settings" tab, click "Restart Gradio and Refresh components" button
by Armit 2022/11/16