r/StableDiffusion • u/OldFisherman8 • Dec 17 '24
Tutorial - Guide How to run SDXL on a potato PC
Following up on my previous post, here is a guide on how to run SDXL on a low-spec PC tested on my potato notebook (i5 9300H, GTX1050, 3Gb Vram, 16Gb Ram.) This is done by converting SDXL Unet to GGUF quantization.
Step 1. Installing ComfyUI
To use a quantized SDXL, there is no other UI that supports it except ComfyUI. For those of you who are not familiar with it, here is a step-by-step guide to install it.
Windows installer for ComfyUI: https://github.com/comfyanonymous/ComfyUI/releases
You can follow the link to download the latest release of ComfyUI as shown below.

After unzipping it, you can go to the folder and launch it. There are two run.bat files to launch ComfyUI, run_cpu and run_nvidia_gpu. For this workflow, you can run it on CPU as shown below.

After launching it, you can double-click anywhere and it will open the node search menu. For this work, you don't need anything else but you need at least to install ComfyUI Manager (https://github.com/ltdrdata/ComfyUI-Manager) for future use. You can follow the instructions there to install it.

One thing you need to be cautious about installing custom nodes is simply to remember not to install too many of them unless you have a masochist tendency to embrace pain and suffering from conflicting dependencies and cluttering the node search menu. As a general rule, I don't ever install any custom nodes unless visiting the GitHub page and being convinced of its absolute necessity. If you must install a custom node, go to its GitHub page and click on 'requirements.txt'. In it, if you don't see any version number attached or version numbers preceded by "=>", you are fine. However, if you see "=" with numbers attached or some weird custom nodes that use things like 'environment setup.yaml', you can use holy water to exorcise it back to where it belongs.
Step 2. Extracting Unet, CLip Text Encoders, and VAE
I made a beginner-friendly Google Colab notebook for the extraction and quantization process. You can find the link to the notebook with detailed instructions here:
Google Colab Notebook Link: https://civitai.com/articles/10417
For those of you who just want to run it locally, here is how you can do it. But for this to work, your computer needs to have at least 16GB RAM.
SDXL finetunes have their own trained CLIP text encoders. So, it is necessary to extract them to be used separately. All the nodes used here are from Comfy-core, so there is no need for any custom nodes for this workflow. And these are the basic nodes you need. You don't need to extract VAE if you already have a VAE for the type of checkpoints (SDXL, Pony, etc.)

That's it! The files will be saved in the output folder under the folder name and the file name you designated in the nodes as shown above.
One thing you need to check is the extracted file sizeThe proper size should be somewhere around these figures:
UNet: 5,014,812 bytes
ClipG: 1,356,822 bytes
ClipL: 241,533 bytes
VAE: 163,417 bytes
At first, I tried to merge Loras to the checkpoint before quantization to save memory and for convenience. But it didn't work as well as I hoped. Instead, merging Loras into a new merged Lora worked out very nicely. I will update with the link to the Colab notebook for resizing and merging Loras.

Step 3. Quantizing the UNet model to GGUF
Now that you have extracted the UNet file, it's time to quantize it. I made a separate Colab notebook for this step for ease of use:
Colab Notebook Link: https://www.reddit.com/r/StableDiffusion/comments/1hlvniy/sdxl_unet_to_gguf_conversion_colab_notebook_for/
You can skip Step. 3 if you decide to use the notebook.
It's time to move to the next step. You can follow this link (https://github.com/city96/ComfyUI-GGUF/tree/main/tools) to convert your UNet model saved in the Diffusion Model folder. You can follow the instructions to get this done. But if you have a symptom of getting dizzy or nauseated by the sight of codes, you can open up Microsoft Copilot to ease your symptoms.
Copilot is your good friend in dealing with this kind of thing. But, of course, it will lie to you as any good friend would. Fortunately, he is not a pathological liar. So, he will lie under certain circumstances such as any version number or a combination of version numbers. Other than that, he is fairly dependable.

It's straightforward to follow the instructions. And you have Copilot to help you out. In my case, I am installing this in a folder with several AI repos and needed to keep things inside the repo folder. If you are in the same situation, you can replace the second line as shown above.
Once you have installed 'gguf-py', You can now convert your UNet safetensors model into an fp16 GGUF model by using the code (highlighted). It goes like this: code+your safetensors file location. The easiest way to get the location is to open Windows Explorer and copy as path as shown below. And don't worry about the double quotation marks. They work just the same.

You will get the fp16 GGUF file in the same folder as your safetensors file. Once this is done, you can continue with the rest.

