xjyplayer commited on
Commit
1641d8d
·
verified ·
1 Parent(s): 91b3111

xjyplayer: xjyplayer uploaded at 2024-09-10 00:23:38

Browse files
Files changed (1) hide show
  1. flux/macp_flux.ps1 +1311 -0
flux/macp_flux.ps1 ADDED
@@ -0,0 +1,1311 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # LoRA train script by @Akegarasu modify by @bdsqlsz
2
+
3
+ #?????(Lora??db??sdxl_lora??Sdxl_db??sdxl_cn3l??stable_cascade_db??stable_cascade_lora??controlnet??hunyuan_lora??hunyuan_db??sd3_db??flux_lora??flux_db)
4
+ $train_mode = "flux_lora"
5
+
6
+ #add
7
+ $del_states_and_sample=0
8
+ $del_pre=1
9
+ $proxy_on=1
10
+
11
+ # Train data path | ??????????????????
12
+ $pretrained_model = "/mnt/workspace/flux/flux1-schnell-fp8.safetensor" # base model path | ???��??
13
+ $vae = "/mnt/workspace/flux/ae.safetensors"
14
+ $is_v2_model = 0 # SD2.0 model | SD2.0??? 2.0??????? clip_skip ?????��
15
+ $v_parameterization = 1 # parameterization | ???????? v2 ????512?????????��?????????
16
+ $train_data_dir = "/mnt/workspace/train/train2" # train dataset path | ????????��????
17
+ $reg_data_dir = "" # reg dataset path | ???????????��??
18
+ $network_weights = "" # pretrained weights for LoRA network | ??????????????? LoRA ????????????????????? LoRA ???��??????
19
+ $network_multiplier = 1.0 # lora?????????????1.0
20
+ $training_comment = "this LoRA model created from bdsqlsz by bdsqlsz'script" # training_comment | ????????????��?????????????????????
21
+ $dataset_class = ""
22
+ $dataset_config = "" # dataset config | ????????????��????
23
+ $disable_mmap_load_safetensors = 0 #??wsl???????????????
24
+
25
+ $output_name="macp_flux_lora_en" # output model name | ?????????? | ???????
26
+ $output_dir="/mnt/workspace/train/output/$output_name"
27
+ $output_log_dir="$output_dir/logs"
28
+
29
+ # Train related params | ?????????????
30
+ $resolution = "1024,1024" # image resolution w,h. ????????????,????????????��????????? 64 ????????
31
+ $batch_size = 2 # batch size ??????????????????????????????????????????
32
+ $max_train_epoches = 10 # max train epoches | ????????? epoch
33
+ $save_every_n_epochs = 2 # save every n epochs | ???? N ???? epoch ?????????
34
+
35
+ $gradient_checkpointing = 1 #????�???????????��??????????
36
+ $gradient_accumulation_steps = 1 # ??????????????????batchsize?????
37
+ $optimizer_accumulation_steps = 0
38
+
39
+ $network_dim = 64 # network dim | ???? 4~128??????????????
40
+ $network_alpha = 32 # network alpha | ???????? network_dim ??????????????��????????? network_dim??????? ??????��????? 1??????��?? alpha ???????????????
41
+
42
+ $train_unet_only = 1 # train U-Net only | ??????? U-Net???????????????��???????????????????6G???????????????
43
+ $train_text_encoder_only = 0 # train Text Encoder only | ??????? ???????????
44
+
45
+ # Learning rate | ??????
46
+ $lr = "2e-4"
47
+ $unet_lr = "2e-4"
48
+ $text_encoder_lr = "2e-4"
49
+ $lr_scheduler = "cosine_with_min_lr"
50
+ # "linear", "cosine", "cosine_with_restarts", "polynomial", "constant", "constant_with_warmup" | PyTorch???6???????????
51
+ # constant????????????, constant_with_warmup ?????????????????, linear ?????????????????, polynomial ???????????????, cosine ???????????, cosine_with_restarts ??????????????????????
52
+ # ????cosine_with_min_lr(??????lora)??warmup_stable_decay(??????db)??inverse_sqrt
53
+ $lr_warmup_steps = 0 # warmup steps | ????????????lr_scheduler ???? constant ???? adafactor ?????????????0???????? lr_scheduler ???? constant_with_warmup ??????��?????????
54
+ $lr_decay_steps = 0 # decay steps | ????????????????? lr_scheduler ?warmup_stable_decay???? ?????��???????10%???????
55
+ $lr_scheduler_num_cycles = 1 # restarts nums | ????????????????????? lr_scheduler ???? cosine_with_restarts ??????��?????????
56
+ $lr_scheduler_timescale = 0 #times scale |?????????????? lr_scheduler ???? inverse_sqrt ??????��??????????lr_warmup_steps
57
+ $lr_scheduler_min_lr_ratio = 0.1 #min lr ratio |??��?????????????? lr_scheduler ???? cosine_with_min_lr????warmup_stable_decay ??????��?????????????0
58
+
59
+ #optimizer | ???????
60
+ $optimizer_type = "PagedAdamW8bit"
61
+ # ????????"adaFactor","AdamW","AdamW8bit","Lion","SGDNesterov","SGDNesterov8bit","DAdaptation",
62
+ # ???????????"Lion8bit"(??????????????????)????"DAdaptAdaGrad"????"DAdaptAdan"(????????????��??????)????"DAdaptSGD"
63
+ # ????DAdaptAdam??DAdaptLion??DAdaptAdanIP????????DAdaptAdam
64
+ # ???????????"Sophia"(2????1.7????????)????"Prodigy"?????????????????Dylora
65
+ # PagedAdamW8bit??PagedLion8bit??Adan??Tiger
66
+ # AdamWScheduleFree??SGDScheduleFree
67
+ # StableAdamW??Ranger
68
+ $d_coef = "0.5" #prodigy D???????
69
+ $d0 = "1e-4" #dadaptation???prodigy?????????
70
+ $fused_backward_pass = 0 #????????float32???????????��?????????adafactor????adamw??gradient_accumulation_steps????????1???????????
71
+ $fused_optimizer_groups = 0
72
+
73
+ #SD3 ?????????????
74
+ $clip_l="/mnt/workspace/clip/clip_l.safetensors"
75
+ $clip_g="/mnt/workspace/clip/clip_g.safetensors"
76
+ $clip_g=""
77
+ $t5xxl="/mnt/workspace/clip/t5xxl_fp16.safetensors"
78
+ $t5xxl_device = "" #???cuda????��??????CPU???????????
79
+ $t5xxl_dtype = "fp16" #?????fp32??fp16??bf16
80
+ $text_encoder_batch_size = 12
81
+ $num_last_block_to_freeze = 0
82
+ $discrete_flow_shift = 1.15 # Euler ????????????????��???sd3???????3.0
83
+ $apply_t5_attn_mask = 1 # ??????T5???????????????0
84
+
85
+ #noise | ????
86
+ $noise_offset = 0.1 # help allow SD to gen better blacks and whites????(0-1) | ????SD???��??????????????????0.06????????0.1
87
+ $adaptive_noise_scale = 0 #???????????????10%~100%??noiseoffset??��
88
+ $noise_offset_random_strength = 0 #??????????????
89
+ $multires_noise_iterations = 0 #?????????????????????????????6-10,0????????
90
+ $multires_noise_discount = 0 #?????????????????????????????0.1-0.3,?????????????????????
91
+ $min_snr_gamma = 0 #??��????????????????step?loss???????��?????��???????3-5????5??????????????????????3????????????????0????????
92
+ $ip_noise_gamma = "0.1" #????????????????????????
93
+ $ip_noise_gamma_random_strength = 0 #?????????????
94
+ $debiased_estimation_loss = 0 #???????????????minsnr???????
95
+ $loss_type = "l2" #????????????`smooth_l1`??`huber`??`l2`(????MSE)
96
+ $huber_schedule = "snr" #huber???????????? `exponential`??`constant` ???? `snr`
97
+ $huber_c = 0.1 #huber?????????c????
98
+ $immiscible_noise = 0 #??????????????????
99
+
100
+ $seed = 1026 # reproducable seed | ????????????????????????prompt?????????????????????????????????????????
101
+
102
+ #LORA_PLUS
103
+ $enable_lora_plus = 0
104
+ $loraplus_lr_ratio = 16
105
+ $loraplus_unet_lr_ratio = 16
106
+ $loraplus_text_encoder_lr_ratio = 4
107
+
108
+ #dropout | ???(????lycoris????????????lycoris???dropout)
109
+ $network_dropout = 0 # dropout ????????��??????????????????????0.1~0.3
110
+ $scale_weight_norms = 1.0 #??????? dropout ?????????????????????1.0
111
+ $rank_dropout = 0 #lora????????rank?????dropout????????0.1~0.3??��???????
112
+ $module_dropout = 0 #lora????????module?????dropout(?????????????)????????0.1~0.3??��???????
113
+ $caption_dropout_every_n_epochs = 0 #dropout caption
114
+ $caption_dropout_rate = 0 #0~1
115
+ $caption_tag_dropout_rate = 0 #0~1
116
+
117
+
118
+ #gorkfast | ??????????
119
+ $gradfilter_ema_alpha = 0 #EMA??????????? ????ema_alpha??????gradfilter_ema????????0.98???0???????????
120
+ $gradfilter_ema_lamb = 2.0 #?????ema?????????????????
121
+
122
+ #flux ??????????
123
+ $ae = $vae
124
+ $timestep_sampling = "sigmoid" # ????????????????? sd3????"sigma"?????DDPM????"uniform" ???? flux????"sigmoid" ???? "shift". shift??????discarete_flow_shift???????
125
+ $sigmoid_scale = 1.0 # sigmoid ?????????????????????? 1.0?????????????????????????
126
+ $model_prediction_type = "raw" # ????????????????? flux????"raw"????????????????"additive" ???? sd????"sigma_scaled"
127
+ $guidance_scale = 1.0 # guidance scale??????CFG, ??????? 1.0
128
+ $blockwise_fused_optimizers = 1 # ??????�D?????????????????1
129
+ $double_blocks_to_swap = 6 # ??????????????????6
130
+ $single_blocks_to_swap = 0 # ??????????????????0
131
+ $cpu_offload_checkpointing = 1 # ??????CPU��??checkpoint??finetune????????
132
+ $mem_eff_save = 1 # ??????????��???��?????1
133
+ $split_qkv=0 # ??????QKV??????1
134
+
135
+ # ??????????? ???captain???????
136
+ $shuffle_caption = 1 # ???????tokens
137
+ $keep_tokens = 1 # keep heading N tokens when shuffling caption tokens | ??????????????? tokens ??????????? N ????????
138
+ $prior_loss_weight = 1 #?????????,0-1
139
+ $weighted_captions = 0 #????????????????????webui?????��?????????(abc), [abc],(abc:1.23),??????????????????????????????????????????75??tokens????
140
+ $secondary_separator = ";;;" #?????????????��?????????????????????token???????????????????? caption_separator ????????��?????????? aaa;;bbb;;cc???????? aaa,bbb,cc ????????????
141
+ $keep_tokens_separator = "|||" #?????????????????????????
142
+ $enable_wildcard = 0 #?????????????????? {aaa|bbb|ccc}
143
+ $caption_prefix = "" #???????????????????????????????????masterpiece, best quality,
144
+ $caption_suffix = "" #????????????????????????????????full body????
145
+ $alpha_mask = 0 #?????????????????????
146
+
147
+ # Output settings | ???????????
148
+ $save_model_as = "safetensors" # model save ext | ????????? ckpt, pt, safetensors
149
+ $mixed_precision = "bf16" # ???fp16,no,bf16????
150
+ $save_precision = "bf16" # ???fp16,fp32,bf16????
151
+ $full_fp16 = 0 #?????fp16???????????????fp16??????????
152
+ $full_bf16 = 0 #????bf16???????????30??????????
153
+ $fp8_base = 1 #????fp8???????????��??????????
154
+
155
+ # Resume training state | ??????????
156
+ $save_state = 0 # save training state | ?????????? ???????????? <output_name>-??????-state ?????? ??? epoch ????
157
+ $resume = "" # resume from state | ?????????????��??????? ????????????????????? ????�Z??????? epoch ???????????????? ???????????????? 1 ?????? ???? network_weights ????????????????????
158
+ $save_state_on_train_end = 0 #???????????????????????
159
+
160
+ #????toml???
161
+ $output_config = 0 #???????????????toml?????????????????????????????????????????
162
+ $config_file = "./toml/" + $output_name + ".toml" #??????????????????????????????????????????
163
+
164
+ #??????????
165
+ $enable_sample = 1 #1?????????0????
166
+ $sample_at_first = 0 #???????????????????
167
+ $sample_every_n_epochs = 2 #?n??epoch??????
168
+ $sample_prompts = "./toml/qinglong.txt" #prompt???��??
169
+ $sample_sampler = "euler_a" #???????? 'ddim', 'pndm', 'heun', 'dpmsolver', 'dpmsolver++', 'dpmsingle', 'k_lms', 'k_euler', 'k_euler_a', 'k_dpm_2', 'k_dpm_2_a'
170
+
171
+ #wandb ??????
172
+ $wandb_api_key = "ed66a86e0e25e80cbf097cc6841673c8f7353969" # wandbAPI KEY???????????
173
+
174
+ #????????????
175
+ $base_weights = "" #???????????basemodel?��????��??????????????????????????????
176
+ $base_weights_multiplier = "1.0" #??????????????????????????????1.0????
177
+
178
+ # ????????
179
+ $enable_bucket = 1 #??????????
180
+ $min_bucket_reso = 256 # arb min resolution | arb ??��?????
181
+ $max_bucket_reso = 2048 # arb max resolution | arb ???????
182
+ $bucket_no_upscale = 1 #???????????
183
+ $persistent_workers = 1 # makes workers persistent, further reduces/eliminates the lag in between epochs. however it may increase memory usage | ??????????��?????????????2????
184
+ $vae_batch_size = 4 #vae????????��??2-4
185
+ $clip_skip = 1 # clip skip | ??? ????? 2
186
+ $cache_latents = 1 #???????????
187
+ $cache_latents_to_disk = 1 # ????????????????????????????��1??????0????
188
+ $torch_compile = 0 #???torch???????????��??????2.1
189
+ $dynamo_backend = "inductor" #"eager", "aot_eager", "inductor","aot_ts_nvfuser","nvprims_nvfuser","cudagraphs","aot_torchxla_trace_once"???????
190
+ $TORCHINDUCTOR_FX_GRAPH_CACHE = 1 #??????? FX ???????
191
+ $TORCHINDUCTOR_CACHE_DIR = "./torch_compile_cache" #??????��???????��??????????
192
+
193
+ #lycoris???????
194
+ $enable_lycoris = 0 # ????lycoris
195
+ $conv_dim = 0 #???? dim???????32
196
+ $conv_alpha = 0 #???? alpha????????1????0.3
197
+ $algo = "lokr" # algo????????????lycoris???????????
198
+ #????lora(????locon)????
199
+ #loha
200
+ #IA3
201
+ #lokr
202
+ #dylora
203
+ #full(DreamBooth?????????lora)
204
+ #diag-oft
205
+ #???????????????????????????��????????????????????????
206
+ #?????????????????????????? LoRA ????????????????????????
207
+ #dim ???????��?????????????????????????��??????????????????????? LoRA ??????????
208
+
209
+ $dropout = 0 #lycoris???dropout
210
+ $preset = "attn-mlp" #?????????????
211
+ #full: default preset, train all the layers in the UNet and CLIP|???????????????Unet??Clip????
212
+ #full-lin: full but skip convolutional layers|????????????
213
+ #attn-mlp: train all the transformer block.|kohya????????????transformer???
214
+ #attn-only??only attention layer will be trained, lot of papers only do training on attn layer.|?????????????????????????????????????????
215
+ #unet-transformer-only???? as same as kohya_ss/sd_scripts with disabled TE, or, attn-mlp preset with train_unet_only enabled.|??attn-mlp????????��??te???
216
+ #unet-convblock-only???? only ResBlock, UpSample, DownSample will be trained.|??????????�????res??????????????
217
+ #./toml/example_lycoris.toml: ???????????????????????????????????????��????????????????��?????��?????��???????????????????
218
+
219
+ $factor = 8 #???????lokr???????-1~8????8?????
220
+ $decompose_both = 1 #??????lokr??????????? LoKr ?????????????????????? LoRA ?????????????????????????????
221
+ $block_size = 4 #??????dylora,????????��????????????1???????????????4????8????12????16??????
222
+ $use_tucker = 0 #??????? (IA)^3 ??full
223
+ $use_scalar = 0 #?????????????????????????
224
+ $train_norm = 0 #???????
225
+ $dora_wd = 0 #Dora?????????rank??��???????LoRA, LoHa, ??LoKr
226
+ $full_matrix = 1 #??????????????
227
+ $bypass_mode = 0 #???????????? bnb 8 ????/4 ��????????????????(QLyCORIS)??????LoRA, LoHa, ??LoKr
228
+ $rescaled = 1 #???????????????��???????OFT
229
+ $constrain = 0 #??????FLOAT??��???????COFT
230
+
231
+ #dylora???????
232
+ $enable_dylora = 0 # ????dylora????lycoris??????????????
233
+ $unit = 4 #????????��????????????1???????????????4????8????12????16??????
234
+
235
+ #Lora_FA
236
+ $enable_lora_fa = 0 # ????lora_fa????lycoris??dylora??????????????
237
+
238
+ #oft
239
+ $enable_oft = 0 # ????oft?????????????????????
240
+
241
+ # block weights | ??????
242
+ $enable_block_weights = 0 #??????????????lycoris??????????????
243
+ $down_lr_weight = "1,0.2,1,1,0.2,1,1,0.2,1,1,1,1" #12???????????12???????0-1.???????��???��???????sine, cosine, linear, reverse_linear, zeros???��?��??down_lr_weight=cosine+.25
244
+ $mid_lr_weight = "1" #1???????????1??????????????????
245
+ $up_lr_weight = "1,1,1,1,1,1,1,1,1,1,1,1" #12?????????
246
+ $block_lr_zero_threshold = 0 #?????????????????????????????????????0????
247
+
248
+ $enable_block_dim = 0 #????dim??????
249
+ $block_dims = "128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128" #dim???????25????
250
+ $block_alphas = "16,16,32,16,32,32,64,16,16,64,64,64,16,64,16,64,32,16,16,64,16,16,16,64,16" #alpha???????25????
251
+ $conv_block_dims = "32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32" #convdim???????25????
252
+ $conv_block_alphas = "1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1" #convalpha???????25????
253
+
254
+ # block lr
255
+ $enable_block_lr = 0
256
+ $block_lr = "0,$lr,$lr,0,$lr,$lr,0,$lr,$lr,0,$lr,$lr,$lr,$lr,$lr,$lr,$lr,$lr,$lr,$lr,$lr,$lr,0"
257
+
258
+ #SDXL??��???
259
+ #https://www.bilibili.com/video/BV1tk4y137fo/
260
+ $min_timestep = 0 #??��??????????0
261
+ $max_timestep = 1000 #?????????????????1000
262
+ $cache_text_encoder_outputs = 1 #?????????????????????????????????��??????????shuffle????
263
+ $cache_text_encoder_outputs_to_disk = 1 #?????????????????????????????????��??????????shuffle????
264
+ $no_half_vae = 0 #?????????????????????mixed_precision?????????????????
265
+ $bucket_reso_steps = 32 #SDXL??????????32????64????32??????????????64
266
+
267
+ #db checkpoint train
268
+ $stop_text_encoder_training = 0
269
+ $no_token_padding = 0 #?????��???????????
270
+
271
+ #sdxl_db
272
+ $diffusers_xformers = 0
273
+ $train_text_encoder = 0
274
+ $learning_rate_te1 = "5e-8"
275
+ $learning_rate_te2 = "5e-8"
276
+
277
+ #sdxl_cn3l or controlnet
278
+ $controlnet_model_name_or_path = ""
279
+ $conditioning_data_dir = ""
280
+ $cond_emb_dim = 32
281
+ $masked_loss = 0 #???????loss???????????????R???255???????mask????0???????????
282
+
283
+ #??????
284
+ $multi_gpu=0 #multi gpu | ?????????????0????1?????? ?��???????????????? >= 2 ???
285
+ $deepspeed=0 #deepspeed | ???deepspeed???????0????1?????? ?��???????????????? >= 2 ???
286
+ $zero_stage=2 #zero stage | zero stage 0,1,2,3,???2??????? ?��???????????????? >= 2 ???
287
+ $offload_optimizer_device="" #offload optimizer device | ??????????��??cpu????nvme, ?��???????????????? >= 2 ???
288
+ $fp16_master_weights_and_gradients=0 #fp16 master weights and gradients | fp16?????????????0????1?????? ?��???????????????? >= 2 ???
289
+
290
+ $ddp_timeout=120
291
+ $ddp_gradient_as_bucket_view=1
292
+ $ddp_static_graph=1
293
+
294
+ #stable_cascade ?????????????
295
+ $effnet_checkpoint_path = "./VAE/effnet_encoder.safetensors" #effnet??????????????VAE
296
+ $stage_c_checkpoint_path = "./Stable-diffusion/train/stage_c_bf16.safetensors" #stage_c??????base_model
297
+ $text_model_checkpoint_path = "" #te???????????????????????????????HF????
298
+ $save_text_model = 1 #0???1?????????????????????TE??��???????????????????????????text_model_checkpoint_path???????
299
+ $previewer_checkpoint_path = "./Stable-diffusion/train/previewer.safetensors" #??????????????????????????
300
+ $adaptive_loss_weight = 1 #0???1?????????adaptive_loss_weight??????????????????P2LOSSWIGHT
301
+
302
+ # ============= DO NOT MODIFY CONTENTS BELOW | ????????��????? =====================
303
+ # Activate python venv
304
+
305
+
306
+ $Env:HF_HOME = "huggingface"
307
+ $Env:XFORMERS_FORCE_DISABLE_TRITON = "1"
308
+ $Env:HF_ENDPOINT = "https://hf-mirror.com"
309
+ $Env:TOKENIZERS_PARALLELISM = "true"
310
+ $network_module = "networks.lora"
311
+ $Env:PYTORCH_CUDA_ALLOC_CONF="expandable_segments:True"
312
+ $Env:CUDA_PATH="/usr/local/cuda"
313
+ $Env:TF_ENABLE_ONEDNN_OPTS="0"
314
+
315
+ $ext_args = [System.Collections.ArrayList]::new()
316
+ $launch_args = [System.Collections.ArrayList]::new()
317
+ $laungh_script = "train_network"
318
+
319
+ #add
320
+ if ($proxy_on -eq 1) {
321
+ bash -c "/mnt/workspace/trojan/run.sh"
322
+ bash -c "service privoxy restart"
323
+ $Env:no_proxy="localhost, 127.0.0.1, ::1, ip.cn, chinaz.com, 192.168.0.0/16, mirrors.cloud.aliyuncs.com, hf-mirror.com, lfs.huggingface.co, .s3-accelerate.amazonaws.com, .hf-mirror.com"
324
+ $Env:HF_ENDPOINT="https://hf-mirror.com"
325
+ $Env:http_proxy="http://127.0.0.1:8893"
326
+ $Env:https_proxy="http://127.0.0.1:8893"
327
+ }
328
+
329
+
330
+ if ($train_mode -ieq "stable_cascade_lora") {
331
+ $laungh_script = "stable_cascade_train_c_network"
332
+ }
333
+ elseif ($train_mode -ieq "flux_lora") {
334
+ $network_module = $network_module + "_flux"
335
+ if ($split_qkv -ne 0) {
336
+ [void]$ext_args.Add("--network_args")
337
+ [void]$ext_args.Add("split_qkv=True")
338
+ }
339
+ }
340
+
341
+ if ($multi_gpu -eq 1) {
342
+ $launch_args += "--multi_gpu"
343
+ $launch_args += "--mixed_precision=$mixed_precision"
344
+ $blockwise_fused_optimizers = 0
345
+ if ($deepspeed -eq 1) {
346
+ [void]$ext_args.Add("--deepspeed")
347
+ if ($zero_stage -ne 0) {
348
+ [void]$ext_args.Add("--zero_stage=$zero_stage")
349
+ }
350
+ if ($offload_optimizer_device) {
351
+ [void]$ext_args.Add("--offload_optimizer_device=$offload_optimizer_device")
352
+ }
353
+ if ($fp16_master_weights_and_gradients -eq 1) {
354
+ [void]$ext_args.Add("--fp16_master_weights_and_gradients")
355
+ }
356
+ }
357
+ if ($ddp_timeout -ne 0) {
358
+ [void]$ext_args.Add("--ddp_timeout=$ddp_timeout")
359
+ }
360
+ if ($ddp_gradient_as_bucket_view -ne 0) {
361
+ [void]$ext_args.Add("--ddp_gradient_as_bucket_view")
362
+ }
363
+ if ($ddp_static_graph -ne 0) {
364
+ [void]$ext_args.Add("--ddp_static_graph")
365
+ }
366
+ }
367
+
368
+ if (-not ($train_mode -ilike "*lora")) {
369
+ $network_module = ""
370
+ $network_alpha = ""
371
+ $conv_dim = ""
372
+ $conv_alpha = ""
373
+ $network_weights = ""
374
+ $network_multiplier = 1.0
375
+ $enable_block_weights = 0
376
+ $enable_block_dim = 0
377
+ $enable_lycoris = 0
378
+ $enable_dylora = 0
379
+ $enable_lora_fa = 0
380
+ $enable_oft = 0
381
+ $unet_lr = ""
382
+ $text_encoder_lr = ""
383
+ $train_unet_only = 0
384
+ $train_text_encoder_only = 0
385
+ $training_comment = ""
386
+ $prior_loss_weight = 1
387
+ $network_dropout = "0"
388
+ $enable_lora_plus = 0
389
+ if ($train_mode -ine "sdxl_cn3l") {
390
+ $network_dim = ""
391
+ }
392
+ }
393
+
394
+ if ($train_mode -ilike "*db") {
395
+ if ($train_mode -ieq "db") {
396
+ $laungh_script = "train_db";
397
+ if ($no_token_padding -ne 0) {
398
+ [void]$ext_args.Add("--no_token_padding")
399
+ }
400
+ if ($stop_text_encoder_training) {
401
+ if ($gradient_accumulation_steps) {
402
+ $stop_text_encoder_training = $stop_text_encoder_training * $gradient_accumulation_steps
403
+ }
404
+ [void]$ext_args.Add("--stop_text_encoder_training=$stop_text_encoder_training")
405
+ }
406
+ if ($learning_rate_te) {
407
+ [void]$ext_args.Add("--learning_rate_te=$learning_rate_te")
408
+ }
409
+ }
410
+ else {
411
+ if ($train_mode -ieq "stable_cascade_db") {
412
+ $laungh_script = "stable_cascade_train_stage_c"
413
+ $pretrained_model = ""
414
+ $learning_rate_te2 = 0
415
+ $min_snr_gamma = 0
416
+ $ip_noise_gamma = 0
417
+ $loss_type = "l2"
418
+ $weighted_captions = 0
419
+ $debiased_estimation_loss = 0
420
+ $immiscible_noise = 0
421
+ }
422
+ else {
423
+ $laungh_script = "train"
424
+ if ($train_mode -ieq "sdxl_db") {
425
+ if ($diffusers_xformers -ne 0) {
426
+ [void]$ext_args.Add("--diffusers_xformers")
427
+ }
428
+ if ($train_text_encoder -ne 0) {
429
+ [void]$ext_args.Add("--train_text_encoder")
430
+ if ($learning_rate_te1 -ne 0) {
431
+ [void]$ext_args.Add("--learning_rate_te1=$learning_rate_te1")
432
+ }
433
+ if ($learning_rate_te2 -ne 0) {
434
+ [void]$ext_args.Add("--learning_rate_te2=$learning_rate_te2")
435
+ }
436
+ }
437
+ if ($enable_block_lr -ne 0) {
438
+ [void]$ext_args.Add("--block_lr=$block_lr")
439
+ }
440
+ }
441
+ elseif ($train_mode -ieq "flux_db") {
442
+ $mem_eff_save = 1
443
+ if ($blockwise_fused_optimizers -ne 0) {
444
+ [void]$ext_args.Add("--blockwise_fused_optimizers")
445
+ }
446
+ if ($double_blocks_to_swap -ne 0) {
447
+ [void]$ext_args.Add("--double_blocks_to_swap=$double_blocks_to_swap")
448
+ }
449
+ if ($single_blocks_to_swap -ne 0) {
450
+ [void]$ext_args.Add("--single_blocks_to_swap=$single_blocks_to_swap")
451
+ }
452
+ if ($cpu_offload_checkpointing -ne 0) {
453
+ [void]$ext_args.Add("--cpu_offload_checkpointing")
454
+ }
455
+ if ($mem_eff_save -ne 0) {
456
+ [void]$ext_args.Add("--mem_eff_save")
457
+ }
458
+ }
459
+ }
460
+ }
461
+ }
462
+
463
+ if ($train_mode -ilike "*cn3l" -or $train_mode -ilike "*controlnet") {
464
+ if ($train_mode -ilike "*controlnet") {
465
+ $laungh_script = "train_controlnet"
466
+ if ($controlnet_model_name_or_path) {
467
+ [void]$ext_args.Add("--controlnet_model_name_or_path=$controlnet_model_name_or_path")
468
+ }
469
+ }
470
+ else {
471
+ $laungh_script = "train_control_net_lllite"
472
+ if ($cond_emb_dim) {
473
+ [void]$ext_args.Add("--cond_emb_dim=$cond_emb_dim")
474
+ }
475
+ }
476
+ if ($conditioning_data_dir) {
477
+ [void]$ext_args.Add("--conditioning_data_dir=$conditioning_data_dir")
478
+ }
479
+ if ($masked_loss) {
480
+ [void]$ext_args.Add("--masked_loss")
481
+ }
482
+ }
483
+
484
+ if ($train_mode -ilike "sdxl*") {
485
+ $laungh_script = "sdxl_" + $laungh_script
486
+ if ($min_timestep -ne 0) {
487
+ [void]$ext_args.Add("--min_timestep=$min_timestep")
488
+ }
489
+ if ($max_timestep -ne 1000) {
490
+ [void]$ext_args.Add("--max_timestep=$max_timestep")
491
+ }
492
+ if ($cache_text_encoder_outputs -ne 0) {
493
+ [void]$ext_args.Add("--cache_text_encoder_outputs")
494
+ if ($cache_text_encoder_outputs_to_disk -ne 0) {
495
+ [void]$ext_args.Add("--cache_text_encoder_outputs_to_disk")
496
+ }
497
+ $shuffle_caption = 0
498
+ $loraplus_text_encoder_lr_ratio = 0
499
+ $caption_dropout_rate = 0
500
+ $caption_tag_dropout_rate = 0
501
+ }
502
+ if ($no_half_vae -ne 0) {
503
+ [void]$ext_args.Add("--no_half_vae")
504
+ $mixed_precision = ""
505
+ $full_fp16 = 0
506
+ $full_bf16 = 0
507
+ $fp8_base = 0
508
+ }
509
+ if ($bucket_reso_steps -ne 64) {
510
+ [void]$ext_args.Add("--bucket_reso_steps=$bucket_reso_steps")
511
+ }
512
+ }
513
+
514
+ if ($train_mode -ilike "sd3*" -or $train_mode -ilike "flux*") {
515
+ if ($clip_l) {
516
+ [void]$ext_args.Add("--clip_l=$clip_l")
517
+ }
518
+ if ($t5xxl) {
519
+ [void]$ext_args.Add("--t5xxl=$t5xxl")
520
+ }
521
+ if ($apply_t5_attn_mask) {
522
+ [void]$ext_args.Add("--apply_t5_attn_mask")
523
+ }
524
+ if ($num_last_block_to_freeze -ne 0) {
525
+ [void]$ext_args.Add("--num_last_block_to_freeze=$num_last_block_to_freeze")
526
+ }
527
+ if ($train_mode -ilike "flux*") {
528
+ $laungh_script = "flux_" + $laungh_script
529
+ $enable_dylora = 0
530
+ $enable_lora_fa = 0
531
+ $enable_oft = 0
532
+ $enable_block_lr = 0
533
+ $enable_block_weights = 0
534
+ $enable_block_dim = 0
535
+ if ($timestep_sampling) {
536
+ [void]$ext_args.Add("--timestep_sampling=$timestep_sampling")
537
+ }
538
+ if ($sigmoid_scale) {
539
+ [void]$ext_args.Add("--sigmoid_scale=$sigmoid_scale")
540
+ }
541
+ if ($model_prediction_type) {
542
+ [void]$ext_args.Add("--model_prediction_type=$model_prediction_type")
543
+ }
544
+ if ($guidance_scale) {
545
+ [void]$ext_args.Add("--guidance_scale=$guidance_scale")
546
+ }
547
+ if ($guidance_rescale -ne 0) {
548
+ [void]$ext_args.Add("--guidance_rescale")
549
+ }
550
+ if ($ae) {
551
+ [void]$ext_args.Add("--ae=$ae")
552
+ $vae = ""
553
+ }
554
+ if ($torch_compile) {
555
+ # $Env:CC = "E:\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.41.34120\bin\Hostx64\x64\cl.exe"
556
+ [void]$ext_args.Add("--torch_compile")
557
+ if ($dynamo_backend) {
558
+ [void]$ext_args.Add("--dynamo_backend=$dynamo_backend")
559
+ }
560
+ if ($TORCHINDUCTOR_FX_GRAPH_CACHE -ne 0) {
561
+ $Env:TORCHINDUCTOR_FX_GRAPH_CACHE = "1"
562
+ if ($TORCHINDUCTOR_CACHE_DIR) {
563
+ $Env:TORCHINDUCTOR_CACHE_DIR = $TORCHINDUCTOR_CACHE_DIR
564
+ }
565
+ }
566
+ }
567
+ }
568
+ else {
569
+ $laungh_script = "sd3_" + $laungh_script
570
+ if ($clip_g) {
571
+ [void]$ext_args.Add("--clip_g=$clip_g")
572
+ }
573
+ if ($t5xxl_device) {
574
+ [void]$ext_args.Add("--t5xxl_device=$t5xxl_device")
575
+ }
576
+ if ($t5xxl_dtype) {
577
+ [void]$ext_args.Add("--t5xxl_dtype=$t5xxl_dtype")
578
+ }
579
+ if ($text_encoder_batch_size) {
580
+ [void]$ext_args.Add("--text_encoder_batch_size=$text_encoder_batch_size")
581
+ }
582
+ if ($discrete_flow_shift) {
583
+ [void]$ext_args.Add("--discrete_flow_shift=$discrete_flow_shift")
584
+ }
585
+ }
586
+ if ($cache_text_encoder_outputs -ne 0) {
587
+ [void]$ext_args.Add("--cache_text_encoder_outputs")
588
+ if ($cache_text_encoder_outputs_to_disk -ne 0) {
589
+ [void]$ext_args.Add("--cache_text_encoder_outputs_to_disk")
590
+ }
591
+ $shuffle_caption = 0
592
+ $loraplus_text_encoder_lr_ratio = 0
593
+ $caption_dropout_rate = 0
594
+ $caption_tag_dropout_rate = 0
595
+ }
596
+ [void]$ext_args.Add("--sdpa")
597
+ }
598
+ elseif ($torch_compile) {
599
+ [void]$ext_args.Add("--sdpa")
600
+ [void]$ext_args.Add("--torch_compile")
601
+ if ($dynamo_backend) {
602
+ [void]$ext_args.Add("--dynamo_backend=$dynamo_backend")
603
+ }
604
+ if ($TORCHINDUCTOR_FX_GRAPH_CACHE -ne 0) {
605
+ $Env:TORCHINDUCTOR_FX_GRAPH_CACHE = "1"
606
+ if ($TORCHINDUCTOR_CACHE_DIR) {
607
+ $Env:TORCHINDUCTOR_CACHE_DIR = $TORCHINDUCTOR_CACHE_DIR
608
+ }
609
+ }
610
+ }
611
+ else {
612
+ [void]$ext_args.Add("--xformers")
613
+ }
614
+
615
+ if ($train_mode -ilike "stable_cascade*") {
616
+ if ($effnet_checkpoint_path) {
617
+ [void]$ext_args.Add("--effnet_checkpoint_path=$effnet_checkpoint_path")
618
+ }
619
+ if ($stage_c_checkpoint_path) {
620
+ [void]$ext_args.Add("--stage_c_checkpoint_path=$stage_c_checkpoint_path")
621
+ }
622
+ if ($text_model_checkpoint_path) {
623
+ [void]$ext_args.Add("--text_model_checkpoint_path=$text_model_checkpoint_path")
624
+ }
625
+ if ($save_text_model -ne 0) {
626
+ [void]$ext_args.Add("--save_text_model")
627
+ }
628
+ if ($previewer_checkpoint_path) {
629
+ [void]$ext_args.Add("--previewer_checkpoint_path=$previewer_checkpoint_path")
630
+ }
631
+ if ($adaptive_loss_weight -ne 0) {
632
+ [void]$ext_args.Add("--adaptive_loss_weight")
633
+ }
634
+ }
635
+
636
+ if ($dataset_class) {
637
+ [void]$ext_args.Add("--dataset_class=$dataset_class")
638
+ }
639
+ elseif ($dataset_config) {
640
+ [void]$ext_args.Add("--dataset_config=$dataset_config")
641
+ }
642
+ else {
643
+ [void]$ext_args.Add("--train_data_dir=$train_data_dir")
644
+ if ($reg_data_dir) {
645
+ [void]$ext_args.Add("--reg_data_dir=$reg_data_dir")
646
+ }
647
+ if ($batch_size) {
648
+ [void]$ext_args.Add("--train_batch_size=$batch_size")
649
+ }
650
+ if ($resolution) {
651
+ [void]$ext_args.Add("--resolution=$resolution")
652
+ }
653
+ if ($enable_bucket) {
654
+ [void]$ext_args.Add("--enable_bucket")
655
+ [void]$ext_args.Add("--min_bucket_reso=$min_bucket_reso")
656
+ [void]$ext_args.Add("--max_bucket_reso=$max_bucket_reso")
657
+ if ($bucket_no_upscale) {
658
+ [void]$ext_args.Add("--bucket_no_upscale")
659
+ }
660
+ }
661
+ }
662
+
663
+ if ($caption_tag_dropout_rate) {
664
+ [void]$ext_args.Add("--caption_tag_dropout_rate=$caption_tag_dropout_rate")
665
+ }
666
+
667
+ if ($pretrained_model) {
668
+ [void]$ext_args.Add("--pretrained_model_name_or_path=$pretrained_model")
669
+ }
670
+
671
+ if ($vae) {
672
+ [void]$ext_args.Add("--vae=$vae")
673
+ }
674
+
675
+ if ($disable_mmap_load_safetensors) {
676
+ [void]$ext_args.Add("--disable_mmap_load_safetensors")
677
+ }
678
+
679
+ if ($save_model_as) {
680
+ [void]$ext_args.Add("--save_model_as=$save_model_as")
681
+ }
682
+
683
+ if ($is_v2_model) {
684
+ [void]$ext_args.Add("--v2")
685
+ $min_snr_gamma = 0
686
+ $debiased_estimation_loss = 0
687
+ if ($v_parameterization) {
688
+ [void]$ext_args.Add("--v_parameterization")
689
+ [void]$ext_args.Add("--scale_v_pred_loss_like_noise_pred")
690
+ [void]$ext_args.Add("--zero_terminal_snr")
691
+ }
692
+ }
693
+ elseif ($train_mode -ilike "hunyuan*") {
694
+ $laungh_script = "hunyuan_" + $laungh_script
695
+ $min_snr_gamma = 0
696
+ $debiased_estimation_loss = 0
697
+ [void]$ext_args.Add("--v_parameterization")
698
+ [void]$ext_args.Add("--scale_v_pred_loss_like_noise_pred")
699
+ [void]$ext_args.Add("--zero_terminal_snr")
700
+ }
701
+ else {
702
+ [void]$ext_args.Add("--clip_skip=$clip_skip")
703
+ }
704
+
705
+ if ($prior_loss_weight -and $prior_loss_weight -ne 1) {
706
+ [void]$ext_args.Add("--prior_loss_weight=$prior_loss_weight")
707
+ }
708
+
709
+ if ($network_dim) {
710
+ [void]$ext_args.Add("--network_dim=$network_dim")
711
+ }
712
+
713
+ if ($network_alpha) {
714
+ [void]$ext_args.Add("--network_alpha=$network_alpha")
715
+ }
716
+
717
+ # if ($training_comment) {
718
+ # # Ensure proper quoting for the value
719
+ # $escapedComment = $training_comment -replace '"', '\"'
720
+ # [void]$ext_args.Add("--training_comment=`"$escapedComment`"")
721
+ # }
722
+
723
+ if ($persistent_workers) {
724
+ [void]$ext_args.Add("--persistent_data_loader_workers")
725
+ }
726
+
727
+ if ($max_data_loader_n_workers) {
728
+ [void]$ext_args.Add("--max_data_loader_n_workers=$max_data_loader_n_workers")
729
+ }
730
+
731
+ if ($shuffle_caption) {
732
+ [void]$ext_args.Add("--shuffle_caption")
733
+ }
734
+
735
+ if ($weighted_captions) {
736
+ [void]$ext_args.Add("--weighted_captions")
737
+ }
738
+
739
+ if ($cache_latents) {
740
+ [void]$ext_args.Add("--cache_latents")
741
+ if ($cache_latents_to_disk) {
742
+ [void]$ext_args.Add("--cache_latents_to_disk")
743
+ }
744
+ }
745
+
746
+ if ($output_config) {
747
+ [void]$ext_args.Add("--output_config")
748
+ [void]$ext_args.Add("--config_file=$config_file")
749
+ }
750
+
751
+ if ($gradient_checkpointing) {
752
+ [void]$ext_args.Add("--gradient_checkpointing")
753
+ }
754
+
755
+ if ($save_state -eq 1) {
756
+ [void]$ext_args.Add("--save_state")
757
+ if ($save_state_on_train_end -eq 1) {
758
+ [void]$ext_args.Add("--save_state_on_train_end")
759
+ }
760
+ }
761
+
762
+ if ($resume) {
763
+ [void]$ext_args.Add("--resume=$resume")
764
+ }
765
+
766
+ if ($noise_offset -ne 0) {
767
+ [void]$ext_args.Add("--noise_offset=$noise_offset")
768
+ if ($adaptive_noise_scale) {
769
+ [void]$ext_args.Add("--adaptive_noise_scale=$adaptive_noise_scale")
770
+ }
771
+ if ($noise_offset_random_strength) {
772
+ [void]$ext_args.Add("--noise_offset_random_strength")
773
+ }
774
+ }
775
+ elseif ($multires_noise_iterations -ne 0) {
776
+ [void]$ext_args.Add("--multires_noise_iterations=$multires_noise_iterations")
777
+ [void]$ext_args.Add("--multires_noise_discount=$multires_noise_discount")
778
+ }
779
+
780
+ if ($network_dropout -ne 0) {
781
+ $enable_lycoris = 0
782
+ [void]$ext_args.Add("--network_dropout=$network_dropout")
783
+ if ($scale_weight_norms -ne 0) {
784
+ [void]$ext_args.Add("--scale_weight_norms=$scale_weight_norms")
785
+ }
786
+ if ($enable_dylora -ne 0) {
787
+ [void]$ext_args.Add("--network_args")
788
+ if ($rank_dropout) {
789
+ [void]$ext_args.Add("rank_dropout=$rank_dropout")
790
+ }
791
+ if ($module_dropout) {
792
+ [void]$ext_args.Add("module_dropout=$module_dropout")
793
+ }
794
+ }
795
+ }
796
+
797
+ if ($enable_block_weights) {
798
+ [void]$ext_args.Add("--network_args")
799
+ [void]$ext_args.Add("down_lr_weight=$down_lr_weight")
800
+ [void]$ext_args.Add("mid_lr_weight=$mid_lr_weight")
801
+ [void]$ext_args.Add("up_lr_weight=$up_lr_weight")
802
+ [void]$ext_args.Add("block_lr_zero_threshold=$block_lr_zero_threshold")
803
+ if ($enable_block_dim) {
804
+ [void]$ext_args.Add("block_dims=$block_dims")
805
+ [void]$ext_args.Add("block_alphas=$block_alphas")
806
+ if ($conv_block_dims) {
807
+ [void]$ext_args.Add("conv_block_dims=$conv_block_dims")
808
+ if ($conv_block_alphas) {
809
+ [void]$ext_args.Add("conv_block_alphas=$conv_block_alphas")
810
+ }
811
+ }
812
+ elseif ($conv_dim) {
813
+ [void]$ext_args.Add("conv_dim=$conv_dim")
814
+ if ($conv_alpha) {
815
+ [void]$ext_args.Add("conv_alpha=$conv_alpha")
816
+ }
817
+ }
818
+ }
819
+ }
820
+ elseif ($enable_lycoris) {
821
+ $network_module = "lycoris.kohya"
822
+ [void]$ext_args.Add("--network_args")
823
+ [void]$ext_args.Add("algo=$algo")
824
+ if ($algo -ine "ia3" -and $algo -ine "diag-oft") {
825
+ if ($algo -ine "full") {
826
+ if ($conv_dim) {
827
+ [void]$ext_args.Add("conv_dim=$conv_dim")
828
+ if ($conv_alpha) {
829
+ [void]$ext_args.Add("conv_alpha=$conv_alpha")
830
+ }
831
+ }
832
+ if ($use_tucker) {
833
+ [void]$ext_args.Add("use_tucker=True")
834
+ }
835
+ if ($algo -ine "dylora") {
836
+ if ($dora_wd) {
837
+ [void]$ext_args.Add("dora_wd=True")
838
+ }
839
+ if ($bypass_mode) {
840
+ [void]$ext_args.Add("bypass_mode=True")
841
+ }
842
+ if ($use_scalar) {
843
+ [void]$ext_args.Add("use_scalar=True")
844
+ }
845
+ }
846
+ }
847
+ [void]$ext_args.Add("preset=$preset")
848
+ }
849
+ if ($dropout -and $algo -ieq "locon") {
850
+ [void]$ext_args.Add("dropout=$dropout")
851
+ }
852
+ if ($train_norm -and $algo -ine "ia3") {
853
+ [void]$ext_args.Add("train_norm=True")
854
+ }
855
+ if ($algo -ieq "lokr") {
856
+ [void]$ext_args.Add("factor=$factor")
857
+ if ($decompose_both) {
858
+ [void]$ext_args.Add("decompose_both=True")
859
+ }
860
+ if ($full_matrix) {
861
+ [void]$ext_args.Add("full_matrix=True")
862
+ }
863
+ }
864
+ elseif ($algo -ieq "dylora") {
865
+ [void]$ext_args.Add("block_size=$block_size")
866
+ }
867
+ elseif ($algo -ieq "diag-oft") {
868
+ if ($rescaled) {
869
+ [void]$ext_args.Add("rescaled=True")
870
+ }
871
+ if ($constrain) {
872
+ [void]$ext_args.Add("constrain=$constrain")
873
+ }
874
+ }
875
+ }
876
+ elseif ($enable_dylora) {
877
+ $network_module = "networks.dylora"
878
+ [void]$ext_args.Add("--network_args")
879
+ [void]$ext_args.Add("unit=$unit")
880
+ if ($conv_dim) {
881
+ [void]$ext_args.Add("conv_dim=$conv_dim")
882
+ if ($conv_alpha) {
883
+ [void]$ext_args.Add("conv_alpha=$conv_alpha")
884
+ }
885
+ }
886
+ if ($module_dropout) {
887
+ [void]$ext_args.Add("module_dropout=$module_dropout")
888
+ }
889
+ }
890
+ elseif ($enable_lora_fa) {
891
+ $network_module = "networks.lora_fa"
892
+ }
893
+ elseif ($enable_oft) {
894
+ $network_module = "networks.oft"
895
+ }
896
+ else {
897
+ if ($conv_dim) {
898
+ [void]$ext_args.Add("--network_args")
899
+ [void]$ext_args.Add("conv_dim=$conv_dim")
900
+ if ($conv_alpha) {
901
+ [void]$ext_args.Add("conv_alpha=$conv_alpha")
902
+ }
903
+ }
904
+ }
905
+
906
+ if ($optimizer_type -ieq "adafactor") {
907
+ [void]$ext_args.Add("--optimizer_type=$optimizer_type")
908
+ [void]$ext_args.Add("--optimizer_args")
909
+ [void]$ext_args.Add("scale_parameter=False")
910
+ [void]$ext_args.Add("warmup_init=False")
911
+ [void]$ext_args.Add("relative_step=False")
912
+ if ($lr_scheduler -and $lr_scheduler -ine "constant") {
913
+ $lr_warmup_steps = 100
914
+ }
915
+ }
916
+
917
+ if ($optimizer_type -ilike "DAdapt*") {
918
+ [void]$ext_args.Add("--optimizer_type=$optimizer_type")
919
+ [void]$ext_args.Add("--optimizer_args")
920
+ [void]$ext_args.Add("weight_decay=0.01")
921
+ if ($optimizer_type -ieq "DAdaptation" -or $optimizer_type -ilike "DAdaptAdam*") {
922
+ [void]$ext_args.Add("decouple=True")
923
+ if ($optimizer_type -ieq "DAdaptAdam") {
924
+ [void]$ext_args.Add("use_bias_correction=True")
925
+ }
926
+ }
927
+ $lr = "1"
928
+ if ($unet_lr) {
929
+ $unet_lr = $lr
930
+ }
931
+ if ($text_encoder_lr) {
932
+ $text_encoder_lr = $lr
933
+ }
934
+ }
935
+
936
+ if ($optimizer_type -ieq "Lion" -or $optimizer_type -ieq "Lion8bit" -or $optimizer_type -ieq "PagedLion8bit") {
937
+ [void]$ext_args.Add("--optimizer_type=$optimizer_type")
938
+ [void]$ext_args.Add("--optimizer_args")
939
+ [void]$ext_args.Add("weight_decay=0.01")
940
+ [void]$ext_args.Add("betas=.95,.98")
941
+ }
942
+
943
+ if ($optimizer_type -ieq "AdamW8bit") {
944
+ $optimizer_type = ""
945
+ [void]$ext_args.Add("--use_8bit_adam")
946
+ }
947
+
948
+ if ($optimizer_type -ieq "PagedAdamW8bit" -or $optimizer_type -ieq "AdamW") {
949
+ [void]$ext_args.Add("--optimizer_type=$optimizer_type")
950
+ [void]$ext_args.Add("--optimizer_args")
951
+ [void]$ext_args.Add("weight_decay=0.1")
952
+ [void]$ext_args.Add("betas=.9,.95")
953
+ }
954
+
955
+ if ($optimizer_type -ieq "Sophia") {
956
+ [void]$ext_args.Add("--optimizer_type=pytorch_optimizer.SophiaH")
957
+ [void]$ext_args.Add("--optimizer_args")
958
+ [void]$ext_args.Add("weight_decay=0.01")
959
+ }
960
+
961
+ if ($optimizer_type -ieq "Prodigy") {
962
+ [void]$ext_args.Add("--optimizer_type=$optimizer_type")
963
+ [void]$ext_args.Add("--optimizer_args")
964
+ [void]$ext_args.Add("weight_decay=0.01")
965
+ [void]$ext_args.Add("betas=.9,.99")
966
+ [void]$ext_args.Add("decouple=True")
967
+ [void]$ext_args.Add("use_bias_correction=True")
968
+ [void]$ext_args.Add("d_coef=$d_coef")
969
+ if ($lr_warmup_steps) {
970
+ [void]$ext_args.Add("safeguard_warmup=True")
971
+ }
972
+ if ($d0) {
973
+ [void]$ext_args.Add("d0=$d0")
974
+ }
975
+ $lr = "1"
976
+ if ($unet_lr) {
977
+ $unet_lr = $lr
978
+ }
979
+ if ($text_encoder_lr) {
980
+ $text_encoder_lr = $lr
981
+ }
982
+ }
983
+
984
+ if ($optimizer_type -ieq "Ranger") {
985
+ [void]$ext_args.Add("--optimizer_type=$optimizer_type")
986
+ if (-not($train_unet_only -or $train_text_encoder_only) -or $train_text_encoder) {
987
+ [void]$ext_args.Add("--optimizer_args")
988
+ [void]$ext_args.Add("decouple_lr=True")
989
+ }
990
+ }
991
+
992
+ if ($optimizer_type -ieq "Adan") {
993
+ [void]$ext_args.Add("--optimizer_type=$optimizer_type")
994
+ if (-not($train_unet_only -or $train_text_encoder_only) -or $train_text_encoder) {
995
+ [void]$ext_args.Add("--optimizer_args")
996
+ [void]$ext_args.Add("decouple_lr=True")
997
+ }
998
+ }
999
+
1000
+ if ($optimizer_type -ieq "StableAdamW") {
1001
+ [void]$ext_args.Add("--optimizer_type=$optimizer_type")
1002
+ if (-not($train_unet_only -or $train_text_encoder_only) -or $train_text_encoder) {
1003
+ [void]$ext_args.Add("--optimizer_args")
1004
+ [void]$ext_args.Add("decouple_lr=True")
1005
+ }
1006
+ }
1007
+
1008
+ if ($optimizer_type -ieq "Tiger") {
1009
+ [void]$ext_args.Add("--optimizer_type=pytorch_optimizer.Tiger")
1010
+ [void]$ext_args.Add("--optimizer_args")
1011
+ [void]$ext_args.Add("weight_decay=0.01")
1012
+ }
1013
+
1014
+ if ($optimizer_type -ilike "*ScheduleFree") {
1015
+ [void]$ext_args.Add("--optimizer_type=$optimizer_type")
1016
+ [void]$ext_args.Add("--optimizer_args")
1017
+ [void]$ext_args.Add("weight_decay=0.08")
1018
+ [void]$ext_args.Add("weight_lr_power=0")
1019
+ }
1020
+
1021
+ if ($optimizer_type -ieq "adammini") {
1022
+ [void]$ext_args.Add("--optimizer_type=$optimizer_type")
1023
+ [void]$ext_args.Add("--optimizer_args")
1024
+ [void]$ext_args.Add("weight_decay=0.01")
1025
+ }
1026
+
1027
+ if ($optimizer_type -ieq "adamg") {
1028
+ [void]$ext_args.Add("--optimizer_type=$optimizer_type")
1029
+ [void]$ext_args.Add("--optimizer_args")
1030
+ [void]$ext_args.Add("weight_decay=0.1")
1031
+ [void]$ext_args.Add("weight_decouple=True")
1032
+ }
1033
+
1034
+ if ($gradfilter_ema_alpha -ne 0) {
1035
+ [void]$ext_args.Add("--gradfilter_ema_alpha=$gradfilter_ema_alpha")
1036
+ [void]$ext_args.Add("--gradfilter_ema_lamb=$gradfilter_ema_lamb")
1037
+ }
1038
+
1039
+ if ($unet_lr) {
1040
+ if ($train_unet_only) {
1041
+ $train_text_encoder_only = 0
1042
+ $loraplus_text_encoder_lr_ratio = 0
1043
+ [void]$ext_args.Add("--network_train_unet_only")
1044
+ }
1045
+ [void]$ext_args.Add("--unet_lr=$unet_lr")
1046
+ }
1047
+
1048
+ if ($text_encoder_lr) {
1049
+ if ($train_text_encoder_only) {
1050
+ $loraplus_unet_lr_ratio = 0
1051
+ [void]$ext_args.Add("--network_train_text_encoder_only")
1052
+ }
1053
+ [void]$ext_args.Add("--text_encoder_lr=$text_encoder_lr")
1054
+ }
1055
+
1056
+ if ($enable_lora_plus) {
1057
+ [void]$ext_args.Add("--network_args")
1058
+ if ($loraplus_unet_lr_ratio) {
1059
+ [void]$ext_args.Add("loraplus_lr_ratio=$loraplus_unet_lr_ratio")
1060
+ }
1061
+ elseif ($loraplus_text_encoder_lr_ratio -eq 0) {
1062
+ [void]$ext_args.Add("loraplus_lr_ratio=$loraplus_lr_ratio")
1063
+ }
1064
+ if ($loraplus_text_encoder_lr_ratio) {
1065
+ [void]$ext_args.Add("loraplus_text_encoder_lr_ratio=$loraplus_text_encoder_lr_ratio")
1066
+ }
1067
+ }
1068
+
1069
+ if ($network_weights) {
1070
+ [void]$ext_args.Add("--network_weights=$network_weights")
1071
+ }
1072
+
1073
+ if ($network_multiplier -ne 1.0) {
1074
+ [void]$ext_args.Add("--network_multiplier=$network_multiplier")
1075
+ }
1076
+
1077
+ if ($keep_tokens) {
1078
+ [void]$ext_args.Add("--keep_tokens=$keep_tokens")
1079
+ }
1080
+
1081
+ # if ($keep_tokens_separator) {
1082
+ # [void]$ext_args.Add("--keep_tokens_separator=$keep_tokens_separator")
1083
+ # }
1084
+
1085
+ # if ($secondary_separator) {
1086
+ # [void]$ext_args.Add("--secondary_separator=$secondary_separator")
1087
+ # }
1088
+
1089
+ if ($enable_wildcard) {
1090
+ [void]$ext_args.Add("--enable_wildcard")
1091
+ }
1092
+
1093
+ if ($caption_prefix) {
1094
+ [void]$ext_args.Add("--caption_prefix=$caption_prefix")
1095
+ }
1096
+
1097
+ if ($caption_suffix) {
1098
+ [void]$ext_args.Add("--caption_suffix=$caption_suffix")
1099
+ }
1100
+
1101
+ if ($alpha_mask) {
1102
+ [void]$ext_args.Add("--alpha_mask")
1103
+ }
1104
+
1105
+ if ($min_snr_gamma -ne 0) {
1106
+ [void]$ext_args.Add("--min_snr_gamma=$min_snr_gamma")
1107
+ }
1108
+ elseif ($debiased_estimation_loss -ne 0) {
1109
+ [void]$ext_args.Add("--debiased_estimation_loss")
1110
+ }
1111
+
1112
+ if ($loss_type -ne "l2") {
1113
+ [void]$ext_args.Add("--loss_type=$loss_type")
1114
+ if ($huber_schedule -ne "snr") {
1115
+ [void]$ext_args.Add("--huber_schedule=$huber_schedule")
1116
+ }
1117
+ if ($huber_c -ne 0.1) {
1118
+ [void]$ext_args.Add("--huber_c=$huber_c")
1119
+ }
1120
+ }
1121
+
1122
+ if ($immiscible_noise) {
1123
+ [void]$ext_args.Add("--immiscible_noise")
1124
+ }
1125
+
1126
+ if ($ip_noise_gamma -ne 0) {
1127
+ [void]$ext_args.Add("--ip_noise_gamma=$ip_noise_gamma")
1128
+ if ($ip_noise_gamma_random_strength) {
1129
+ [void]$ext_args.Add("--ip_noise_gamma_random_strength")
1130
+ }
1131
+ }
1132
+
1133
+ if ($wandb_api_key) {
1134
+ [void]$ext_args.Add("--wandb_api_key=$wandb_api_key")
1135
+ [void]$ext_args.Add("--log_with=wandb")
1136
+ [void]$ext_args.Add("--log_tracker_name=" + $output_name)
1137
+ }
1138
+
1139
+ if ($enable_sample) {
1140
+ if ($sample_at_first) {
1141
+ [void]$ext_args.Add("--sample_at_first")
1142
+ }
1143
+ [void]$ext_args.Add("--sample_every_n_epochs=$sample_every_n_epochs")
1144
+ [void]$ext_args.Add("--sample_prompts=$sample_prompts")
1145
+ [void]$ext_args.Add("--sample_sampler=$sample_sampler")
1146
+ }
1147
+
1148
+ if ($base_weights) {
1149
+ [void]$ext_args.Add("--base_weights")
1150
+ foreach ($base_weight in $base_weights.Split(" ")) {
1151
+ [void]$ext_args.Add($base_weight)
1152
+ }
1153
+ [void]$ext_args.Add("--base_weights_multiplier")
1154
+ foreach ($ratio in $base_weights_multiplier.Split(" ")) {
1155
+ [void]$ext_args.Add([float]$ratio)
1156
+ }
1157
+ }
1158
+
1159
+ if ($fused_backward_pass -ne 0) {
1160
+ [void]$ext_args.Add("--fused_backward_pass")
1161
+ $gradient_accumulation_steps = 0
1162
+ $full_fp16 = 0
1163
+ $full_bf16 = 0
1164
+ $fp8_base = 0
1165
+ $mixed_precision = ""
1166
+ $save_precision = "fp16"
1167
+ }
1168
+ elseif ($fused_optimizer_groups) {
1169
+ [void]$ext_args.Add("--fused_optimizer_groups")
1170
+ }
1171
+
1172
+ if ($fp8_base -ne 0) {
1173
+ [void]$ext_args.Add("--fp8_base")
1174
+ }
1175
+ if ($full_fp16 -ne 0) {
1176
+ [void]$ext_args.Add("--full_fp16")
1177
+ $mixed_precision = "fp16"
1178
+ $save_precision = "fp16"
1179
+ }
1180
+ elseif ($full_bf16 -ne 0) {
1181
+ [void]$ext_args.Add("--full_bf16")
1182
+ $mixed_precision = "bf16"
1183
+ $save_precision = "bf16"
1184
+ }
1185
+
1186
+ if ($mixed_precision) {
1187
+ [void]$ext_args.Add("--mixed_precision=$mixed_precision")
1188
+ }
1189
+
1190
+ if ($network_module) {
1191
+ [void]$ext_args.Add("--network_module=$network_module")
1192
+ }
1193
+
1194
+ if ($gradient_accumulation_steps) {
1195
+ [void]$ext_args.Add("--gradient_accumulation_steps=$gradient_accumulation_steps")
1196
+ }
1197
+
1198
+ if ($optimizer_accumulation_steps) {
1199
+ [void]$ext_args.Add("--optimizer_accumulation_steps=$optimizer_accumulation_steps")
1200
+ }
1201
+
1202
+ if ($lr_scheduler) {
1203
+ [void]$ext_args.Add("--lr_scheduler=$lr_scheduler")
1204
+ }
1205
+
1206
+ if ($lr_scheduler_num_cycles) {
1207
+ [void]$ext_args.Add("--lr_scheduler_num_cycles=$lr_scheduler_num_cycles")
1208
+ }
1209
+
1210
+ if ($lr_warmup_steps) {
1211
+ if ($gradient_accumulation_steps) {
1212
+ $lr_warmup_steps = $lr_warmup_steps * $gradient_accumulation_steps
1213
+ }
1214
+ [void]$ext_args.Add("--lr_warmup_steps=$lr_warmup_steps")
1215
+ }
1216
+
1217
+ if ($lr_decay_steps) {
1218
+ if ($gradient_accumulation_steps) {
1219
+ $lr_decay_steps = $lr_decay_steps * $gradient_accumulation_steps
1220
+ }
1221
+ [void]$ext_args.Add("--lr_decay_steps=$lr_decay_steps")
1222
+ }
1223
+
1224
+ if ($lr_scheduler_timescale) {
1225
+ [void]$ext_args.Add("--lr_scheduler_timescale=$lr_scheduler_timescale")
1226
+ }
1227
+
1228
+ if ($lr_scheduler_min_lr_ratio) {
1229
+ [void]$ext_args.Add("--lr_scheduler_min_lr_ratio=$lr_scheduler_min_lr_ratio")
1230
+ }
1231
+
1232
+ if ($caption_dropout_every_n_epochs) {
1233
+ [void]$ext_args.Add("--caption_dropout_every_n_epochs=$caption_dropout_every_n_epochs")
1234
+ }
1235
+ if ($caption_dropout_rate) {
1236
+ [void]$ext_args.Add("--caption_dropout_rate=$caption_dropout_rate")
1237
+ }
1238
+ if ($caption_tag_dropout_rate) {
1239
+ [void]$ext_args.Add("--caption_tag_dropout_rate=$caption_tag_dropout_rate")
1240
+ }
1241
+
1242
+ #add
1243
+ if ($del_pre -eq 1) {
1244
+ Get-ChildItem -Path $train_data_dir -Filter '*.npz' -Recurse -File | Remove-Item -Force
1245
+ Get-ChildItem -Path $reg_data_dir -Filter '*.npz' -Recurse -File | Remove-Item -Force
1246
+ }
1247
+
1248
+ if (-not (Test-Path -Path $output_dir)) {
1249
+ New-Item -Path $output_dir -ItemType Directory -Force
1250
+ }
1251
+
1252
+ if (-not (Test-Path -Path $output_log_dir)) {
1253
+ New-Item -Path $output_log_dir -ItemType Directory -Force
1254
+ }
1255
+
1256
+ # Assuming $launchArgs and $ext_args are arrays in PowerShell
1257
+ # Build the arguments for the Python command
1258
+ $pythonArgs = @(
1259
+ $launchArgs,
1260
+ "./sd-scripts/$laungh_script.py",
1261
+ "--output_dir=$output_dir",
1262
+ "--logging_dir=$output_log_dir",
1263
+ "--resolution=$resolution",
1264
+ "--max_train_epochs=$max_train_epoches",
1265
+ "--learning_rate=$lr",
1266
+ "--output_name=$output_name",
1267
+ "--train_batch_size=$batch_size",
1268
+ "--save_every_n_epochs=$save_every_n_epochs",
1269
+ "--save_precision=$save_precision",
1270
+ "--seed=$seed",
1271
+ "--max_token_length=225",
1272
+ "--caption_extension=.txt",
1273
+ "--vae_batch_size=$vae_batch_size"
1274
+ )
1275
+
1276
+ # Add $ext_args to the pythonArgs
1277
+ $pythonArgs += $ext_args
1278
+
1279
+ # Join all arguments into a single string
1280
+ $commandString = $pythonArgs -join " "
1281
+
1282
+ # Construct the final command
1283
+ $command = "python -m accelerate.commands.launch $commandString"
1284
+
1285
+ # Output the final command for debugging
1286
+ Write-Output $command
1287
+
1288
+ # Change to the script directory
1289
+ Set-Location $PSScriptRoot
1290
+
1291
+ if ($env:OS -ilike "*windows*" -and (Test-Path "./venv/Scripts/Activate.ps1")) {
1292
+ # Activate virtual environment on Windows
1293
+ Write-Output "Windows venv"
1294
+ # Execute the activation script and run the Python command in the same PowerShell session
1295
+ & ./venv/Scripts/Activate.ps1
1296
+ & $command
1297
+ }
1298
+ elseif (Test-Path "./venv/bin/activate") {
1299
+ # Activate virtual environment on Linux
1300
+ Write-Output "Linux venv"
1301
+ # Use bash -c to execute the activation script and the Python command
1302
+ $bashCommand = "source ./venv/bin/activate && $command"
1303
+ bash -c "$bashCommand"
1304
+ } else {
1305
+ # If the virtual environment activation script is not found
1306
+ Write-Output "Virtual environment activation script not found."
1307
+ }
1308
+
1309
+
1310
+ Write-Output "Train finished"
1311
+ exit