### Start kohya_ss GUI with uv Source: https://github.com/bmaltais/kohya_ss/blob/master/docs/Installation/uv_windows.md Launches the kohya_ss GUI using the uv managed environment. If uv is not installed, it will prompt for automatic installation. ```cmd .\gui-uv.bat ``` -------------------------------- ### Run Setup Script Source: https://github.com/bmaltais/kohya_ss/blob/master/docs/Installation/pip_linux.md Executes the setup script for kohya_ss. This script handles the necessary installations and configurations. ```bash ./setup.sh ``` -------------------------------- ### Start GUI with Command Prompt Source: https://github.com/bmaltais/kohya_ss/blob/master/docs/Installation/pip_windows.md Launch the kohya_ss GUI using Command Prompt, with example arguments for listening address and port. ```cmd gui.bat --listen 127.0.0.1 --server_port 7860 --inbrowser --share ``` -------------------------------- ### Run kohya_ss Setup Script on Runpod Source: https://github.com/bmaltais/kohya_ss/blob/master/docs/installation_runpod.md Navigate into the cloned kohya_ss directory and execute the setup script specific to Runpod environments. This script installs necessary dependencies. ```shell cd kohya_ss ./setup-runpod.sh ``` -------------------------------- ### Start GUI with Conda (CMD) Source: https://github.com/bmaltais/kohya_ss/blob/master/docs/Installation/pip_windows.md Launch the kohya_ss GUI using Command Prompt after setup. ```cmd gui.bat ``` -------------------------------- ### Start GUI with PowerShell Source: https://github.com/bmaltais/kohya_ss/blob/master/docs/Installation/pip_windows.md Launch the kohya_ss GUI using PowerShell, with example arguments for listening address and port. ```powershell gui.ps1 --listen 127.0.0.1 --server_port 7860 --inbrowser --share ``` -------------------------------- ### Make Setup Script Executable Source: https://github.com/bmaltais/kohya_ss/blob/master/docs/Installation/pip_linux.md Grants execute permissions to the setup.sh script, allowing it to be run. ```bash chmod +x setup.sh ``` -------------------------------- ### kohya_ss Configuration Example (config.toml) Source: https://context7.com/bmaltais/kohya_ss/llms.txt A comprehensive example of a config.toml file, illustrating various settings for model training, folder management, and advanced parameters. ```toml [settings] use_shell = false # Set true only if your OS requires it [model] models_dir = "C:/sd_models" output_name = "my_character_lora" train_data_dir = "C:/datasets/my_character/img" save_model_as = "safetensors" # ckpt | safetensors | diffusers | diffusers_safetensors save_precision = "bf16" # float | fp16 | bf16 [folders] output_dir = "C:/outputs" reg_data_dir = "C:/datasets/my_character/reg" logging_dir = "C:/logs" [accelerate_launch] mixed_precision = "fp16" # no | fp16 | bf16 | fp8 num_processes = 1 num_machines = 1 num_cpu_threads_per_process = 2 dynamo_backend = "no" [basic] learning_rate = 0.0001 lr_scheduler = "cosine" # constant | cosine | linear | polynomial | ... lr_warmup = 10 # % of total steps epoch = 10 train_batch_size = 2 max_resolution = "512,512" save_every_n_epochs = 1 optimizer = "AdamW8bit" cache_latents = true enable_bucket = true [advanced] gradient_accumulation_steps = 2 gradient_checkpointing = true xformers = "xformers" noise_offset = 0.05 clip_skip = 2 fp8_base = false [samples] sample_every_n_epochs = 1 sample_sampler = "euler_a" sample_prompts = "a photo of sks person, best quality --w 512 --h 512 --d 1 --l 7 --s 28" [huggingface] huggingface_repo_id = "myuser/my-lora" huggingface_token = "hf_xxxxxxxxxxxx" huggingface_repo_visibility = "private" save_state_to_huggingface = false [wd14_caption] repo_id = "SmilingWolf/wd-convnext-tagger-v3" general_threshold = 0.35 character_threshold = 0.35 caption_extension = ".txt" batch_size = 8 onnx = true ``` -------------------------------- ### Sample Image Generation Prompts Source: https://github.com/bmaltais/kohya_ss/blob/master/README.md Example prompts for generating sample images during training. Lines starting with '#' are comments. Options like --n, --w, --h, --d, --l, and --s can be used to control generation parameters. ```txt # prompt 1 masterpiece, best quality, (1girl), in white shirts, upper body, looking at viewer, simple background --n low quality, worst quality, bad anatomy, bad composition, poor, low effort --w 768 --h 768 --d 1 --l 7.5 --s 28 # prompt 2 masterpiece, best quality, 1boy, in business suit, standing at street, looking back --n (low quality, worst quality), bad anatomy, bad composition, poor, low effort --w 576 --h 832 --d 2 --l 5.5 --s 40 ``` -------------------------------- ### Start GUI with Custom Options Source: https://github.com/bmaltais/kohya_ss/blob/master/docs/Installation/uv_linux.md Launches the kohya_ss GUI using the uv managed environment with specified network and browser options. Use `--share` to make the UI accessible externally. ```bash ./gui-uv.sh --listen 127.0.0.1 --server_port 7860 --inbrowser --share ``` -------------------------------- ### Start GUI with Conda Source: https://github.com/bmaltais/kohya_ss/blob/master/docs/Installation/pip_windows.md Launch the kohya_ss GUI using PowerShell or Command Prompt after setup. ```powershell gui.ps1 ``` -------------------------------- ### Run Alternative Setup Script with Conda Source: https://github.com/bmaltais/kohya_ss/blob/master/docs/Installation/pip_windows.md Use this command if you need to run the setup script specifically for Python 3.10. ```powershell setup-3.10.bat ``` -------------------------------- ### Run Setup Script with Conda Source: https://github.com/bmaltais/kohya_ss/blob/master/docs/Installation/pip_windows.md Execute the setup script after activating the Conda environment. ```powershell setup.bat ``` -------------------------------- ### Run Docker Compose Build and Up Source: https://context7.com/bmaltais/kohya_ss/llms.txt Command to build the Docker image and start the services defined in `docker-compose.yaml`. The GUI will be accessible at http://localhost:7860. ```bash docker compose up --build # GUI available at http://localhost:7860 ``` -------------------------------- ### Get GUI Help Information Source: https://github.com/bmaltais/kohya_ss/blob/master/docs/Installation/pip_windows.md Display help information for the GUI script, listing available command-line options. ```cmd gui.bat --help ``` -------------------------------- ### Viewing TensorBoard Logs Source: https://github.com/bmaltais/kohya_ss/blob/master/docs/train_README.md Command to launch TensorBoard for viewing training logs. Ensure tensorboard is installed (`pip install tensorboard`). ```bash tensorboard --logdir=logs ``` -------------------------------- ### Sample Prompts for Training Source: https://github.com/bmaltais/kohya_ss/blob/master/docs/train_README.md Prepare a text file with prompts for sample output during training. Each line is a prompt, and lines starting with '#' are comments. Options for image generation can be specified with '--' followed by a lowercase English letter. ```txt # prompt 1 masterpiece, best quality, 1girl, in white shirts, upper body, looking at viewer, simple background --n low quality, worst quality, bad anatomy,bad composition, poor, low effort --w 768 --h 768 --d 1 --l 7.5 --s 28 # prompt 2 masterpiece, best quality, 1boy, in business suit, standing at street, looking back --n low quality, worst quality, bad anatomy,bad composition, poor, low effort --w 576 --h 832 --d 2 --l 5.5 --s 40 ``` -------------------------------- ### AccelerateLaunch Gradio Component Source: https://context7.com/bmaltais/kohya_ss/llms.txt Example of initializing and using the AccelerateLaunch Gradio component for GPU and distributed settings. This component prepends settings to training commands. ```python import gradio as gr from kohya_gui.class_accelerate_launch import AccelerateLaunch from kohya_gui.class_gui_config import KohyaSSGUIConfig config = KohyaSSGUIConfig("./config.toml") with gr.Blocks() as demo: accel = AccelerateLaunch(config=config) # accel.mixed_precision → "fp16" / "bf16" / "fp8" / "no" # accel.num_processes → 1 (multi-GPU: set to number of GPUs) # accel.gpu_ids → "0,1" for multi-GPU # accel.dynamo_backend → "inductor" for torch.compile speedup demo.launch() ``` -------------------------------- ### Start kohya_ss GUI with Custom Options Source: https://github.com/bmaltais/kohya_ss/blob/master/docs/Installation/uv_windows.md Starts the kohya_ss GUI with specific network and browser settings. This command allows customization of the server's listening address, port, and whether to open in a browser or share the UI. ```cmd .\gui-uv.bat --listen 127.0.0.1 --server_port 7860 --inbrowser --share ``` -------------------------------- ### Prepare Presets for Release Source: https://github.com/bmaltais/kohya_ss/blob/master/presets/finetune/prepare_presets.md Run this command to prepare new presets for release to users. Ensure you have Python installed and the script is in the correct directory. ```bash python.exe .\tools\prepare_presets.py .\presets\finetune\*.json ``` -------------------------------- ### Start kohya_ss GUI Source: https://github.com/bmaltais/kohya_ss/blob/master/docs/Installation/pip_linux.md Launches the kohya_ss graphical user interface with specified network and port settings. The `--share` flag enables a public URL. ```bash ./gui.sh --listen 127.0.0.1 --server_port 7860 --inbrowser --share ``` -------------------------------- ### Use Pre-built Docker Image Source: https://github.com/bmaltais/kohya_ss/blob/master/docs/installation_docker.md Clone the repository and start the Docker container using docker compose. To update, stop the current container, remove it, and then restart with the always pull flag. ```bash git clone --recursive https://github.com/bmaltais/kohya_ss.git cd kohya_ss docker compose up -d ``` ```bash docker compose down && docker compose up -d --pull always ``` -------------------------------- ### LoRA Training Command Source: https://context7.com/bmaltais/kohya_ss/llms.txt Example accelerate command for training a LoRA model. Recommended for SDXL LoRA. ```bash accelerate launch \ --mixed_precision="fp16" \ --num_cpu_threads_per_process=2 \ sd-scripts/train_network.py \ --pretrained_model_name_or_path="stabilityai/stable-diffusion-xl-base-1.0" \ --train_data_dir="/datasets/my_char/img" \ --reg_data_dir="/datasets/my_char/reg" \ --output_dir="/outputs" \ --output_name="my_char_sdxl_lora" \ --save_model_as="safetensors" \ --save_precision="bf16" \ --network_module="networks.lora" \ --network_dim=32 \ --network_alpha=16 \ --learning_rate=4e-7 \ --lr_scheduler="constant_with_warmup" \ --lr_warmup_steps=100 \ --optimizer_type="Adafactor" \ --optimizer_args="scale_parameter=False" "relative_step=False" "warmup_init=False" \ --max_train_epochs=15 \ --train_batch_size=2 \ --gradient_accumulation_steps=2 \ --resolution="1024,1024" \ --enable_bucket \ --cache_latents \ --xformers \ --network_train_unet_only \ --sample_every_n_epochs=1 \ --sample_prompts="/outputs/sample/prompt.txt" \ --sample_sampler="euler_a" ``` -------------------------------- ### Install Python and Git on Ubuntu Source: https://github.com/bmaltais/kohya_ss/blob/master/docs/Installation/pip_linux.md Installs Python 3.11 and Git on Ubuntu 22.04 or later systems. Ensure you have sudo privileges. ```bash sudo apt update sudo apt install python3.11 python3.11-venv git ``` -------------------------------- ### Start Headless GUI on Server Source: https://github.com/bmaltais/kohya_ss/blob/master/docs/Installation/uv_linux.md Launches the kohya_ss GUI in headless mode on a server, suitable for environments without a direct display. It specifies network and sharing options. ```bash ./gui-uv.sh --headless --listen 127.0.0.1 --server_port 7860 --inbrowser --share ``` -------------------------------- ### Run kohya_ss GUI with Public URL on Runpod Source: https://github.com/bmaltais/kohya_ss/blob/master/docs/installation_runpod.md Start the kohya_ss GUI, generating a public URL for access. This command is suitable when you need to access the GUI from outside the Runpod instance without direct port exposure. ```shell ./gui.sh --share --headless ``` -------------------------------- ### SDXL Finetuning Optimizer Settings (Adafactor) Source: https://github.com/bmaltais/kohya_ss/blob/master/docs/Finetuning/top_level.md Example configuration for Adafactor optimizer with a fixed learning rate, suitable for SDXL finetuning. Ensure `optimizer_type` is set to 'adafactor' and adjust `learning_rate` as needed. ```python optimizer_type = "adafactor" optimizer_args = [ "scale_parameter=False", "relative_step=False", "warmup_init=False" ] lr_scheduler = "constant_with_warmup" lr_warmup_steps = 100 learning_rate = 4e-7 # SDXL original learning rate ``` -------------------------------- ### SDXL LoRA Training Configuration with Adafactor Optimizer Source: https://github.com/bmaltais/kohya_ss/blob/master/docs/LoRA/top_level.md Example configuration for Adafactor optimizer with a fixed learning rate, suitable for SDXL LoRA training. Ensure to use the `--network_train_unet_only` option for SDXL. ```python optimizer_type = "adafactor" optimizer_args = [ "scale_parameter=False", "relative_step=False", "warmup_init=False" ] lr_scheduler = "constant_with_warmup" lr_warmup_steps = 100 learning_rate = 4e-7 # This is the standard learning rate for SDXL ``` -------------------------------- ### ControlNet-LLLite Training Configuration Source: https://github.com/bmaltais/kohya_ss/blob/master/docs/train_lllite_README.md Example TOML configuration for training ControlNet-LLLite. Key parameters include model paths, training epochs, data loader workers, seed, gradient checkpointing, mixed precision, optimizer, learning rate, VRAM saving options, network dimensions, and dataset configuration. ```toml pretrained_model_name_or_path = "/path/to/model_trained_on.safetensors" max_train_epochs = 12 max_data_loader_n_workers = 4 persistent_data_loader_workers = true seed = 42 gradient_checkpointing = true mixed_precision = "bf16" save_precision = "bf16" full_bf16 = true optimizer_type = "adamw8bit" learning_rate = 2e-4 xformers = true output_dir = "/path/to/output/dir" output_name = "output_name" save_every_n_epochs = 1 save_model_as = "safetensors" vae_batch_size = 4 cache_latents = true cache_latents_to_disk = true cache_text_encoder_outputs = true cache_text_encoder_outputs_to_disk = true network_dim = 64 cond_emb_dim = 32 dataset_config = "/path/to/dataset.toml" ``` -------------------------------- ### Set Custom Installation Path Source: https://github.com/bmaltais/kohya_ss/blob/master/docs/Installation/pip_linux.md Overrides the default installation directory for kohya_ss by specifying a custom path using the `-d` flag with the setup script. ```bash ./setup.sh -d /your/custom/path ``` -------------------------------- ### Install DeepDanbooru Package Source: https://github.com/bmaltais/kohya_ss/blob/master/docs/train_README.md Install the DeepDanbooru package itself after setting up the environment and requirements. This command should also be run from the DeepDanbooru folder. ```python pip install . ``` -------------------------------- ### Install DeepDanbooru Requirements Source: https://github.com/bmaltais/kohya_ss/blob/master/docs/train_README.md Install the necessary Python libraries for DeepDanbooru. This command should be run from the DeepDanbooru folder after cloning the repository. ```python pip install -r requirements.txt ``` -------------------------------- ### Generate Sample Images During Training Source: https://context7.com/bmaltais/kohya_ss/llms.txt Use the `create_prompt_file` function to generate a prompt file for preview images during training. The prompt syntax supports negative prompts, image dimensions, seed, CFG scale, and steps. ```python from kohya_gui.class_sample_images import create_prompt_file # Prompt syntax: free text + optional flags # --n negative prompt # --w width --h height # --d seed --l CFG scale --s steps prompts = """ # portrait masterpiece, best quality, 1girl, sks person, smiling, white shirt --n lowres, bad anatomy --w 512 --h 768 --d 42 --l 7.5 --s 28 # full body masterpiece, 1girl, sks person, standing in a park --n worst quality --w 512 --h 768 --d 1 --l 7 --s 30 """ prompt_file_path = create_prompt_file( sample_prompts = prompts, output_dir = "/outputs/my_lora", ) # Writes to /outputs/my_lora/sample/prompt.txt # Pass this path via --sample_prompts in the training command ``` -------------------------------- ### Upgrade kohya_ss Source: https://github.com/bmaltais/kohya_ss/blob/master/docs/Installation/pip_linux.md Updates the kohya_ss repository to the latest version by pulling changes and then rerunning the setup script. ```bash git pull ./setup.sh ``` -------------------------------- ### Upgrade kohya_ss Environment Source: https://github.com/bmaltais/kohya_ss/blob/master/docs/Installation/pip_windows.md Commands to pull the latest changes from the repository and re-run the setup script to upgrade the environment. ```cmd git pull setup.bat ``` -------------------------------- ### Pull Latest Changes Source: https://github.com/bmaltais/kohya_ss/blob/master/docs/Installation/uv_windows.md Updates the local repository to the latest version from the remote. This command should be run before starting the GUI after an update. ```powershell git pull ``` -------------------------------- ### Programmatic Dataset Folder Preparation Source: https://context7.com/bmaltais/kohya_ss/llms.txt Demonstrates how to prepare dataset folders for Dreambooth training programmatically using the `dreambooth_folder_preparation` function. ```python # Programmatic folder preparation via dreambooth_folder_preparation() from kohya_gui.dreambooth_folder_creation_gui import dreambooth_folder_preparation dreambooth_folder_preparation( util_training_images_dir_input = "/raw_photos/john", util_training_images_repeat_input = 30, util_instance_prompt_input = "john", util_regularization_images_dir_input= "/reg_photos/person", util_regularization_images_repeat_input = 1, util_class_prompt_input = "person", util_training_dir_output = "/datasets/john_dreambooth", ) # Creates /datasets/john_dreambooth/img/30_john person/ (training images copied) # /datasets/john_dreambooth/reg/1_person/ (reg images copied) ``` -------------------------------- ### Prepare LoRA Presets for Release Source: https://github.com/bmaltais/kohya_ss/blob/master/presets/lora/prepare_presets.md Run this command to prepare new LoRA presets for release to users. Ensure you are in the correct directory. ```bash python.exe .\tools\prepare_presets.py .\presets\lora\*.json ``` -------------------------------- ### BasicTraining Gradio Component Source: https://context7.com/bmaltais/kohya_ss/llms.txt Example of initializing and using the BasicTraining Gradio component for hyperparameter controls. This component is reusable across different training tabs. ```python import gradio as gr from kohya_gui.class_basic_training import BasicTraining from kohya_gui.class_gui_config import KohyaSSGUIConfig config = KohyaSSGUIConfig("./config.toml") with gr.Blocks() as demo: sdxl_checkbox = gr.Checkbox(label="SDXL", value=False) training = BasicTraining( sdxl_checkbox = sdxl_checkbox, learning_rate_value = "1e-4", lr_scheduler_value = "cosine", lr_warmup_value = "10", # warmup % of total steps lr_warmup_steps_value = 0, finetuning = False, dreambooth = False, config = config, ) # Now training.learning_rate, training.epoch, training.train_batch_size, etc. # are all Gradio components wired to event handlers demo.launch() ``` -------------------------------- ### Launch Kohya's GUI Source: https://context7.com/bmaltais/kohya_ss/llms.txt Use these commands to launch the GUI on Linux, macOS, or Windows. Options include specifying listen address, server port, headless mode, and reverse proxy configuration. Specific flags are available for Intel ARC (IPEX) or AMD ROCm GPUs. ```bash # Linux / macOS — standard launch (pip-based venv) ./gui.sh --listen 0.0.0.0 --server_port 7860 ``` ```bash # Linux / macOS — uv-based launch (no prior setup.sh required) ./gui-uv.sh --listen 127.0.0.1 --server_port 7860 ``` ```bash # Windows gui.bat --listen 127.0.0.1 --server_port 7860 ``` ```bash # Headless (no browser auto-open, suitable for remote servers / Docker) python kohya_gui.py \ --headless \ --listen 0.0.0.0 \ --server_port 7860 \ --username admin \ --password secret \ --config ./my_config.toml ``` ```bash # Behind a reverse proxy (e.g., nginx sub-path /kohya_ss) python kohya_gui.py --root_path /kohya_ss --headless ``` ```bash # Intel ARC (IPEX) or AMD ROCm GPU ./gui.sh --use-ipex # Intel ./gui.sh --use-rocm # AMD ``` -------------------------------- ### CommandExecutor for Training Process Management Source: https://context7.com/bmaltais/kohya_ss/llms.txt Shows how to use `CommandExecutor` to manage the `accelerate launch` subprocess for training, including starting, checking status, and terminating the process. ```python from kohya_gui.class_command_executor import CommandExecutor import gradio as gr with gr.Blocks() as demo: executor = CommandExecutor(headless=True) # Start a LoRA training job run_cmd = [ "accelerate", "launch", "--mixed_precision=fp16", "--num_processes=1", "sd-scripts/train_network.py", "--pretrained_model_name_or_path=runwayml/stable-diffusion-v1-5", "--train_data_dir=/datasets/my_lora/img", "--output_dir=/outputs", "--output_name=my_lora", "--network_module=networks.lora", "--network_dim=32", "--network_alpha=16", "--max_train_epochs=10", "--learning_rate=1e-4", "--save_model_as=safetensors", ] executor.execute_command(run_cmd=run_cmd) print("Running:", executor.is_running()) # True # Stop it if needed executor.kill_command() # Or block until it finishes executor.wait_for_training_to_end() ``` -------------------------------- ### Logging Directory and Prefix Source: https://github.com/bmaltais/kohya_ss/blob/master/docs/train_README.md Specify the directory for saving training logs and an optional prefix for log folder names. TensorBoard-formatted logs are saved. ```bash --logging_dir=logs --log_prefix=db_style1_ ``` -------------------------------- ### Checkout Previous Version Source: https://github.com/bmaltais/kohya_ss/blob/master/README.md Use this command to switch to a previous version of the project, specifically v24.1.7, which predates support for flux.1 and sd3. ```shell git checkout v24.1.7 ``` -------------------------------- ### Run kohya_ss GUI with Direct Port Exposure on Runpod Source: https://github.com/bmaltais/kohya_ss/blob/master/docs/installation_runpod.md Launch the kohya_ss GUI, listening on all network interfaces (0.0.0.0) and disabling the headless mode. Use this if you have exposed port 7860 directly in your Runpod configuration. ```shell ./gui.sh --listen=0.0.0.0 --headless ```