Getting Started - Enferlain/sd-optim GitHub Wiki
Getting Started with sd-optim
This guide covers the basic setup required to get sd-optim
running.
Prerequisites
- Python: A working Python environment (version 3.10 or later recommended). Pip should also be available.
- Supported WebUI: A functional local installation of a supported Stable Diffusion WebUI, such as:
- AUTOMATIC1111/stable-diffusion-webui
- lllyasviel/stable-diffusion-webui-forge
- (Add other supported UIs like Swarm, Comfy if applicable)
You need to know how to launch your WebUI with the necessary API flags enabled (usually
--api
).
- Git: Required for cloning the repository.
Installation
sd-optim
is typically installed as an extension within your chosen WebUI's extensions
directory.
- Navigate to Extensions Directory: Open your terminal or command prompt and navigate into the
extensions
directory of your WebUI installation.# Example for A1111/Forge: cd /path/to/stable-diffusion-webui/extensions
- Clone the Repository: Use
git clone
to download thesd-optim
code.
(Note: Replace the URL with the actual repository URL once you have it! Also, updategit clone https://github.com/your-github-username/sd-optim.git sd-optim
sd-optim
if the final folder name is different) - Install Dependencies: Navigate into the newly cloned
sd-optim
directory and install the required Python packages.
(Alternatively, if you are using A1111/Forge's environment, restarting the WebUI might trigger thecd sd-optim pip install -r requirements.txt
install.py
script, but running pip manually is often more reliable).
Initial Configuration Setup
sd-optim
uses Hydra for configuration, primarily through YAML files in the conf/
directory. You need to create your own configuration files from the provided templates (.tmpl.yaml
).
-
Navigate to
conf/
Directory:cd /path/to/stable-diffusion-webui/extensions/sd-optim/conf
-
Copy Template Files: Copy the following template files, removing the
.tmpl
part:config.tmpl.yaml
->config.yaml
optimization_guide/guide.tmpl.yaml
->optimization_guide/guide.yaml
payloads/cargo_*.tmpl.yaml
->payloads/cargo_*.yaml
(Copy the template corresponding to thewebui
you set inconfig.yaml
, e.g.,cargo_forge.tmpl.yaml
->cargo_forge.yaml
)payloads/cargo/payload.tmpl.yaml
->payloads/cargo/payload.yaml
(You will likely create multiple payload files later).
-
Edit Configuration Files: You must edit these newly created
.yaml
files to match your setup:config.yaml
:- Set the correct
webui
identifier (e.g.,forge
). - Update
model_paths
to point to your actual model files. - Update
wildcards_dir
andscorer_model_dir
to your local paths. - Review other settings like
merge_method
,scorer_method
, andoptimizer
settings. See the Configuration page for details.
- Set the correct
payloads/cargo/payload.yaml
: Define at least one image generation payload with your desired prompt, settings, etc. See the Payloads page for details.optimization_guide/guide.yaml
: Configure which model parameters you want to optimize. See the Configuration page for details.
Running the Optimizer
- Start Your WebUI: Launch your Stable Diffusion WebUI (A1111, Forge, etc.) with the API enabled (e.g., by adding the
--api
command-line flag). Ensure it's running and accessible at theurl
specified in yourconfig.yaml
. - Run the Script: Open a new terminal or command prompt, navigate to the
sd-optim
extension directory, and run the main script:
(Note: Ensure the Python environment where you installed the requirements is active).cd /path/to/stable-diffusion-webui/extensions/sd-optim python bayesian_merger.py
The optimization process will begin, interacting with your running WebUI via its API to merge models, generate images, and score them based on your configuration. Logs and results will be saved in the logs/
directory within the sd-optim
folder.
Now you're ready to explore the detailed Configuration options!