{"id":19146490,"url":"https://github.com/kahsolt/stable-diffusion-webui-sonar","last_synced_at":"2026-03-04T06:33:31.782Z","repository":{"id":65540016,"uuid":"564217792","full_name":"Kahsolt/stable-diffusion-webui-sonar","owner":"Kahsolt","description":"Wrapped k-diffuison samplers with tricks to improve the generated image quality (maybe?), extension script for AUTOMATIC1111/stable-diffusion-webui","archived":false,"fork":false,"pushed_at":"2023-10-17T07:00:04.000Z","size":4422,"stargazers_count":114,"open_issues_count":0,"forks_count":11,"subscribers_count":5,"default_branch":"main","last_synced_at":"2025-05-07T02:04:09.225Z","etag":null,"topics":["extensions","stable-diffusion","stable-diffusion-webui-plugin"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Kahsolt.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-11-10T08:47:25.000Z","updated_at":"2025-02-14T17:22:15.000Z","dependencies_parsed_at":"2023-02-15T15:01:03.487Z","dependency_job_id":"0b589031-f379-4a9c-86f3-034d54d847c6","html_url":"https://github.com/Kahsolt/stable-diffusion-webui-sonar","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/Kahsolt/stable-diffusion-webui-sonar","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Kahsolt%2Fstable-diffusion-webui-sonar","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Kahsolt%2Fstable-diffusion-webui-sonar/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Kahsolt%2Fstable-diffusion-webui-sonar/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Kahsolt%2Fstable-diffusion-webui-sonar/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Kahsolt","download_url":"https://codeload.github.com/Kahsolt/stable-diffusion-webui-sonar/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Kahsolt%2Fstable-diffusion-webui-sonar/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":30074201,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-03-04T05:31:57.858Z","status":"ssl_error","status_checked_at":"2026-03-04T05:31:38.462Z","response_time":59,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["extensions","stable-diffusion","stable-diffusion-webui-plugin"],"created_at":"2024-11-09T07:44:19.635Z","updated_at":"2026-03-04T06:33:31.749Z","avatar_url":"https://github.com/Kahsolt.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# stable-diffusion-webui-sonar\n\n    Wrapped k-diffuison samplers with tricks to improve the generated image quality (maybe?), extension script for AUTOMATIC1111/stable-diffusion-webui\n\n----\n\n\u003cp align=\"left\"\u003e\n  \u003ca href=\"https://github.com/Kahsolt/stable-diffusion-webui-sonar/commits\"\u003e\u003cimg alt=\"Last Commit\" src=\"https://img.shields.io/github/last-commit/Kahsolt/stable-diffusion-webui-sonar\"\u003e\u003c/a\u003e\n  \u003ca href=\"https://github.com/Kahsolt/stable-diffusion-webui-sonar/issues\"\u003e\u003cimg alt=\"GitHub issues\" src=\"https://img.shields.io/github/issues/Kahsolt/stable-diffusion-webui-sonar\"\u003e\u003c/a\u003e\n  \u003ca href=\"https://github.com/Kahsolt/stable-diffusion-webui-sonar/stargazers\"\u003e\u003cimg alt=\"GitHub stars\" src=\"https://img.shields.io/github/stars/Kahsolt/stable-diffusion-webui-sonar\"\u003e\u003c/a\u003e\n  \u003ca href=\"https://github.com/Kahsolt/stable-diffusion-webui-sonar/network\"\u003e\u003cimg alt=\"GitHub forks\" src=\"https://img.shields.io/github/forks/Kahsolt/stable-diffusion-webui-sonar\"\u003e\u003c/a\u003e\n  \u003cimg alt=\"Language\" src=\"https://img.shields.io/github/languages/top/Kahsolt/stable-diffusion-webui-sonar\"\u003e\n  \u003cimg alt=\"License\" src=\"https://img.shields.io/github/license/Kahsolt/stable-diffusion-webui-sonar\"\u003e\n  \u003cbr/\u003e\n\u003c/p\u003e\n\nℹ This is the sister repo of [https://github.com/Kahsolt/stable-diffusion-webui-prompt-travel](https://github.com/Kahsolt/stable-diffusion-webui-prompt-travel), it focuses on **single prompt optimization** rather than traveling between multiple prompts. \n\nThe 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. \nTechnically to do this, we hack into the samplers and sampling processing, do some tricks like:\n\n  - momentum on latent difference\n  - txt2img under hard guidance of another given image (yet another img2img-like in a **shallow fusion** manner...)\n\nto get image latents with higher quality (~perhaps!), and just pray again for good results 🤣\n\n⚠ 我们成立了插件反馈 QQ 群: 616795645 (赤狐屿)，欢迎出建议、意见、报告bug等 (w  \n⚠ We have a QQ chat group now: 616795645, any suggeustions, discussions and bug reports are highly wellllcome !!  \n\n\n### Change Log\n\n⚪ Features\n\n- 2023/10/17: work with SDXL models\n- 2023/03/09: switch between two morphs (as AlwaysVisible for working with other scripts, as Script for supporting auto grid search)\n- 2023/03/08: add grid search (free your hands!!)\n- 2023/01/28: add upcale (issue #3)\n- 2023/01/12: remove gradient-related functionality due to webui code change\n- 2022/11/27: add momentum on `Euler`, add hard ref-image guidance on `Naive`\n- 2022/11/20: add an Euler-like `Naive`, the simplest difference-estimation-based sampler with momentum \u0026 gradient\n- 2022/11/18: add momentum on `Euler a`\n\n⚪ Fixups\n\n- 2023/05/09: updates to sd-webui v1.1.0 (issue #14: `TypeError: CFGDenoiser.forward() missing 's_min_uncond'`)\n- 2023/01/28: keep up with webui's updates (issue #4: `NameError: name 'CFGDenoiser' is not defined`)\n- 2023/01/28: keep up with webui's updates of extra-networks\n- 2023/01/12: keep up with webui's updates (issue #2: `AttributeError: 'Options' object has no attribute 'filter_nsfw'`)\n- 2023/01/03: keep up with webui's updates (issue #1: `AttributeError: 'StableDiffusionProcessingTxt2Img' object has no attribute 'firstphase_height'`)\n\n\n### Examples\n\n⚪ momentum\n\n![momentum.png](img/momentum.png)\n\n![grid.jpg](img/grid.jpg)\n\nHow momentum works:\n\n- Basically at each sample step, the denoiser will modify the latent image by a `dx`\n  - using [sd-extension-steps-animation](https://github.com/vladmandic/sd-extension-steps-animation) you can inspect into the sampling process\n  - this `dx` is also to some extent understood as `gradient` or `differential`\n- And the sigma schedule (like `karras`) controls denoiser's step-size (i.e. magnitude of `dx`), to assure the process annealing so that the final output converges at some place\n  - see [damping signal](https://en.wikipedia.org/wiki/Damping#Damped_sine_wave)\n- Momentum mechanism memorizes kind of history of `dx`, and is used to increase (when `pos`) or reduce (when `neg`) the damping magitude\n  - a bit like the `LMS/PLMS` sampler, but works on gradient level\n  - by this way, you can anneal your noisy latent image to some other places nearby (works like subseed...)\n  - by this way, **you could retain some details which is normally taken as noise and removed by a denoiser** (subseed might not be capable for this)\n\n\u003cdel\u003e Parameter tuning reference: \u003c/del\u003e\n\n- set `Momentum (current)` to `1`, this will give you an image without momentum mechanism\n- tune `Momentum (current)` and `Momentum (history)` to see what will vary...\n  - `Momentum (current)` is weighted-accumulated 1st-order gradient, usually should `\u003e= 0.85`\n  - `Momentum (history)` is weighted-accumulated of all higher-than-1st-order gradients \n  - probably keep `Momentum sign = pos` and `Momentum history init = zero`\n  - because other parameters are pure experimental and I could not explain in brief... 🤣\n\n**=\u003e Just run a grid search first:**\n\n- set `Momentum (current) search list` and `Momentum (history) search list`\n- the full syntax is `\u003cstart\u003e:\u003cstop\u003e:\u003cstep\u003e`:\n  - `0.75:0.95:5` =\u003e `[0.75, 0.8, 0.85, 0.9, 0.95]`, when `step \u003e 1` is an int, parse as step count\n  - `0.95:0.75:-0.1` =\u003e `[0.95, 0.85, 0.75]`, when `-1.0 \u003c step \u003c 1.0` is a float, parse as step size\n  - `0.75:0.95` =\u003e `[0.75, 0.85, 0.95]`, by default `step=3`\n  - `0.75` =\u003e `[0.75]`, just one constant\n  - when left empty, will read from the Slider value accordingly\n- run Generate!\n\n\n⚪ ref_img guide\n\n![ref.png](img/ref.png)\n\n⚠ Above images are not intented to show the best results, but showing the trendency. You shall carefully tune these hparams all by yourself to get good results. 🤣\n\nHow hard ref_img guidance works:\n\n- **After** each denoise step, make an extra step towards the given image in latent space\n- It is a kind of shallow fusion, thus ...\n  - in fact needs a carefully step-size scheduling, but not implemented yet :(\n  - when the given condition (the digested prompts) mismatches the ref_img very much, they will fight, and the canvas would be again and again overwriten, giving bad final results 🤣\n\n\n![ui](img/ui.png)\n\n\n### Options\n\n- base_sampler: (categorical)\n  - `Eular a`: `Eular` with ancestral noise sampling\n  - `Eular`: `Eular` the original\n  - `Naive`: a so simple, sometimes naive sampler but to start anything from\n- momentum_*\n  - momentum: (float), momentum of current latent difference\n    - the larger, approving the current difference, (set `1.0` to **disable** momentum mechanism)\n    - the smaller, approving the history difference momentum\n  - momentum_hist: (float), momentum of memorized difference history\n    - the larger, approving current history\n    - the smaller, approving former histories\n  - momentum_hist_init: (categorical), init value of history, aka. the genesis (experimental)\n    - `zero`: use the first denoised latent\n    - `rand_init`: just use the init latent noise \n    - `rand_new`: use a new guassian noise\n  - momentum_sign: (categorical), momentum direction to apply correction (experimental)\n    - `pos`: correct by direction of history momentum, affirming the history\n    - `neg`: correct by opposite direction of history momentum, denying the history\n    - `rand`: random choose from above at each sampling step\n    - NOTE: option `neg` works well only if `momentum_hist` is enough large (`~0.9`)\n- ref_*\n  - ref_img: (file), reference image file\n  - ref_meth: (categorical)\n    - `linear`: linear interpolate between current and ref latent\n    - `euler`: make an eular step from current to ref latent \n  - ref_start_step: (float, int)\n  - ref_stop_step: (float, int)\n    - sampling step range which enables the ref guidance mechanism (kind of scheduling)\n    - if \u003e 1, parse as step number; if \u003c= 1, parse as percentage of total steps\n- upscale_*\n  - upscaler: (categorical)\n  - ratio: (float)\n  - width: (int)\n  - height: (int)\n    - if `width==height==0`, upscale by the specified ratio\n    - if `width==0 or height==0`, the zero one will be auto calculated to match the non-zero one, keeping the aspect-raio\n    - if `width!=0 and height!=0`, upscale while keeping the aspect-raio to cover the target size, then crop the excess if necessary\n\n\n### Developers\n\nThis repo allows your to quickly implement your own k-diffusion samplers, follow to do this:\n\n- creart a sampling procedure `sample_\u003cname\u003e()`, you can refer to the skeleton sampler `sample_naive()`\n- add a `SamplerData` entry in `all_samplers_sonar`\n- design ui components for your sampler hparams in `ui()`, then modify `swith_sampler()` to show/hide related tabs\n- restart webui and play with your own sampler~\n\n\n### Installation\n\nEasiest way to install it is to:\n1. Go to the \"Extensions\" tab in the webui, switch to the \"Install from URL\" tab\n2. Paste https://github.com/Kahsolt/stable-diffusion-webui-sonar.git into \"URL for extension's git repository\" and click install\n\nManual install:\n1. Copy this repo folder to the 'extensions' folder of https://github.com/AUTOMATIC1111/stable-diffusion-webui\n\n----\n\nby Armit\n2022/11/16 \n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkahsolt%2Fstable-diffusion-webui-sonar","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkahsolt%2Fstable-diffusion-webui-sonar","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkahsolt%2Fstable-diffusion-webui-sonar/lists"}