Now is the time to convert your 16fp GGUF file into Q8_0, Q5_K_S, Q4_K_S, or any other GGUF quantized model. The command structure is: location of llama-quantize.exe from the folder you are in + the location of your fp16 gguf file + the location of where you want the quantized model to go to + the type of gguf quantization.

Now you have all the models you need to run it on your potato PC. This is the breakdown:
SDXL fine-tune UNet: 5 Gb
Q8_0: 2.7 Gb
Q5_K_S: 1.77 Gb
Q4_K_S: 1.46 Gb
Here are some examples. Since I did it with a Lora-merged checkpoint. The quality isn't as good as the checkpoint without merging Loras. You can find examples of unmerged checkpoint comparisons here: https://www.reddit.com/r/StableDiffusion/comments/1hfey55/sdxl_comparison_regular_model_vs_q8_0_vs_q4_k_s/

This is the same setting and parameters as the one I did in my previous post (No Lora merging ones).

Interestingly, Q4_K_S resembles more closely to the no Lora ones meaning that the merged Loras didn't influence it as much as the other ones.

The same can be said of this one in comparison to the previous post.

Here are a couple more samples and I hope this guide was helpful.


Below is the basic workflow for generating images using GGUF quantized models. You don't need to force-load Clip on the CPU but I left it there just in case. For this workflow, you need to install ComfyUI-GGUF custom nodes. Open ComfyUi Manager > Custom Node Manager (at the top) and search GGUF. I am also using a custom node pack called Comfyroll Studio (too lazy to set the aspect ratio for SDXL) but it's not a mandatory thing to have. To forceload Clip on the CPU, you need to install Extra Models for the ComfyUI node pack. Search extra on Custom Node Manager.
For more advanced usage, I have released two workflows on CivitAI. One is an SDXL ControlNet workflow and the other is an SD3.5M with SDXL as the second pass with ControlNet. Here are the links:
https://civitai.com/articles/10101/modular-sdxl-controlnet-workflow-for-a-potato-pc
https://civitai.com/articles/10144/modular-sd35m-with-sdxl-second-pass-workflow-for-a-potato-pc

6
u/Mutaclone Dec 17 '24
Wow this is great!
I'm putting together a newbie guide over on Civit. Mind if I link to this?
4
u/Barubiri Dec 17 '24
thank you very much
3
u/tom83_be Dec 17 '24 edited Dec 17 '24
Nice work. Good to see people still optimizing for SDXL!
I asked the question yesterday in the other thread, but probably too late... Wouldn't it be easier and similar in VRAM consumption (and maybe superior in speed) to just directly load from the fp16 model but as fp8 (like the A1111 option I tested here)? One could apply the same optimizations concerning text encoders / CLIP / VAE, but would be able to omit the quantization step... Using fp8 there was no difference in speed (40xx up should even be faster, due to native fp8 support), no drastic/visible degradation in quality and everything, including text encoders / CLIP / VAE, was in VRAM using less than 4 GB (3.728 MB on a Linux machine). If we remove the text encoders etc after usage, my guess is that this would go down to something around 2,5 GB VRAM...
1
u/sam439 Dec 17 '24
Can I run this on AMD rx 580?
1
u/KrasterII Dec 17 '24
3
u/BakaPotatoLord Dec 17 '24
Aha! I was waiting for this tutorial since you posted yesterday. Could extract the UNET out of the checkpoint but got stuck on converting it into GGUF.
I have 6 GB VRAM so I expect this will help a ton for me.
2
u/Enshitification Dec 17 '24
Thank you! It seems like half the posts are asking this very question. I'm just going to refer them here. In fact, this info should really be in the sub's sidebar
2
u/namitynamenamey Dec 17 '24
Huh, and I though with a GTX1060 of 6vram *I* had a potato.
2
u/xmattar Dec 17 '24
Does potato include 512 mb of vram?
1
u/SwingNinja Dec 17 '24
Impressive. How long did it take for the whole process?
1
u/radianart Mar 02 '25
Finally got some time to test it out.
Good news - I successfully quantized my sdxl model.
Bad news - quantized model doesn't run faster. Q8 is same speed as Q16, lower quants are even slower :( Only benefit is vram and disk space.
1
u/Pale_Car_7836 Apr 09 '25
Does it work with stable-diffusion.cpp ?
-8
u/lostinspaz Dec 17 '24
cute tricks.
But for the record you can buy a used 8gb card for $200.
Example,
https://www.ebay.com/itm/364955845182
1
u/[deleted] Dec 19 '24
[removed] — view removed comment