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

  1. Python: A working Python environment (version 3.10 or later recommended). Pip should also be available.
  2. Supported WebUI: A functional local installation of a supported Stable Diffusion WebUI, such as:
  3. Git: Required for cloning the repository.

Installation

sd-optim is typically installed as an extension within your chosen WebUI's extensions directory.

  1. 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
    
  2. Clone the Repository: Use git clone to download the sd-optim code.
    git clone https://github.com/your-github-username/sd-optim.git sd-optim
    
    (Note: Replace the URL with the actual repository URL once you have it! Also, update sd-optim if the final folder name is different)
  3. Install Dependencies: Navigate into the newly cloned sd-optim directory and install the required Python packages.
    cd sd-optim
    pip install -r requirements.txt
    
    (Alternatively, if you are using A1111/Forge's environment, restarting the WebUI might trigger the 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).

  1. Navigate to conf/ Directory:

    cd /path/to/stable-diffusion-webui/extensions/sd-optim/conf
    
  2. 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 the webui you set in config.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).
  3. 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 and scorer_model_dir to your local paths.
      • Review other settings like merge_method, scorer_method, and optimizer settings. See the Configuration page for details.
    • 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

  1. 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 the url specified in your config.yaml.
  2. Run the Script: Open a new terminal or command prompt, navigate to the sd-optim extension directory, and run the main script:
    cd /path/to/stable-diffusion-webui/extensions/sd-optim
    python bayesian_merger.py
    
    (Note: Ensure the Python environment where you installed the requirements is active).

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!