Stable Diffusion LoRA微调API
请求方法
POST
请求地址
https://api.lanrui.co/api/sd/train/lora
CURL 示例
curl --location 'https://api.lanrui.co/api/sd/train/lora' \
--header 'Content-Type: application/json' \
--header 'Authorization: Bearer {填入API Key,删除花括号}' \
--data '{
"pretrained_model_name_or_path": "runwayml/stable-diffusion-v1-5",
"":
"LoRA_type": "LyCORIS/iA3",
"adaptive_noise_scale": 0.005,
"caption_dropout_rate": 0.5,
"epoch": 300,
"gradient_accumulation_steps": 1,
"keep_tokens": 1,
"learning_rate": 1.0,
"lr_scheduler": "constant",
"lr_warmup": 0,
"min_snr_gamma": 5,
"network_alpha": 1024,
"network_dim": 1024,
"network_dropout": 0.3,
"noise_offset": 0.05,
"noise_offset_type": "Original",
"optimizer": "Prodigy",
"optimizer_args": "d_coef=1.0 weight_decay=0.01 safeguard_warmup=False use_bias_correction=False",
"save_every_n_epochs": 1,
"scale_weight_norms": 1,
"seed": "0",
"shuffle_caption": true,
"text_encoder_lr": 1.0,
"train_batch_size": 1,
"unet_lr": 1.0
}'
请求 Body 参数(application/json)
参数名 | 参数类型 | 取值范围 | 参数释义 | 是否必填 |
---|---|---|---|---|
pretrained_model_name_or_path | string | 默认值: runwayml/stable-diffusion-v1-5 取值范围: stabilityai/stable-diffusion-xl-base-1.0 runwayml/stable-diffusion-v1-5 | Pretrained model name | 否 |
sdxl | boolean | 默认值: False | sdxl | 否 |
repeats | integer | 默认值: 10 | The number of times an image is reused within an epoch | 否 |
train_batch_size | integer | 默认值: 1 取值范围: [1, inf) | Batch size for training | 否 |
epoch | integer | 默认值: 20 取值范围: [1, inf) | Epoch size for training | 否 |
mixed_precision | string | 默认值: fp16 取值范围: no fp16 bf16 fp8 | Whether or not to use mixed precision training | 否 |
train_data_dir | string | 默认值: 空 | Image folder (containing training images subfolders) | 否 |
max_resolution | string | 默认值: 512,512 | Max resolution (width, height) | 否 |
color_aug | boolean | 默认值: False | Enable weak color augmentation | 否 |
flip_aug | boolean | 默认值: False | Enable horizontal flip augmentation | 否 |
output_dir | string | 默认值: 空 | Output directory for trained model | 否 |
save_every_n_epochs | integer | 默认值: 10 取值范围: [1, inf) | Save every N epochs | 否 |
save_precision | string | 默认值: fp16 取值范围: float fp16 bf16 | Save precision | 否 |
learning_rate | number | 默认值: 0.0001 | Learning rate (Set to 0 to not train the Unet) | 否 |
text_encoder_lr | number | 默认值: 0.0001 取值范围: [0.0, inf) | Text Encoder learning rate (Optional) | 否 |
unet_lr | number | 默认值: 0.0001 取值范围: [0.0, inf) | Unet learning rate (Optional) | 否 |
lr_scheduler | string | 默认值: constant 取值范围: constant adafactor constant_with_warmup cosine cosine_with_restarts linear polynomial | LR Scheduler | 否 |
lr_warmup | number | 默认值: 0 取值范围: [0.0, inf) | LR warmup (% of total steps) Can't use LR warmup with LR Scheduler constant... setting to 0 and disabling field... | 否 |
lr_scheduler_num_cycles | integer | 默认值: 1 取值范围: [1, inf) | Number of restarts for cosine scheduler with restarts | 否 |
lr_scheduler_power | number | 默认值: 1.0 取值范围: [0.0, inf) | Polynomial power for polynomial scheduler | 否 |
optimizer | string | 默认值: PagedAdamW8bit 取值范围: AdamW AdamW8bit Adafactor DAdaptation DAdaptAdaGrad DAdaptAdam DAdaptAdan DAdaptAdanIP DAdaptAdamPreprint DAdaptLion DAdaptSGD Lion Lion8bit PagedAdamW8bit PagedAdamW32bit PagedLion8bit Prodigy SGDNesterov SGDNesterov8bit | Optimizer | 否 |
max_grad_norm | number | 默认值: 1.0 取值范围: [0.0, 1.0] | Max grad norm | 否 |
min_snr_gamma | integer | 默认值: 0 取值范围: [0, 20] | Recommended value of 5 when used | 否 |
shuffle_caption | boolean | 默认值: False | Shuffle caption | 否 |
keep_tokens | integer | 默认值: 0 取值范围: [0, 32] | Keep n tokens | 否 |
max_token_length | integer | 默认值: 75 取值范围: 75 150 225 | max token length of text encoder | 否 |
noise_offset_type | string | 默认值: Original 取值范围: Original Multires | Noise offset type | 否 |
noise_offset | number | 默认值: 0 取值范围: [0.0, 1.0] | Recommended values are 0.05 - 0.15 | 否 |
noise_offset_random_strength | boolean | 默认值: False | Use random strength between 0~noise_offset for noise offset | 否 |
adaptive_noise_scale | number | 默认值: 0 取值范围: [-1.0, 1.0] | Add latent mean absolute value * this value to noise_offset | 否 |
multires_noise_iterations | integer | 默认值: 0 取值范围: [0, 64] | Enable multires noise (recommended values are 6-10) | 否 |
multires_noise_discount | number | 默认值: 0.3 取值范围: [0.0, 1.0] | Recommended values are 0.8. For LoRAs with small datasets, 0.1-0.3 | 否 |
sample_every_n_epochs | integer | 默认值: 0 | Sample every n epochs | 否 |
sample_sampler | string | 默认值: euler_a 取值范围: ddim pndm lms euler euler_a heun dpm_2 dpm_2_a dpmsolver dpmsolver++ dpmsingle k_lms k_euler k_euler_a k_dpm_2 k_dpm_2_a | Sample sampler | 否 |
sample_prompts | string | 默认值: 空 | Enter one sample prompt per line to generate multiple samples per cycle. Optional specifiers include: --w (width), --h (height), --d (seed), --l (cfg scale), --s (sampler steps) and --n (negative prompt). eg: 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 | 否 |
seed | integer | 默认值: 0 取值范围: [0, inf) | Seed (Set to 0 to make random) | 否 |
clip_skip | integer | 默认值: 1 取值范围: [0, 12] | Clip skip | 否 |
stop_text_encoder_training_pct | integer | 默认值: 0 取值范围: [0, 100] | Stop TE (% of total steps) | 否 |
gradient_accumulation_steps | integer | 默认值: 1 取值范围: [1, 120] | Number of updates steps to accumulate before performing a backward/update pass | 否 |
optimizer_args | string | 默认值: 空 | (Optional) eg: relative_step=True scale_parameter=True warmup_init=True | 否 |
lr_scheduler_args | string | 默认值: 空 | (Optional) eg: milestones=[1,10,30,50] gamma=0.1 | 否 |
enable_bucket | boolean | 默认值: True | Enable buckets | 否 |
random_crop | boolean | 默认值: False | Random crop instead of center crop | 否 |
min_bucket_reso | integer | 默认值: 64 取值范围: [64, 4096] | Minimum size in pixel a bucket can be (>= 64) | 否 |
max_bucket_reso | integer | 默认值: 2048 取值范围: [64, 4096] | Maximum size in pixel a bucket can be (>= 64) | 否 |
bucket_no_upscale | boolean | 默认值: True | Don't upscale bucket resolution | 否 |
bucket_reso_steps | integer | 默认值: 64 取值范围: [1, 128] | Bucket resolution steps | 否 |
caption_dropout_every_n_epochs | integer | 默认值: 0 | Dropout caption every n epochs | 否 |
caption_dropout_rate | number | 默认值: 0 取值范围: [0.0, 1.0] | Rate of caption dropout | 否 |
weighted_captions | boolean | 默认值: False | Enable weighted captions in the standard style (token:1.3). No commas inside parens, or shuffle/dropout may break the decoder. | 否 |
ip_noise_gamma | number | 默认值: 0 取值范围: [0.0, 1.0] | Enable input perturbation noise. used for regularization. recommended value: around 0.1 | 否 |
ip_noise_gamma_random_strength | boolean | 默认值: False | Use random strength between 0~ip_noise_gamma for input perturbation noise | 否 |
min_timestep | integer | 默认值: 0 取值范围: [0, 1000] | Values greater than 0 will make the model more img2img focussed. 0 = image only | 否 |
max_timestep | integer | 默认值: 1000 取值范围: [0, 1000] | Values lower than 1000 will make the model more img2img focussed. 1000 = noise only | 否 |
LoRA_type | string | 默认值: Standard 取值范围: Kohya DyLoRA Kohya LoCon LoRA-FA LyCORIS/iA3 LyCORIS/BOFT LyCORIS/Diag-OFT LyCORIS/DyLoRA LyCORIS/GLoRA LyCORIS/LoCon LyCORIS/LoHa LyCORIS/LoKr LyCORIS/Native Fine-Tuning Standard | LoRA type | 否 |
LyCORIS_preset | string | 默认值: full 取值范围: attn-mlp attn-only full full-lin unet-transformer-only unet-convblock-only | LyCORIS Preset | 否 |
network_dim | integer | 默认值: 8 取值范围: [1, 512] | Network Rank (Dimension) | 否 |
network_alpha | number | 默认值: 1.0 取值范围: [1e-05, 1024.0] | Alpha for LoRA weight scaling | 否 |
conv_dim | integer | 默认值: 1 取值范围: [0, 512] | Convolution Rank (Dimension) | 否 |
conv_alpha | integer | 默认值: 1 取值范围: [0, 512] | Convolution Alpha | 否 |
factor | integer | 默认值: -1 取值范围: [-1, 64] | LoKr factor | 否 |
bypass_mode | boolean | 默认值: False | Designed for bnb 8bit/4bit linear layer. (QLyCORIS) | 否 |
dora_wd | boolean | 默认值: False | Enable the DoRA method for these algorithms | 否 |
use_cp | boolean | 默认值: False | A two-step approach utilizing tensor decomposition and fine-tuning to accelerate convolution layers in large neural networks, resulting in significant CPU speedups with minor accuracy drops. | 否 |
use_tucker | boolean | 默认值: False | Efficiently decompose tensor shapes, resulting in a sequence of convolution layers with varying dimensions and Hadamard product implementation through multiplication of two distinct tensors. | 否 |
use_scalar | boolean | 默认值: False | Train an additional scalar in front of the weight difference, use a different weight initialization strategy. | 否 |
rank_dropout_scale | boolean | 默认值: False | Adjusts the scale of the rank dropout to maintain the average dropout rate, ensuring more consistent regularization across different layers. | 否 |
constrain | number | 默认值: 0.0 | Limits the norm of the oft_blocks, ensuring that their magnitude does not exceed a specified threshold, thus controlling the extent of the transformation applied. | 否 |
rescaled | boolean | 默认值: False | Applies an additional scaling factor to the oft_blocks, allowing for further adjustment of their impact on the model's transformations. | 否 |
train_norm | boolean | 默认值: False | Selects trainable layers in a network, but trains normalization layers identically across methods as they lack matrix decomposition. | 否 |
decompose_both | boolean | 默认值: False | Controls whether both input and output dimensions of the layer's weights are decomposed into smaller matrices for reparameterization. | 否 |
train_on_input | boolean | 默认值: True | Set if we change the information going into the system (True) or the information coming out of it (False). | 否 |
down_lr_weight | string | 默认值: 空 | Specify the learning rate weight of the down blocks of U-Net. (Optional) eg: 0,0,0,0,0,0,1,1,1,1,1,1 | 否 |
mid_lr_weight | string | 默认值: 空 | Specify the learning rate weight of the mid block of U-Net. (Optional) eg: 0.5 | 否 |
up_lr_weight | string | 默认值: 空 | Specify the learning rate weight of the up blocks of U-Net. The same as down_lr_weight. (Optional) eg: 0,0,0,0,0,0,1,1,1,1,1,1 | 否 |
block_lr_zero_threshold | string | 默认值: 空 | If the weight is not more than this value, the LoRA module is not created. The default is 0. (Optional) eg: 0.1 | 否 |
block_dims | string | 默认值: 空 | Specify the dim (rank) of each block. Specify 25 numbers. (Optional) eg: 2,2,2,2,4,4,4,4,6,6,6,6,8,6,6,6,6,4,4,4,4,2,2,2,2 | 否 |
block_alphas | string | 默认值: 空 | Specify the alpha of each block. Specify 25 numbers as with block_dims. If omitted, the value of network_alpha is used. (Optional) eg: 2,2,2,2,4,4,4,4,6,6,6,6,8,6,6,6,6,4,4,4,4,2,2,2,2 | 否 |
conv_block_dims | string | 默认值: 空 | Extend LoRA to Conv2d 3x3 and specify the dim (rank) of each block. Specify 25 numbers. (Optional) eg: 2,2,2,2,4,4,4,4,6,6,6,6,8,6,6,6,6,4,4,4,4,2,2,2,2 | 否 |
conv_block_alphas | string | 默认值: 空 | Specify the alpha of each block when expanding LoRA to Conv2d 3x3. Specify 25 numbers. If omitted, the value of conv_alpha is used. (Optional) eg: 2,2,2,2,4,4,4,4,6,6,6,6,8,6,6,6,6,4,4,4,4,2,2,2,2 | 否 |
scale_weight_norms | number | 默认值: 0 取值范围: [0.0, 10.0] | Max Norm Regularization is a technique to stabilize network training by limiting the norm of network weights. It may be effective in suppressing overfitting of LoRA and improving stability when used with other LoRAs. See PR #545 on kohya_ss/sd_scripts repo for details. Recommended setting: 1. Higher is weaker, lower is stronger. | 否 |
network_dropout | number | 默认值: 0.0 取值范围: [0.0, 1.0] | Is a normal probability dropout at the neuron level. In the case of LoRA, it is applied to the output of down. Recommended range 0.1 to 0.5 | 否 |
rank_dropout | number | 默认值: 0.0 取值范围: [0.0, 1.0] | Can specify rank_dropout to dropout each rank with specified probability. Recommended range 0.1 to 0.3 | 否 |
module_dropout | number | 默认值: 0.0 取值范围: [0.0, 1.0] | Can specify module_dropout to dropout each rank with specified probability. Recommended range 0.1 to 0.3 | 否 |
unit | integer | 默认值: 1 取值范围: [1, 64] | DyLoRA Unit / Block size | 否 |
下表展示了与不同的LoRA_type相关的具体参数:
参数名/ LoRA_type | Kohya DyLoRA | Kohya LoCon | LoRA-FA | LyCORIS/iA3 | LyCORIS/BOFT | LyCORIS/Diag-OFT | LyCORIS/DyLoRA | LyCORIS/GLoRA | LyCORIS/LoCon | LyCORIS/LoHa | LyCORIS/LoKr | LyCORIS/Native Fine-Tuning | Standard |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|
LyCORIS_preset | - | - | - | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | - |
network_alpha | ✓ | ✓ | ✓ | - | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | - | ✓ |
conv_dim | - | - | - | - | - | - | - | - | - | - | - | - | - |
conv_alpha | - | - | - | - | - | - | - | - | - | - | - | - | - |
factor | - | - | - | - | - | - | - | - | - | - | ✓ | - | - |
bypass_mode | - | - | - | - | - | - | - | - | ✓ | ✓ | ✓ | - | - |
dora_wd | - | - | - | - | - | - | - | - | ✓ | ✓ | ✓ | - | - |
use_cp | - | - | - | - | - | - | - | - | - | - | - | - | - |
use_tucker | - | - | - | - | ✓ | ✓ | ✓ | - | ✓ | ✓ | - | ✓ | - |
use_scalar | - | - | - | - | ✓ | ✓ | - | - | ✓ | ✓ | ✓ | ✓ | - |
rank_dropout_scale | - | - | - | - | ✓ | ✓ | - | ✓ | ✓ | ✓ | ✓ | ✓ | - |
constrain | - | - | - | - | ✓ | ✓ | - | - | - | - | - | - | - |
rescaled | - | - | - | - | ✓ | ✓ | - | - | - | - | - | - | - |
train_norm | - | - | - | - | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | - |
decompose_both | - | - | - | - | - | - | - | - | - | - | ✓ | - | - |
train_on_input | - | - | - | ✓ | - | - | - | - | - | - | - | - | - |
down_lr_weight | ✓ | ✓ | ✓ | - | - | - | - | - | - | - | - | - | ✓ |
mid_lr_weight | ✓ | ✓ | ✓ | - | - | - | - | - | - | - | - | - | ✓ |
up_lr_weight | ✓ | ✓ | ✓ | - | - | - | - | - | - | - | - | - | ✓ |
block_lr_zero_threshold | ✓ | ✓ | ✓ | - | - | - | - | - | - | - | - | - | ✓ |
block_dims | ✓ | ✓ | ✓ | - | - | - | - | - | - | - | - | - | ✓ |
block_alphas | ✓ | ✓ | ✓ | - | - | - | - | - | - | - | - | - | ✓ |
conv_block_dims | ✓ | ✓ | ✓ | - | - | - | - | - | - | - | - | - | ✓ |
conv_block_alphas | ✓ | ✓ | ✓ | - | - | - | - | - | - | - | - | - | ✓ |
scale_weight_norms | ✓ | ✓ | ✓ | - | - | - | ✓ | ✓ | ✓ | ✓ | ✓ | - | ✓ |
network_dropout | ✓ | ✓ | ✓ | - | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
rank_dropout | ✓ | ✓ | ✓ | - | ✓ | ✓ | - | ✓ | ✓ | ✓ | - | ✓ | ✓ |
module_dropout | ✓ | ✓ | ✓ | - | ✓ | ✓ | - | ✓ | ✓ | ✓ | - | ✓ | ✓ |
unit | ✓ | - | - | - | - | - | ✓ | - | - | - | - | - | - |