{"id":19888287,"url":"https://github.com/wasmedge/wasmedge-stable-diffusion","last_synced_at":"2025-07-20T08:05:04.875Z","repository":{"id":247892372,"uuid":"823955890","full_name":"WasmEdge/wasmedge-stable-diffusion","owner":"WasmEdge","description":"A Rust library for using stable diffusion functions when the Wasi is being executed on WasmEdge.","archived":false,"fork":false,"pushed_at":"2024-10-31T09:35:55.000Z","size":3079,"stargazers_count":11,"open_issues_count":0,"forks_count":3,"subscribers_count":6,"default_branch":"main","last_synced_at":"2025-05-29T05:49:18.440Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/WasmEdge.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"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":"2024-07-04T04:53:54.000Z","updated_at":"2025-02-16T05:59:34.000Z","dependencies_parsed_at":"2024-07-11T06:45:46.585Z","dependency_job_id":"60609038-54d7-4333-9236-2360266b30b5","html_url":"https://github.com/WasmEdge/wasmedge-stable-diffusion","commit_stats":null,"previous_names":["wasmedge/wasmedge-stable-diffusion"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/WasmEdge/wasmedge-stable-diffusion","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/WasmEdge%2Fwasmedge-stable-diffusion","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/WasmEdge%2Fwasmedge-stable-diffusion/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/WasmEdge%2Fwasmedge-stable-diffusion/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/WasmEdge%2Fwasmedge-stable-diffusion/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/WasmEdge","download_url":"https://codeload.github.com/WasmEdge/wasmedge-stable-diffusion/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/WasmEdge%2Fwasmedge-stable-diffusion/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":266087790,"owners_count":23874519,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","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":[],"created_at":"2024-11-12T18:06:49.685Z","updated_at":"2025-07-20T08:05:04.820Z","avatar_url":"https://github.com/WasmEdge.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"# wasmedge-stable-diffusion\nA Rust library for using stable diffusion functions when the Wasi is being executed on WasmEdge.\n## Set up WasmEdge\n\n```Bash\ngit clone https://github.com/WasmEdge/WasmEdge.git\ncd WasmEdge\ncmake -GNinja -Bbuild -DCMAKE_BUILD_TYPE=Release -DWASMEDGE_BUILD_TESTS=OFF -DWASMEDGE_PLUGIN_STABLEDIFFUSION=On -DWASMEDGE_USE_LLVM=OFF\ncmake --build build\nsudo cmake --install build\n```\n\n## Download Model\nDownload the weights or quantized model from the following command.  \nYou also can use our example to quantize the weights by yourself.\n\nstable-diffusion v1.4: [second-state/stable-diffusion-v-1-4-GGUF](https://huggingface.co/second-state/stable-diffusion-v-1-4-GGUF)  \nstable-diffusion v1.5: [second-state/stable-diffusion-v1-5-GGUF](https://huggingface.co/second-state/stable-diffusion-v1-5-GGUF)  \nstable-diffusion v2.1: [second-state/stable-diffusion-2-1-GGUF](https://huggingface.co/second-state/stable-diffusion-2-1-GGUF)\n\n```\ncurl -L -O https://huggingface.co/second-state/stable-diffusion-v-1-4-GGUF/resolve/main/sd-v1-4.ckpt\ncurl -L -O https://huggingface.co/second-state/stable-diffusion-v-1-4-GGUF/resolve/main/stable-diffusion-v1-4-Q8_0.gguf\n```\n\n## Compile example file\nThe compiled `.wasm` file located at `./target/wasm32-wasi/release/`, and named `wasmedge_stable_diffusion_example.wasm`\n```Bash\ncargo build --target wasm32-wasi --release\n```\n\n## Run\nIt supports two mode: txt2img and img2img.\n\n### txt2img\nAssume that the model `stable-diffusion-v-1-4-GGUF` is located in the models folder of the same directory as this project.\n```Bash\nwasmedge --dir .:. ./target/wasm32-wasi/release/wasmedge_stable_diffusion_example.wasm -m ../../models/stable-diffusion-v1-4-Q8_0.gguf -p \"a lovely cat\"\n```\n\u003cp align=\"center\"\u003e\n  \u003cimg src=\"./assets/output.png\" width=\"256x\"\u003e\n\u003c/p\u003e\n\n### img2img\n- `./output.png` is the image generated from the above txt2img pipeline\n```Bash\nwasmedge --dir .:. ./target/wasm32-wasi/release/wasmedge_stable_diffusion_example.wasm --mode img2img -m ../../models/stable-diffusion-v1-4-Q8_0.gguf -p \"cat with red eyes\" -i ./output.png -o ./img2img_output.png\n```\n\u003cp align=\"center\"\u003e\n  \u003cimg src=\"./assets/output2.png\" width=\"256x\"\u003e\n\u003c/p\u003e\n\n### Convert\n- Stable Diffusion model: [sd-v1-4.ckpt](), which type is Q8_0.\n```Bash\nwasmedge --dir .:. ./target/wasm32-wasi/release/wasmedge_stable_diffusion_example.wasm  --mode convert -o stable-diffusion-v1-4-Q8_0_test.gguf -m ../../models/sd-v1-4.ckpt --type q8_0\n```\nIf you want to use the converted model, please use `--type` to asign the type `Q8_0`.\n\n## More Guides - LoRA\n### Get weights\n- LoRA model: [v1-5-pruned-emaonly.safetensors](https://huggingface.co/runwayml/stable-diffusion-v1-5/resolve/main/v1-5-pruned-emaonly.safetensors)\n```Bash\ncurl -L -O https://huggingface.co/runwayml/stable-diffusion-v1-5/resolve/main/v1-5-pruned-emaonly.safetensors\n```\n### txt2img\nYou can specify the directory where the lora weights are stored via `--lora-model-dir`.\nIf not specified, the default is the current working directory.\n```Bash\nwasmedge --dir .:. ./target/wasm32-wasi/release/wasmedge_stable_diffusion_example.wasm \\\n--lora-model-dir ../../lora \\\n--model ../../lora/v1-5-pruned-emaonly.safetensors \\\n-p \"a lovely cat\u003clora:marblesh:1\u003e\" \\\n-o output_lora_txt2img.png\n```\nThe lora model `../../lora/sd_xl_base_1.0.safetensors` and vae model `../../lora/sdxl_vae.safetensors` will be applied to the model.\n\u003cp align=\"center\"\u003e\n  \u003cimg src=\"./assets/output_lora_txt2img.png\" width=\"256x\"\u003e\n\u003c/p\u003e\n\n### img2img\n```Bash\nwasmedge --dir .:. ./target/wasm32-wasi/release/wasmedge_stable_diffusion_example.wasm \\\n-p \"with blue eyes\u003clora:marblesh:1\u003e\" \\\n--lora-model-dir ../../lora \\\n--model ../../lora/v1-5-pruned-emaonly.safetensors \\\n-i output_lora_txt2img.png \\\n-o output_lora_img2img.png\n```\n\u003cp align=\"center\"\u003e\n  \u003cimg src=\"./assets/output_lora_img2img.png\" width=\"256x\"\u003e\n\u003c/p\u003e\n\n## Supported parameters\n```\nusage: wasmedge --dir .:. ./target/wasm32-wasi/release/wasmedge_stable_diffusion_example.wasm [arguments]\n\narguments:\n  -M, --mode [MODEL]                 run mode (txt2img or img2img or convert, default: txt2img)\n  -t, --threads N                    number of threads to use during computation (default: -1).If threads \u003c= 0, then threads will be set to the number of CPU physical cores\n  -m, --model [MODEL]                path to full model\n  --diffusion-model                  path to the standalone diffusion model\n  --clip_l                           path to the clip-l text encoder\n  --t5xxl                            path to the the t5xxl text encoder\n  --vae [VAE]                        path to vae\n  --taesd [TAESD_PATH]               path to taesd. Using Tiny AutoEncoder for fast decoding (low quality)\n  --control-net [CONTROL_PATH]       path to control net model\n  --embd-dir [EMBEDDING_PATH]        path to embeddings\n  --stacked-id-embd-dir [DIR]        path to PHOTOMAKER stacked id embeddings\n  --input-id-images-dir [DIR]        path to PHOTOMAKER input id images dir\n  --normalize-input                  normalize PHOTOMAKER input id images\n  --upscale-model [ESRGAN_PATH]      path to esrgan model. Upscale images after generate, just RealESRGAN_x4plus_anime_6B supported by now\n  --upscale-repeats                  Run the ESRGAN upscaler this many times (default 1)\n  --type [TYPE]                      weight type (f32, f16, q4_0, q4_1, q5_0, q5_1, q8_0, q2_k, q3_k, q4_k)\n                                     If not specified, the default is the type of the weight file\n  --lora-model-dir [DIR]             lora model directory\n  -i, --init-img [IMAGE]             path to the input image, required by img2img\n  --control-image [IMAGE]            path to image condition, control net\n  -o, --output OUTPUT                path to write result image to (default: ./output.png)\n  -p, --prompt [PROMPT]              the prompt to render\n  -n, --negative-prompt PROMPT       the negative prompt (default: \"\")\n  --cfg-scale SCALE                  unconditional guidance scale: (default: 7.0)\n  --strength STRENGTH                strength for noising/unnoising (default: 0.75)\n  --style-ratio STYLE-RATIO          strength for keeping input identity (default: 20%)\n  --control-strength STRENGTH        strength to apply Control Net (default: 0.9)\n                                     1.0 corresponds to full destruction of information in init image\n \n  --guidance                         guidance\n  -H, --height H                     image height, in pixel space (default: 512)\n  -W, --width W                      image width, in pixel space (default: 512)\n  --sampling-method {euler, euler_a, heun, dpm2, dpm++2s_a, dpm++2m, dpm++2mv2, ipndm, ipndm_v, lcm}\n                                     sampling method (default: \"euler_a\")\n  --steps  STEPS                     number of sample steps (default: 20)\n  --rng {std_default, cuda}          RNG (default: cuda)\n  -s SEED, --seed SEED               RNG seed (default: 42, use random seed for \u003c 0)\n  -b, --batch-count COUNT            number of images to generate\n  --schedule {discrete, karras, exponential, ays, gits} Denoiser sigma schedule (default: discrete)\n  --clip-skip N                      ignore last layers of CLIP network; 1 ignores none, 2 ignores one layer (default: -1)\n                                     \u003c= 0 represents unspecified, will be 1 for SD1.x, 2 for SD2.x\n  --vae-tiling                       process vae in tiles to reduce memory usage\n  --vae-on-cpu                       keep vae in cpu (for low vram)\n  --clip-on-cpu                      keep clip in cpu (for low vram)\n  --control-net-cpu                  keep controlnet in cpu (for low vram)\n  --canny                            apply canny preprocessor (edge detection)\n```\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwasmedge%2Fwasmedge-stable-diffusion","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fwasmedge%2Fwasmedge-stable-diffusion","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwasmedge%2Fwasmedge-stable-diffusion/lists"}