跳到主要内容

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_pathstring默认值: runwayml/stable-diffusion-v1-5
取值范围:
stabilityai/stable-diffusion-xl-base-1.0
runwayml/stable-diffusion-v1-5
Pretrained model name
sdxlboolean默认值: False
sdxl
repeatsinteger默认值: 10
The number of times an image is reused within an epoch
train_batch_sizeinteger默认值: 1
取值范围: [1, inf)
Batch size for training
epochinteger默认值: 20
取值范围: [1, inf)
Epoch size for training
mixed_precisionstring默认值: fp16
取值范围:
no
fp16
bf16
fp8
Whether or not to use mixed precision training
train_data_dirstring默认值:
Image folder (containing training images subfolders)
max_resolutionstring默认值: 512,512
Max resolution (width, height)
color_augboolean默认值: False
Enable weak color augmentation
flip_augboolean默认值: False
Enable horizontal flip augmentation
output_dirstring默认值:
Output directory for trained model
save_every_n_epochsinteger默认值: 10
取值范围: [1, inf)
Save every N epochs
save_precisionstring默认值: fp16
取值范围:
float
fp16
bf16
Save precision
learning_ratenumber默认值: 0.0001
Learning rate (Set to 0 to not train the Unet)
text_encoder_lrnumber默认值: 0.0001
取值范围: [0.0, inf)
Text Encoder learning rate (Optional)
unet_lrnumber默认值: 0.0001
取值范围: [0.0, inf)
Unet learning rate (Optional)
lr_schedulerstring默认值: constant
取值范围:
constant
adafactor
constant_with_warmup
cosine
cosine_with_restarts
linear
polynomial
LR Scheduler
lr_warmupnumber默认值: 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_cyclesinteger默认值: 1
取值范围: [1, inf)
Number of restarts for cosine scheduler with restarts
lr_scheduler_powernumber默认值: 1.0
取值范围: [0.0, inf)
Polynomial power for polynomial scheduler
optimizerstring默认值: PagedAdamW8bit
取值范围:
AdamW
AdamW8bit
Adafactor
DAdaptation
DAdaptAdaGrad
DAdaptAdam
DAdaptAdan
DAdaptAdanIP
DAdaptAdamPreprint
DAdaptLion
DAdaptSGD
Lion
Lion8bit
PagedAdamW8bit
PagedAdamW32bit
PagedLion8bit
Prodigy
SGDNesterov
SGDNesterov8bit
Optimizer
max_grad_normnumber默认值: 1.0
取值范围: [0.0, 1.0]
Max grad norm
min_snr_gammainteger默认值: 0
取值范围: [0, 20]
Recommended value of 5 when used
shuffle_captionboolean默认值: False
Shuffle caption
keep_tokensinteger默认值: 0
取值范围: [0, 32]
Keep n tokens
max_token_lengthinteger默认值: 75
取值范围:
75
150
225
max token length of text encoder
noise_offset_typestring默认值: Original
取值范围:
Original
Multires
Noise offset type
noise_offsetnumber默认值: 0
取值范围: [0.0, 1.0]
Recommended values are 0.05 - 0.15
noise_offset_random_strengthboolean默认值: False
Use random strength between 0~noise_offset for noise offset
adaptive_noise_scalenumber默认值: 0
取值范围: [-1.0, 1.0]
Add latent mean absolute value * this value to noise_offset
multires_noise_iterationsinteger默认值: 0
取值范围: [0, 64]
Enable multires noise (recommended values are 6-10)
multires_noise_discountnumber默认值: 0.3
取值范围: [0.0, 1.0]
Recommended values are 0.8. For LoRAs with small datasets, 0.1-0.3
sample_every_n_epochsinteger默认值: 0
Sample every n epochs
sample_samplerstring默认值: 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_promptsstring默认值:
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
seedinteger默认值: 0
取值范围: [0, inf)
Seed (Set to 0 to make random)
clip_skipinteger默认值: 1
取值范围: [0, 12]
Clip skip
stop_text_encoder_training_pctinteger默认值: 0
取值范围: [0, 100]
Stop TE (% of total steps)
gradient_accumulation_stepsinteger默认值: 1
取值范围: [1, 120]
Number of updates steps to accumulate before performing a backward/update pass
optimizer_argsstring默认值:
(Optional) eg: relative_step=True scale_parameter=True warmup_init=True
lr_scheduler_argsstring默认值:
(Optional) eg: milestones=[1,10,30,50] gamma=0.1
enable_bucketboolean默认值: True
Enable buckets
random_cropboolean默认值: False
Random crop instead of center crop
min_bucket_resointeger默认值: 64
取值范围: [64, 4096]
Minimum size in pixel a bucket can be (>= 64)
max_bucket_resointeger默认值: 2048
取值范围: [64, 4096]
Maximum size in pixel a bucket can be (>= 64)
bucket_no_upscaleboolean默认值: True
Don't upscale bucket resolution
bucket_reso_stepsinteger默认值: 64
取值范围: [1, 128]
Bucket resolution steps
caption_dropout_every_n_epochsinteger默认值: 0
Dropout caption every n epochs
caption_dropout_ratenumber默认值: 0
取值范围: [0.0, 1.0]
Rate of caption dropout
weighted_captionsboolean默认值: False
Enable weighted captions in the standard style (token:1.3). No commas inside parens, or shuffle/dropout may break the decoder.
ip_noise_gammanumber默认值: 0
取值范围: [0.0, 1.0]
Enable input perturbation noise. used for regularization. recommended value: around 0.1
ip_noise_gamma_random_strengthboolean默认值: False
Use random strength between 0~ip_noise_gamma for input perturbation noise
min_timestepinteger默认值: 0
取值范围: [0, 1000]
Values greater than 0 will make the model more img2img focussed. 0 = image only
max_timestepinteger默认值: 1000
取值范围: [0, 1000]
Values lower than 1000 will make the model more img2img focussed. 1000 = noise only
LoRA_typestring默认值: 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_presetstring默认值: full
取值范围:
attn-mlp
attn-only
full
full-lin
unet-transformer-only
unet-convblock-only
LyCORIS Preset
network_diminteger默认值: 8
取值范围: [1, 512]
Network Rank (Dimension)
network_alphanumber默认值: 1.0
取值范围: [1e-05, 1024.0]
Alpha for LoRA weight scaling
conv_diminteger默认值: 1
取值范围: [0, 512]
Convolution Rank (Dimension)
conv_alphainteger默认值: 1
取值范围: [0, 512]
Convolution Alpha
factorinteger默认值: -1
取值范围: [-1, 64]
LoKr factor
bypass_modeboolean默认值: False
Designed for bnb 8bit/4bit linear layer. (QLyCORIS)
dora_wdboolean默认值: False
Enable the DoRA method for these algorithms
use_cpboolean默认值: 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_tuckerboolean默认值: 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_scalarboolean默认值: False
Train an additional scalar in front of the weight difference, use a different weight initialization strategy.
rank_dropout_scaleboolean默认值: False
Adjusts the scale of the rank dropout to maintain the average dropout rate, ensuring more consistent regularization across different layers.
constrainnumber默认值: 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.
rescaledboolean默认值: False
Applies an additional scaling factor to the oft_blocks, allowing for further adjustment of their impact on the model's transformations.
train_normboolean默认值: False
Selects trainable layers in a network, but trains normalization layers identically across methods as they lack matrix decomposition.
decompose_bothboolean默认值: False
Controls whether both input and output dimensions of the layer's weights are decomposed into smaller matrices for reparameterization.
train_on_inputboolean默认值: True
Set if we change the information going into the system (True) or the information coming out of it (False).
down_lr_weightstring默认值:
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_weightstring默认值:
Specify the learning rate weight of the mid block of U-Net. (Optional) eg: 0.5
up_lr_weightstring默认值:
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_thresholdstring默认值:
If the weight is not more than this value, the LoRA module is not created. The default is 0. (Optional) eg: 0.1
block_dimsstring默认值:
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_alphasstring默认值:
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_dimsstring默认值:
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_alphasstring默认值:
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_normsnumber默认值: 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_dropoutnumber默认值: 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_dropoutnumber默认值: 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_dropoutnumber默认值: 0.0
取值范围: [0.0, 1.0]
Can specify module_dropout to dropout each rank with specified probability. Recommended range 0.1 to 0.3
unitinteger默认值: 1
取值范围: [1, 64]
DyLoRA Unit / Block size

下表展示了与不同的LoRA_type相关的具体参数:

参数名/ LoRA_typeKohya DyLoRAKohya LoConLoRA-FALyCORIS/iA3LyCORIS/BOFTLyCORIS/Diag-OFTLyCORIS/DyLoRALyCORIS/GLoRALyCORIS/LoConLyCORIS/LoHaLyCORIS/LoKrLyCORIS/Native Fine-TuningStandard
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-----------

返回响应(json)