### ControlNet Command Line Example Source: https://github.com/kohya-ss/sd-scripts/blob/main/docs/gen_img_README.md Example of how to use ControlNet with various parameters during image generation. Ensure ControlNet 1.0 is installed and Canny is used for preprocessing if not specified otherwise. ```batchfile python gen_img.py --ckpt model_ckpt --scale 8 --steps 48 --outdir txt2img --xformers \ --W 512 --H 768 --bf16 --sampler k_euler_a \ --control_net_models diff_control_sd15_canny.safetensors --control_net_weights 1.0 \ --guide_image_path guide.png --control_net_ratios 1.0 --interactive ``` -------------------------------- ### Windows Installation Steps Source: https://github.com/kohya-ss/sd-scripts/blob/main/README.md Commands to clone the repository, set up a virtual environment, activate it, and install core dependencies including PyTorch. ```powershell git clone https://github.com/kohya-ss/sd-scripts.git cd sd-scripts python -m venv venv .\venv\Scripts\activate pip install torch==2.6.0 torchvision==0.21.0 --index-url https://download.pytorch.org/whl/cu124 pip install --upgrade -r requirements.txt accelerate config ``` -------------------------------- ### Install PyTorch for CUDA 12.1 Source: https://github.com/kohya-ss/sd-scripts/blob/main/README.md Example command to install a specific version of PyTorch for CUDA 12.1. Adjust the URL for different CUDA versions. ```bash pip install torch==2.6.0 torchvision==0.21.0 --index-url https://download.pytorch.org/whl/cu121 ``` -------------------------------- ### Install pytest Source: https://github.com/kohya-ss/sd-scripts/blob/main/tests/README.md Install the pytest framework using pip. This is a prerequisite for running tests. ```bash pip install pytest ``` -------------------------------- ### Install xformers Source: https://github.com/kohya-ss/sd-scripts/blob/main/README.md Command to install the xformers library for potential performance improvements. Ensure your virtual environment is activated. ```bash pip install xformers --index-url https://download.pytorch.org/whl/cu124 ``` -------------------------------- ### Example Prompt with Options Source: https://github.com/kohya-ss/sd-scripts/blob/main/docs/gen_img_README.md Demonstrates the usage of various prompt options such as negative prompts, image dimensions, steps, and random seeds within a single generation command. ```bash (masterpiece, best quality), 1girl, in shirt and plated skirt, standing at street under cherry blossoms, upper body, [from below], kind smile, looking at another, [goodembed] --n realistic, real life, (negprompt), (lowres:1.1), (worst quality:1.2), (low quality:1.1), bad anatomy, bad hands, text, error, missing fingers, extra digit, fewer digits, cropped, normal quality, jpeg artifacts, signature, watermark, username, blurry --w 960 --h 640 --s 28 --d 1 ``` -------------------------------- ### SD3 Network Training Command Example Source: https://github.com/kohya-ss/sd-scripts/blob/main/docs/sd3_train_network.md Execute sd3_train_network.py using accelerate launch. Ensure all required model paths and dataset configurations are provided. Use line breaks with \ or ^ for readability. ```bash accelerate launch --num_cpu_threads_per_process 1 sd3_train_network.py \ --pretrained_model_name_or_path="" \ --clip_l="" \ --clip_g="" \ --t5xxl="" \ --dataset_config="my_sd3_dataset_config.toml" \ --output_dir="" \ --output_name="my_sd3_lora" \ --save_model_as=safetensors \ --network_module=networks.lora \ --network_dim=16 \ --network_alpha=1 \ --learning_rate=1e-4 \ --optimizer_type="AdamW8bit" \ --lr_scheduler="constant" \ --sdpa \ --max_train_epochs=10 \ --save_every_n_epochs=1 \ --mixed_precision="fp16" \ --gradient_checkpointing \ --weighting_scheme="uniform" \ --blocks_to_swap=32 ``` -------------------------------- ### Install ONNX Runtime Source: https://github.com/kohya-ss/sd-scripts/blob/main/docs/wd14_tagger_README-en.md Install ONNX and ONNX Runtime for GPU acceleration. Refer to the official ONNX Runtime documentation for more installation details. ```powershell pip install onnx onnxruntime-gpu ``` -------------------------------- ### Accelerate Config Answers Source: https://github.com/kohya-ss/sd-scripts/blob/main/README.md Recommended answers for the 'accelerate config' prompts for a typical single-machine setup using fp16 mixed precision. ```text - This machine - No distributed training - NO - NO - NO - all - fp16 ``` -------------------------------- ### Recommended Network Dimension Settings Source: https://github.com/kohya-ss/sd-scripts/blob/main/docs/train_leco.md Recommended starting values for --network_dim based on model type. For SD 1.x/2.x, use 4-8. For SDXL, use 8-16. ```bash --network_dim=4 ``` ```bash --network_dim=8 ``` -------------------------------- ### SDXL LoRA Training Command Source: https://github.com/kohya-ss/sd-scripts/blob/main/docs/sdxl_train_network.md Basic command line execution example for SDXL LoRA training using accelerate launch. Ensure to replace placeholders with your specific paths and configurations. ```bash accelerate launch --num_cpu_threads_per_process 1 sdxl_train_network.py --pretrained_model_name_or_path="" --dataset_config="my_sdxl_dataset_config.toml" --output_dir="" --output_name="my_sdxl_lora" --save_model_as=safetensors --network_module=networks.lora --network_dim=32 --network_alpha=16 --learning_rate=1e-4 --unet_lr=1e-4 --text_encoder_lr1=1e-5 --text_encoder_lr2=1e-5 --optimizer_type="AdamW8bit" --lr_scheduler="constant" --max_train_epochs=10 --save_every_n_epochs=1 --mixed_precision="bf16" --gradient_checkpointing --cache_text_encoder_outputs --cache_latents ``` -------------------------------- ### Example WD14 Tagger Usage Source: https://github.com/kohya-ss/sd-scripts/blob/main/docs/wd14_tagger_README-en.md Example of running the WD14 Tagger with a specific model repository, batch size, and training data folder. ```bash python tag_images_by_wd14_tagger.py --onnx --repo_id SmilingWolf/wd-swinv2-tagger-v3 --batch_size 4 ..\train_data ``` -------------------------------- ### TOML Configuration for Multiple Datasets Source: https://github.com/kohya-ss/sd-scripts/blob/main/docs/config_README-en.md Example TOML configuration demonstrating how to set up multiple datasets, including DreamBooth and fine-tuning styles, with specific subset configurations for image directories, class tokens, and metadata. ```toml [general] shuffle_caption = true caption_extension = '.txt' keep_tokens = 1 # This is a DreamBooth-style dataset [[datasets]] resolution = 512 batch_size = 4 keep_tokens = 2 [[datasets.subsets]] image_dir = 'C:\\hoge' class_tokens = 'hoge girl' # This subset uses keep_tokens = 2 (the value of the parent datasets) [[datasets.subsets]] image_dir = 'C:\\fuga' class_tokens = 'fuga boy' keep_tokens = 3 [[datasets.subsets]] is_reg = true image_dir = 'C:\\reg' class_tokens = 'human' keep_tokens = 1 # This is a fine-tuning dataset [[datasets]] resolution = [768, 768] batch_size = 2 [[datasets.subsets]] image_dir = 'C:\\piyo' metadata_file = 'C:\\piyo\\piyo_md.json' # This subset uses keep_tokens = 1 (the value of [general]) ``` -------------------------------- ### Install DeepSpeed (Experimental) Source: https://github.com/kohya-ss/sd-scripts/blob/main/README.md Command to install the DeepSpeed library, which is experimental and only available on Linux or WSL2. Ensure your virtual environment is activated. ```bash pip install deepspeed==0.16.7 ``` -------------------------------- ### Multi-line Captions Example (Text File) Source: https://github.com/kohya-ss/sd-scripts/blob/main/docs/config_README-en.md Demonstrates how multi-line captions are represented in a plain text file when wildcard notation is enabled. Each line is treated as a potential caption. ```txt 1girl, hatsune miku, vocaloid, upper body, looking at viewer, microphone, stage a girl with a microphone standing on a stage detailed digital art of a girl with a microphone on a stage ``` -------------------------------- ### Run Anima Train ControlNet LLLite Source: https://github.com/kohya-ss/sd-scripts/blob/main/docs/anima_train_control_net_lllite.md Use this command to launch the training process. Replace placeholders with your specific model paths, dataset configuration, and output directories. Ensure you have 'accelerate' installed and configured. ```bash accelerate launch --num_cpu_threads_per_process 1 anima_train_control_net_lllite.py \ --pretrained_model_name_or_path="" \ --qwen3="" \ --vae="" \ --dataset_config="my_anima_lllite_dataset.toml" \ --output_dir="" \ --output_name="my_anima_lllite" \ --save_model_as=safetensors \ --cond_emb_dim=32 \ --lllite_mlp_dim=64 \ --lllite_cond_dim=64 \ --lllite_target_layers=self_attn_q \ --learning_rate=5e-5 \ --optimizer_type="AdamW8bit" \ --lr_scheduler="constant" \ --timestep_sampling="shift" \ --discrete_flow_shift=3.0 \ --max_train_epochs=10 \ --save_every_n_epochs=1 \ --mixed_precision="bf16" \ --gradient_checkpointing \ --cache_latents \ --cache_text_encoder_outputs \ --vae_chunk_size=64 \ --vae_disable_cache ``` -------------------------------- ### Sample Image Generation Prompt Source: https://github.com/kohya-ss/sd-scripts/blob/main/docs/flux_train_network.md Example prompt for generating sample images during training, including negative prompts and specific settings for guidance and CFG scale. This is used in conjunction with training commands. ```text Japanese shrine in the summer forest. --n low quality, ugly, unfinished, out of focus, deformed, disfigure, blurry, smudged, restricted palette, flat colors --w 512 --h 512 --d 1 --l 4.0 --g 0.0 --s 20 ``` -------------------------------- ### Adafactor Optimizer Configuration for SDXL Source: https://github.com/kohya-ss/sd-scripts/blob/main/docs/train_SDXL-en.md Example TOML configuration for Adafactor optimizer with a fixed learning rate, suitable for SDXL training. This setup aims to reduce GPU memory usage. ```toml 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 ``` -------------------------------- ### Loading Pre-trained LoRA Weights Source: https://github.com/kohya-ss/sd-scripts/blob/main/docs/train_network_advanced.md Start training by loading existing LoRA weights. This is useful for fine-tuning or resuming training from a specific LoRA checkpoint. It only loads the LoRA module weights, unlike the --resume option. ```shell --network_weights="" ``` -------------------------------- ### Textual Inversion Dataset Configuration Source: https://github.com/kohya-ss/sd-scripts/blob/main/docs/train_textual_inversion.md Example TOML configuration file for setting up a dataset for Textual Inversion training. Specifies general settings and subset configurations including image directory, caption extension, and repeat counts. ```toml [general] shuffle_caption = false caption_extension = ".txt" keep_tokens = 1 [[datasets]] resolution = 512 # 1024 for SDXL batch_size = 4 # Can use larger values than LoRA training enable_bucket = true [[datasets.subsets]] image_dir = "path/to/images" caption_extension = ".txt" num_repeats = 10 ``` -------------------------------- ### ControlNet-LLLite Training Configuration Source: https://github.com/kohya-ss/sd-scripts/blob/main/docs/train_lllite_README.md Example TOML configuration for training ControlNet-LLLite models. Key parameters include model paths, training epochs, optimizer settings, learning rate, and dimensions for network and conditioning embeddings. ```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" ``` -------------------------------- ### Prompt File Format for Sample Image Generation Source: https://github.com/kohya-ss/sd-scripts/blob/main/docs/train_network_advanced.md This format is used for specifying prompts and their associated generation parameters in a text file for sample image generation. Lines starting with '#' are comments. Options like '--n', '--w', '--h', '--d', '--l', '--g', and '--s' can be appended to each prompt. ```text # 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 ``` -------------------------------- ### Sample pytest test function Source: https://github.com/kohya-ss/sd-scripts/blob/main/tests/README.md A basic example of a test function written for pytest. Test functions should start with 'test_'. This example asserts that 1 equals 2, which will fail. ```python def test_x(): assert 1 == 2, "Invalid test response" ``` -------------------------------- ### Directory Structure Mapping to Configuration Source: https://github.com/kohya-ss/sd-scripts/blob/main/docs/config_README-en.md Illustrates how image directories map to different configuration registration locations: [[datasets.subsets]], [[datasets]], and [general]. This visual aid helps understand the hierarchy and precedence of settings. ```text C:\ ├─ hoge -> [[datasets.subsets]] No.1 ┐ ┐ ├─ fuga -> [[datasets.subsets]] No.2 |-> [[datasets]] No.1 | ├─ reg -> [[datasets.subsets]] No.3 ┘ |-> [general] └─ piyo -> [[datasets.subsets]] No.4 --> [[datasets]] No.2 ┘ ``` -------------------------------- ### Run pytest tests Source: https://github.com/kohya-ss/sd-scripts/blob/main/tests/README.md Execute all tests discovered by pytest in the current directory. Ensure pytest is installed before running. ```bash pytest ``` -------------------------------- ### Select Logging Tool Source: https://github.com/kohya-ss/sd-scripts/blob/main/docs/train_leco.md The --log_with argument specifies the logging tool to use. Options include 'tensorboard', 'wandb', or 'all'. ```bash --log_with="tensorboard" ``` -------------------------------- ### Specify Additional LoRA Network Arguments (Conv2d with default alpha) Source: https://github.com/kohya-ss/sd-scripts/blob/main/docs/train_network.md This example demonstrates specifying the Conv2d dimension while omitting alpha, which will default to 1. ```bash --network_args "conv_dim=4" ``` -------------------------------- ### Import AI Agent Prompts Source: https://github.com/kohya-ss/sd-scripts/blob/main/README.md Import the repository's recommended prompts for AI agents like Claude and Gemini by adding this line to your configuration file. ```markdown @./.ai/claude.prompt.md ``` ```markdown @./.ai/gemini.prompt.md ``` -------------------------------- ### Specify Additional LoRA Network Arguments (Conv2d) Source: https://github.com/kohya-ss/sd-scripts/blob/main/docs/train_network.md Used for LoRA-specific parameters. This example shows how to set the rank and alpha for Conv2d (3x3) LoRA (LoRA-C3Lier). ```bash --network_args "conv_dim=4" "conv_alpha=1" ``` -------------------------------- ### Include Final Layer in LoRA Training Source: https://github.com/kohya-ss/sd-scripts/blob/main/docs/anima_train_network.md Example of using network_args to include the final layer in LoRA training. Patterns are matched against the full module name. ```bash --network_args "include_patterns=['.*final_layer.*']" ``` -------------------------------- ### Set Attention Implementation Mode Source: https://github.com/kohya-ss/sd-scripts/blob/main/docs/anima_train_network.md Choose the attention implementation: 'torch' (default), 'xformers', 'flash', or 'sageattn'. 'xformers' requires '--split_attn'. 'sageattn' is for inference only. ```bash --attn_mode ``` -------------------------------- ### Upgrade Repository and Dependencies Source: https://github.com/kohya-ss/sd-scripts/blob/main/README.md Commands to pull the latest changes from the repository, reactivate the virtual environment, and upgrade all dependencies. ```powershell cd sd-scripts git pull .\venv\Scripts\activate pip install --use-pep517 --upgrade -r requirements.txt ``` -------------------------------- ### Captioning with Token String Source: https://github.com/kohya-ss/sd-scripts/blob/main/docs/train_textual_inversion.md Example of how to format captions for Textual Inversion, ensuring the specified token string is included. This is crucial for the model to recognize the custom token. ```text mychar, 1girl, blonde hair, blue eyes ``` -------------------------------- ### Multi-Resolution Dataset Configuration Source: https://github.com/kohya-ss/sd-scripts/blob/main/docs/flux_train_network.md Define multiple resolutions with different batch sizes in the dataset configuration file. This TOML example shows settings for two different resolutions. ```toml [general] # Common settings flip_aug = true color_aug = false keep_tokens_separator= "|||" shuffle_caption = false caption_extension = ".txt" [[datasets]] # First resolution settings batch_size = 2 enable_bucket = true resolution = [1024, 1024] [[datasets.subsets]] image_dir = "path/to/image/directory" num_repeats = 1 [[datasets]] # Second resolution settings batch_size = 3 enable_bucket = true resolution = [768, 768] [[datasets.subsets]] image_dir = "path/to/image/directory" num_repeats = 1 ``` -------------------------------- ### Recommended Settings for Chroma Models Source: https://github.com/kohya-ss/sd-scripts/blob/main/docs/flux_train_network.md Use these settings for Chroma models, which require specific guidance scale and timestep sampling configurations. ```bash --timestep_sampling sigmoid --model_prediction_type raw --guidance_scale 0.0 ``` -------------------------------- ### Dynamic Prompt: Enumeration Source: https://github.com/kohya-ss/sd-scripts/blob/main/docs/gen_img_README.md Shows how to use all items from a list in order (enumeration) and how multiple enumerated lists generate all combinations. ```text {e$$red|blue} flower, {e$$1girl|2girls} ``` -------------------------------- ### Exclude MLP Layers from LoRA Training Source: https://github.com/kohya-ss/sd-scripts/blob/main/docs/anima_train_network.md Example of using network_args to additionally exclude MLP layers from LoRA training. Patterns are matched against the full module name. ```bash --network_args "exclude_patterns=['.*mlp.*']" ``` -------------------------------- ### Multi-line Captions Example (JSON Metadata) Source: https://github.com/kohya-ss/sd-scripts/blob/main/docs/config_README-en.md Shows how multi-line captions are structured within a JSON metadata file. Line breaks are represented by '\n', and tags are appended to each caption line. ```json { "/path/to/image.png": { "caption": "a cartoon of a frog with the word frog on it\ntest multiline caption1\ntest multiline caption2", "tags": "open mouth, simple background, standing, no humans, animal, black background, frog, animal costume, animal focus" }, ... } ``` -------------------------------- ### Template Usage for Styles Source: https://github.com/kohya-ss/sd-scripts/blob/main/docs/train_textual_inversion.md Command-line arguments for specifying training templates. Use '--use_object_template' for characters/objects and '--use_style_template' for artistic styles. ```bash --use_object_template ``` ```bash --use_style_template ``` -------------------------------- ### Run LoRA Training Command Source: https://github.com/kohya-ss/sd-scripts/blob/main/docs/validation.md Launch the LoRA training process using accelerate and specify all necessary parameters including model paths, dataset configuration, output directories, and training hyperparameters. Ensure logging is enabled to track validation loss. ```bash accelerate launch sdxl_train_network.py \ --pretrained_model_name_or_path="sd_xl_base_1.0.safetensors" \ --dataset_config="dataset_config.toml" \ --output_dir="output" \ --output_name="my_lora" \ --network_module=networks.lora \ --network_dim=32 \ --network_alpha=16 \ --save_every_n_epochs=1 \ --learning_rate=1e-4 \ --optimizer_type="AdamW8bit" \ --mixed_precision="bf16" \ --logging_dir=logs ``` -------------------------------- ### SDXL Training Command Source: https://github.com/kohya-ss/sd-scripts/blob/main/docs/train_leco.md Basic command to launch LoRA training for SDXL models using accelerate. Ensure all arguments are on a single line when executing. ```bash accelerate launch --mixed_precision bf16 sdxl_train_leco.py --pretrained_model_name_or_path="sdxl_model.safetensors" --prompts_file="slider.toml" --output_dir="output" --output_name="my_sdxl_slider" --network_dim=8 --network_alpha=4 --learning_rate=1e-4 --optimizer_type="AdamW8bit" --max_train_steps=1000 --max_denoising_steps=40 --mixed_precision=bf16 --sdpa --gradient_checkpointing --save_every_n_steps=200 ``` -------------------------------- ### Configuring Additional LoRA Network Arguments Source: https://github.com/kohya-ss/sd-scripts/blob/main/docs/train_network.md The --network_args parameter allows specifying additional parameters specific to LoRA modules. For example, to use LoRA-C3Lier (Conv2d 3x3), you can specify 'conv_dim' and 'conv_alpha'. ```bash --network_args "conv_dim=4" "conv_alpha=1" ``` ```bash --network_args "conv_dim=4" ``` -------------------------------- ### Run FLUX.1 Training Command Source: https://github.com/kohya-ss/sd-scripts/blob/main/docs/flux_train_network.md This command initiates the FLUX.1 model training process. Ensure all model paths and configuration files are correctly specified. ```bash accelerate launch --num_cpu_threads_per_process 1 flux_train_network.py \ --pretrained_model_name_or_path="" \ --clip_l="" \ --t5xxl="" \ --ae="" \ --dataset_config="my_flux_dataset_config.toml" \ --output_dir="" \ --output_name="my_flux_lora" \ --save_model_as=safetensors \ --network_module=networks.lora_flux \ --network_dim=16 \ --network_alpha=1 \ --learning_rate=1e-4 \ --optimizer_type="AdamW8bit" \ --lr_scheduler="constant" \ --sdpa \ --max_train_epochs=10 \ --save_every_n_epochs=1 \ --mixed_precision="fp16" \ --gradient_checkpointing \ --guidance_scale=1.0 \ --timestep_sampling="flux_shift" \ --model_prediction_type="raw" \ --blocks_to_swap=18 \ --cache_text_encoder_outputs \ --cache_latents ``` -------------------------------- ### Basic Fine-tuning Command Structure Source: https://github.com/kohya-ss/sd-scripts/blob/main/docs/fine_tune.md This is the common command structure for fine-tuning scripts across different architectures. Ensure you replace placeholders like `` with your specific paths. ```bash accelerate launch --mixed_precision bf16 {script_name}.py \ --pretrained_model_name_or_path \ --dataset_config \ --output_dir \ --output_name \ --save_model_as safetensors \ --max_train_steps 10000 \ --learning_rate 1e-5 \ --optimizer_type AdamW8bit ``` -------------------------------- ### Converting ai-toolkit YAML to TOML Source: https://github.com/kohya-ss/sd-scripts/blob/main/docs/train_leco.md Demonstrates the conversion of an ai-toolkit style YAML configuration to TOML format, highlighting key syntax differences. ```yaml targets: - target_class: "" positive: "high detail" negative: "low detail" multiplier: 1.0 guidance_scale: 1.0 resolution: 512 ``` ```toml guidance_scale = 1.0 resolution = 512 [[targets]] target_class = "" positive = "high detail" negative = "low detail" multiplier = 1.0 ``` -------------------------------- ### SD 1.x/2.x Training Command Source: https://github.com/kohya-ss/sd-scripts/blob/main/docs/train_leco.md Basic command to launch LoRA training for SD 1.x/2.x models using accelerate. Ensure all arguments are on a single line when executing. ```bash accelerate launch --mixed_precision bf16 train_leco.py --pretrained_model_name_or_path="model.safetensors" --prompts_file="prompts.toml" --output_dir="output" --output_name="my_leco" --network_dim=8 --network_alpha=4 --learning_rate=1e-4 --optimizer_type="AdamW8bit" --max_train_steps=500 --max_denoising_steps=40 --mixed_precision=bf16 --sdpa --gradient_checkpointing --save_every_n_steps=100 ``` -------------------------------- ### Regional LoRA Prompting Example Source: https://github.com/kohya-ss/sd-scripts/blob/main/docs/gen_img_README.md Defines multiple prompt regions using ' AND '. The R, G, and B channels of a mask image correspond to the first three regions, respectively. Subsequent regions and negative prompts apply to the entire image. ```text shs 2girls, looking at viewer, smile AND bsb 2girls, looking back AND 2girls --n bad quality, worst quality ``` -------------------------------- ### Run Image Generation in Interactive Mode Source: https://github.com/kohya-ss/sd-scripts/blob/main/docs/gen_img_README.md Use this command to start the image generation script in interactive mode. Specify your model checkpoint and output directory. Options like `--xformers` and `--fp16` can be used for performance and precision. ```batchfile python gen_img.py --ckpt --outdir --xformers --fp16 --interactive ``` -------------------------------- ### Recommended Settings for FLUX.1 Training Source: https://github.com/kohya-ss/sd-scripts/blob/main/docs/flux_train_network.md Use these settings for general FLUX.1 model training. They optimize timestep sampling and model prediction. ```bash --timestep_sampling shift --discrete_flow_shift 3.1582 --model_prediction_type raw --guidance_scale 1.0 ``` -------------------------------- ### Specify Qwen-Image VAE Model Path Source: https://github.com/kohya-ss/sd-scripts/blob/main/docs/anima_train_network.md Provide the path to the Qwen-Image VAE model. ```bash --vae="" ``` -------------------------------- ### Run Lumina Network Training Source: https://github.com/kohya-ss/sd-scripts/blob/main/docs/lumina_train_network.md Execute the lumina_train_network.py script with necessary model and dataset configurations. Ensure all paths and parameters are correctly set for your training environment. ```bash accelerate launch --num_cpu_threads_per_process 1 lumina_train_network.py \ --pretrained_model_name_or_path="lumina-image-2.safetensors" \ --gemma2="gemma-2-2b.safetensors" \ --ae="ae.safetensors" \ --dataset_config="my_lumina_dataset_config.toml" \ --output_dir="./output" \ --output_name="my_lumina_lora" \ --save_model_as=safetensors \ --network_module=networks.lora_lumina \ --network_dim=8 \ --network_alpha=8 \ --learning_rate=1e-4 \ --optimizer_type="AdamW" \ --lr_scheduler="constant" \ --timestep_sampling="nextdit_shift" \ --discrete_flow_shift=6.0 \ --model_prediction_type="raw" \ --system_prompt="You are an assistant designed to generate high-quality images based on user prompts." \ --max_train_epochs=10 \ --save_every_n_epochs=1 \ --mixed_precision="bf16" \ --gradient_checkpointing \ --cache_latents \ --cache_text_encoder_outputs ``` -------------------------------- ### Configuring Multi-Resolution Datasets with Skip Image Resolution Source: https://github.com/kohya-ss/sd-scripts/blob/main/docs/config_README-en.md Illustrates the use of `enable_bucket`, `bucket_no_upscale`, `max_bucket_reso`, and `skip_image_resolution` for managing multi-resolution training data and preventing image overlap. ```toml [general] enable_bucket = true bucket_no_upscale = true max_bucket_reso = 1536 [[datasets]] resolution = 768 [[datasets.subsets]] image_dir = 'C:\hoge' [[datasets]] resolution = 1024 skip_image_resolution = 768 [[datasets.subsets]] image_dir = 'C:\hoge' [[datasets]] resolution = 1280 skip_image_resolution = 1024 [[datasets.subsets]] image_dir = 'C:\hoge' ``` -------------------------------- ### Basic Image Generation with Text-to-Image Source: https://github.com/kohya-ss/sd-scripts/blob/main/docs/gen_img_README.md Generates images using a specified checkpoint, output directory, and various generation parameters. Supports xformers and fp16 for optimization. Includes detailed prompt with negative prompts. ```batchfile python gen_img.py --ckpt trinart_characters_it4_v1_vae_merged.ckpt \ --outdir outputs --xformers --fp16 --scale 12.5 --sampler k_euler --steps 32 \ --image_path template.png --strength 0.8 \ --prompt "1girl, cowboy shot, brown hair, pony tail, brown eyes, \ sailor school uniform, outdoors \ --n lowres, bad anatomy, bad hands, error, missing fingers, cropped, \ worst quality, low quality, normal quality, jpeg artifacts, (blurry), \ hair ornament, glasses" \ --batch_size 8 --images_per_prompt 32 ``` -------------------------------- ### Using Negative Prompts and Prompt Weighting Source: https://github.com/kohya-ss/sd-scripts/blob/main/docs/gen_img_README.md Demonstrates the syntax for specifying negative prompts using the `--n` flag and applying prompt weighting with parentheses and colons, similar to AUTOMATIC1111's Web UI. ```batchfile python gen_img.py --ckpt --outdir --xformers --fp16 --prompt "(positive prompt:1.3) --n (negative prompt)" ``` -------------------------------- ### Recommended Max Train Steps Settings Source: https://github.com/kohya-ss/sd-scripts/blob/main/docs/train_leco.md Recommended ranges for --max_train_steps. For SD 1.x/2.x, use 300-1000 steps. For SDXL, use 500-2000 steps. ```bash --max_train_steps=300 ``` ```bash --max_train_steps=500 ``` -------------------------------- ### Optimizer Selection and Arguments Source: https://github.com/kohya-ss/sd-scripts/blob/main/docs/train_network_advanced.md Choose an optimizer for training, such as AdamW8bit or Adafactor. Additional arguments can be passed to the selected optimizer using key=value pairs. ```shell --optimizer_type="AdamW8bit" --optimizer_args "weight_decay=0.01" "betas=0.9,0.999" ``` ```shell --optimizer_type="Adafactor" --optimizer_args "relative_step=True" ``` -------------------------------- ### Recommended Batch Size Settings Source: https://github.com/kohya-ss/sd-scripts/blob/main/docs/train_leco.md Recommended batch size for training. Use 1-4 for both SD 1.x/2.x and SDXL. This is typically set in the TOML configuration. ```toml batch_size = 1 ``` ```toml batch_size = 1 ``` -------------------------------- ### Run HunyuanImage-2.1 Training Source: https://github.com/kohya-ss/sd-scripts/blob/main/docs/hunyuan_image_train_network.md This command launches the training process for HunyuanImage-2.1 models using accelerate. Ensure all required model paths and dataset configurations are correctly specified. ```bash accelerate launch --num_cpu_threads_per_process 1 hunyuan_image_train_network.py \ --pretrained_model_name_or_path="" \ --text_encoder="" \ --byt5="" \ --vae="" \ --dataset_config="my_hunyuan_dataset_config.toml" \ --output_dir="" \ --output_name="my_hunyuan_lora" \ --save_model_as=safetensors \ --network_module=networks.lora_hunyuan_image \ --network_dim=16 \ --network_alpha=1 \ --network_train_unet_only \ --learning_rate=1e-4 \ --optimizer_type="AdamW8bit" \ --lr_scheduler="constant" \ --attn_mode="torch" \ --split_attn \ --max_train_epochs=10 \ --save_every_n_epochs=1 \ --mixed_precision="bf16" \ --gradient_checkpointing \ --model_prediction_type="raw" \ --discrete_flow_shift=5.0 \ --blocks_to_swap=18 \ --cache_text_encoder_outputs \ --cache_latents ``` -------------------------------- ### Fine-tune Lumina-Next DiT Model Source: https://github.com/kohya-ss/sd-scripts/blob/main/docs/fine_tune.md Command for fine-tuning Lumina-Next DiT models. It can leverage Flash Attention for faster computation. ```bash accelerate launch --mixed_precision bf16 lumina_train.py \ --pretrained_model_name_or_path "Lumina-Next-DiT-B.safetensors" \ --dataset_config "dataset_config.toml" \ --output_dir "output" \ --output_name "lumina_finetuned" \ --learning_rate 1e-5 ``` -------------------------------- ### Launch SDXL Latent Caching Script Source: https://github.com/kohya-ss/sd-scripts/blob/main/docs/train_SDXL-en.md Launches the script to cache latents to disk for SDXL training. Ensure to specify the correct number of CPU threads per process. ```bash accelerate launch --num_cpu_threads_per_process 1 tools/cache_latents.py ... ``` -------------------------------- ### Recommended Guidance Scale Settings Source: https://github.com/kohya-ss/sd-scripts/blob/main/docs/train_leco.md Recommended guidance scale values for training. For SD 1.x/2.x, use 1.0-2.0. For SDXL, use 1.0-3.0. This is typically set in the TOML configuration. ```toml guidance_scale = 1.0 ``` ```toml guidance_scale = 1.0 ``` -------------------------------- ### Recommended Resolution Settings Source: https://github.com/kohya-ss/sd-scripts/blob/main/docs/train_leco.md Recommended base resolution for training. Use 512 for SD 1.x/2.x and 1024 for SDXL. This is typically set in the TOML configuration. ```toml resolution = 512 ``` ```toml resolution = 1024 ``` -------------------------------- ### Recommended HunyuanImage-2.1 Training Settings Source: https://github.com/kohya-ss/sd-scripts/blob/main/docs/hunyuan_image_train_network.md These are the recommended default settings for HunyuanImage-2.1 training, optimizing model prediction processing for best results. ```bash --model_prediction_type raw --discrete_flow_shift 5.0 ``` -------------------------------- ### Inpainting Training Prompt with Reference Image Source: https://github.com/kohya-ss/sd-scripts/blob/main/docs/inpainting_training.md Configure prompts for inpainting training to include a reference image for masked regions. The image path must not contain ' --'. ```text a photo of a cat sitting on a sofa --i /path/to/reference.jpg --w 512 --h 512 --d 42 ``` -------------------------------- ### Configuring Logging Directory Source: https://github.com/kohya-ss/sd-scripts/blob/main/docs/train_network.md Specify the --logging_dir to direct logs for tools like TensorBoard. If omitted, no logs will be generated. ```bash --logging_dir="" ``` -------------------------------- ### Specifying Dataset Configuration File Source: https://github.com/kohya-ss/sd-scripts/blob/main/docs/train_network.md Use --dataset_config to point to a .toml file containing dataset configurations. Using a .toml file is recommended over specifying dataset settings directly on the command line due to length. ```bash --dataset_config="<設定ファイルのパス>" ``` -------------------------------- ### Train Textual Inversion for SDXL Models Source: https://github.com/kohya-ss/sd-scripts/blob/main/docs/train_textual_inversion.md Launches the Textual Inversion training script for Stable Diffusion XL models. Ensure dataset configuration and model paths are correctly set. ```bash accelerate launch --num_cpu_threads_per_process 1 sdxl_train_textual_inversion.py \ --pretrained_model_name_or_path="path/to/sdxl_model.safetensors" \ --dataset_config="dataset_config.toml" \ --output_dir="output" \ --output_name="my_sdxl_textual_inversion" \ --save_model_as="safetensors" \ --token_string="mychar" \ --init_word="girl" \ --num_vectors_per_token=4 \ --max_train_steps=1600 \ --learning_rate=1e-6 \ --optimizer_type="AdamW8bit" \ --mixed_precision="fp16" \ --cache_latents \ --sdpa ```