{"id":765,"date":"2023-02-07T19:00:00","date_gmt":"2023-02-07T18:00:00","guid":{"rendered":"https:\/\/www.anginf.de\/?p=765"},"modified":"2023-02-08T12:55:42","modified_gmt":"2023-02-08T11:55:42","slug":"stable-diffusion-on-wsl-on-windows","status":"publish","type":"post","link":"https:\/\/www.anginf.de\/?p=765","title":{"rendered":"Stable Diffusion on WSL on Windows"},"content":{"rendered":"\n<p>First install WSL2 as suggested by the many different websites out there. I installed it like this:<\/p>\n\n\n\n<pre class=\"wp-block-code has-dark-gray-color has-text-color\"><code lang=\"powershell\" class=\"language-powershell\">wsl --install -d Ubuntu-22.04<\/code><\/pre>\n\n\n\n<p>Open the installed Ubuntu and install the necessary packages for stable diffusion itself:<\/p>\n\n\n\n<pre id=\"block-63b5d5ae-a31d-4b74-9cbc-0f9e85d6c6eb\" class=\"wp-block-code has-dark-gray-color has-text-color\"><code lang=\"bash\" class=\"language-bash\">sudo apt update &amp;&amp; sudo apt -y upgrade &amp;&amp; sudo apt -y install git-lfs python3-pip\npip install torch --extra-index-url https:\/\/download.pytorch.org\/whl\/cu117\npip install diffusers transformers==4.26 scipy ftfy accelerate<\/code><\/pre>\n\n\n\n<p>Add CUDA-Support for the WSL (from <a href=\"https:\/\/developer.nvidia.com\/cuda-downloads?target_os=Linux&amp;target_arch=x86_64&amp;Distribution=Ubuntu&amp;target_version=22.04&amp;target_type=deb_network\">this site<\/a>):<\/p>\n\n\n\n<pre id=\"block-cdba4c97-a8e9-41a2-b723-3193efcd628f\" class=\"wp-block-code has-dark-gray-color has-text-color\"><code lang=\"bash\" class=\"language-bash\">wget https:\/\/developer.download.nvidia.com\/compute\/cuda\/repos\/ubuntu2204\/x86_64\/cuda-keyring_1.0-1_all.deb\nsudo dpkg -i cuda-keyring_1.0-1_all.deb\nsudo apt-get update\nsudo apt-get -y install cuda<\/code><\/pre>\n\n\n\n<p>Write yourself a small python file (e.g. as main.py) which will enable the image generation and save the images to a file with the prompt name:<\/p>\n\n\n\n<pre class=\"wp-block-code has-dark-gray-color has-text-color\"><code lang=\"python\" class=\"language-python\">import torch\nfrom torch import autocast\nfrom diffusers import StableDiffusionPipeline\n\npipe = StableDiffusionPipeline.from_pretrained(\"CompVis\/stable-diffusion-v1-4\")\npipe.to(\"cuda\")\n\nprompt = \"a dark environment, two warriors standing on a chess field with swords drawn\"\nsteps = 50\nwidth = 512\nheight = 512\n\nwith autocast(\"cuda\"):\n  for i in range(4):\n    output = pipe(prompt, width=width, height=height, num_inference_steps=steps)\n    image = output[\"images\"][0]\n    file = prompt.replace(\" \", \"_\").replace(\",\", \"\")\n    image.save(f\"{file}-{i}.png\")\n<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>First install WSL2 as suggested by the many different websites out there. I installed it like this: Open the installed Ubuntu and install the necessary packages for stable diffusion itself: Add CUDA-Support for the WSL (from this site): Write yourself a small python file (e.g. as main.py) which will enable the image generation and save &hellip; <a href=\"https:\/\/www.anginf.de\/?p=765\" class=\"more-link\"><span class=\"screen-reader-text\">Stable Diffusion on WSL on Windows<\/span> weiterlesen <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-765","post","type-post","status-publish","format-standard","hentry","category-allgemein"],"_links":{"self":[{"href":"https:\/\/www.anginf.de\/index.php?rest_route=\/wp\/v2\/posts\/765","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.anginf.de\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.anginf.de\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.anginf.de\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.anginf.de\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=765"}],"version-history":[{"count":6,"href":"https:\/\/www.anginf.de\/index.php?rest_route=\/wp\/v2\/posts\/765\/revisions"}],"predecessor-version":[{"id":779,"href":"https:\/\/www.anginf.de\/index.php?rest_route=\/wp\/v2\/posts\/765\/revisions\/779"}],"wp:attachment":[{"href":"https:\/\/www.anginf.de\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=765"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.anginf.de\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=765"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.anginf.de\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=765"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}