Skip to content

Commit 363f83c

Browse files
fix(ui): Set Zero values to Null instead of 0.0 (#161)
1 parent 99c673d commit 363f83c

15 files changed

Lines changed: 85 additions & 55 deletions

File tree

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ dependencies = [
6969

7070
[tool.ruff]
7171
src = ["src"]
72-
select = ["E", "F", "W", "C9", "N8", "I"]
72+
lint.select = ["E", "F", "W", "C9", "N8", "I"]
7373
target-version = "py39"
7474
line-length = 120
7575

src/invoke_training/pipelines/_experimental/sd_dpo_lora/config.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,11 +95,12 @@ class SdDirectPreferenceOptimizationLoraConfig(BasePipelineConfig):
9595

9696
text_encoder_learning_rate: float | None = None
9797
"""The learning rate to use for the text encoder model. If set, this overrides the optimizer's default learning
98-
rate.
98+
rate. Set to null or 0 to use the optimizer's default learning rate.
9999
"""
100100

101101
unet_learning_rate: float | None = None
102102
"""The learning rate to use for the UNet model. If set, this overrides the optimizer's default learning rate.
103+
Set to null or 0 to use the optimizer's default learning rate.
103104
"""
104105

105106
lr_scheduler: Literal[
@@ -194,7 +195,7 @@ class SdDirectPreferenceOptimizationLoraConfig(BasePipelineConfig):
194195
"""
195196

196197
max_grad_norm: float | None = None
197-
"""Max gradient norm for clipping. Set to None for no clipping.
198+
"""Max gradient norm for clipping. Set to null or 0 for no clipping.
198199
"""
199200

200201
validation_prompts: list[str] = []

src/invoke_training/pipelines/flux/lora/config.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,12 +52,12 @@ class FluxLoraConfig(BasePipelineConfig):
5252

5353
text_encoder_learning_rate: float | None = 1e-4
5454
"""The learning rate to use for the text encoder model. If set, this overrides the optimizer's default learning
55-
rate.
55+
rate. Set to null or 0 to use the optimizer's default learning rate.
5656
"""
5757

5858
transformer_learning_rate: float | None = 4e-4
5959
"""The learning rate to use for the transformer model. If set, this overrides the optimizer's default learning
60-
rate.
60+
rate. Set to null or 0 to use the optimizer's default learning rate.
6161
"""
6262

6363
lr_scheduler: Literal[
@@ -176,7 +176,7 @@ class FluxLoraConfig(BasePipelineConfig):
176176
"""
177177

178178
max_grad_norm: float | None = None
179-
"""Max gradient norm for clipping. Set to None for no clipping.
179+
"""Max gradient norm for clipping. Set to null or 0 for no clipping.
180180
"""
181181

182182
validation_prompts: list[str] = []

src/invoke_training/pipelines/stable_diffusion/lora/config.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,11 +59,12 @@ class SdLoraConfig(BasePipelineConfig):
5959

6060
text_encoder_learning_rate: float | None = None
6161
"""The learning rate to use for the text encoder model. If set, this overrides the optimizer's default learning
62-
rate.
62+
rate. Set to null or 0 to use the optimizer's default learning rate.
6363
"""
6464

6565
unet_learning_rate: float | None = None
6666
"""The learning rate to use for the UNet model. If set, this overrides the optimizer's default learning rate.
67+
Set to null or 0 to use the optimizer's default learning rate.
6768
"""
6869

6970
lr_scheduler: Literal[
@@ -188,7 +189,7 @@ class SdLoraConfig(BasePipelineConfig):
188189
"""
189190

190191
max_grad_norm: float | None = None
191-
"""Max gradient norm for clipping. Set to None for no clipping.
192+
"""Max gradient norm for clipping. Set to null or 0 for no clipping.
192193
"""
193194

194195
validation_prompts: list[str] = []

src/invoke_training/pipelines/stable_diffusion/textual_inversion/config.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ class SdTextualInversionConfig(BasePipelineConfig):
160160
"""
161161

162162
max_grad_norm: float | None = None
163-
"""Maximum gradient norm for gradient clipping. Set to `None` for no clipping.
163+
"""Maximum gradient norm for gradient clipping. Set to `null` or 0 for no clipping.
164164
"""
165165

166166
validation_prompts: list[str] = []

src/invoke_training/pipelines/stable_diffusion_xl/finetune/config.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ class SdxlFinetuneConfig(BasePipelineConfig):
125125
"""
126126

127127
max_grad_norm: float | None = None
128-
"""Max gradient norm for clipping. Set to None for no clipping.
128+
"""Max gradient norm for clipping. Set to null or 0 for no clipping.
129129
"""
130130

131131
validation_prompts: list[str] = []

src/invoke_training/pipelines/stable_diffusion_xl/lora/config.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,11 +59,12 @@ class SdxlLoraConfig(BasePipelineConfig):
5959

6060
text_encoder_learning_rate: float | None = None
6161
"""The learning rate to use for the text encoder model. If set, this overrides the optimizer's default learning
62-
rate.
62+
rate. Set to null or 0 to use the optimizer's default learning rate.
6363
"""
6464

6565
unet_learning_rate: float | None = None
6666
"""The learning rate to use for the UNet model. If set, this overrides the optimizer's default learning rate.
67+
Set to null or 0 to use the optimizer's default learning rate.
6768
"""
6869

6970
lr_scheduler: Literal[
@@ -188,7 +189,7 @@ class SdxlLoraConfig(BasePipelineConfig):
188189
"""
189190

190191
max_grad_norm: float | None = None
191-
"""Max gradient norm for clipping. Set to None for no clipping.
192+
"""Max gradient norm for clipping. Set to null or 0 for no clipping.
192193
"""
193194

194195
validation_prompts: list[str] = []

src/invoke_training/pipelines/stable_diffusion_xl/lora_and_textual_inversion/config.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -84,16 +84,18 @@ class SdxlLoraAndTextualInversionConfig(BasePipelineConfig):
8484

8585
optimizer: AdamOptimizerConfig | ProdigyOptimizerConfig = AdamOptimizerConfig()
8686

87-
text_encoder_learning_rate: float = 1e-5
88-
"""The learning rate to use for the text encoder model.
87+
text_encoder_learning_rate: float | None = 1e-5
88+
"""The learning rate to use for the text encoder model. Set to null or 0 to use the optimizer's default learning
89+
rate.
8990
"""
9091

91-
unet_learning_rate: float = 1e-4
92-
"""The learning rate to use for the UNet model.
92+
unet_learning_rate: float | None = 1e-4
93+
"""The learning rate to use for the UNet model. Set to null or 0 to use the optimizer's default learning rate.
9394
"""
9495

95-
textual_inversion_learning_rate: float = 1e-3
96-
"""The learning rate to use for textual inversion training of the embeddings.
96+
textual_inversion_learning_rate: float | None = 1e-3
97+
"""The learning rate to use for textual inversion training of the embeddings. Set to null or 0 to use the
98+
optimizer's default learning rate.
9799
"""
98100

99101
lr_scheduler: Literal[
@@ -187,7 +189,7 @@ class SdxlLoraAndTextualInversionConfig(BasePipelineConfig):
187189
"""
188190

189191
max_grad_norm: float | None = None
190-
"""Max gradient norm for clipping. Set to None for no clipping.
192+
"""Max gradient norm for clipping. Set to null or 0 for no clipping.
191193
"""
192194

193195
validation_prompts: list[str] = []

src/invoke_training/ui/config_groups/flux_lora_config_group.py

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ def __init__(self):
6767
with gr.Row():
6868
self.transformer_learning_rate = gr.Number(
6969
label="Transformer Learning Rate",
70-
info="The transformer learning rate. If None, then it is inherited from the base optimizer "
70+
info="The transformer learning rate. Set to 0 or leave empty to inherit from the base optimizer "
7171
"learning rate.",
7272
interactive=True,
7373
)
@@ -103,7 +103,7 @@ def __init__(self):
103103
)
104104
self.max_grad_norm = gr.Number(
105105
label="Max Gradient Norm",
106-
info="Max gradient norm for clipping. Set to None for no clipping.",
106+
info="Max gradient norm for clipping. Set to 0 or leave empty for no clipping (null).",
107107
interactive=True,
108108
)
109109
self.train_batch_size = gr.Number(
@@ -313,13 +313,9 @@ def safe_pop(component, default=None):
313313
# Set basic properties
314314
new_config.model = safe_pop(self.model, new_config.model)
315315
new_config.train_transformer = safe_pop(self.train_transformer, new_config.train_transformer)
316-
new_config.train_text_encoder = safe_pop(self.train_text_encoder, new_config.train_text_encoder)
317-
new_config.transformer_learning_rate = safe_pop(
318-
self.transformer_learning_rate, new_config.transformer_learning_rate
319-
)
320-
new_config.text_encoder_learning_rate = safe_pop(
321-
self.text_encoder_learning_rate, new_config.text_encoder_learning_rate
322-
)
316+
# Note: train_text_encoder and text_encoder_learning_rate are not supported for Flux LoRA
317+
transformer_lr_value = safe_pop(self.transformer_learning_rate, new_config.transformer_learning_rate)
318+
new_config.transformer_learning_rate = None if transformer_lr_value == 0 else transformer_lr_value
323319
new_config.gradient_accumulation_steps = safe_pop(
324320
self.gradient_accumulation_steps, new_config.gradient_accumulation_steps
325321
)
@@ -330,7 +326,8 @@ def safe_pop(component, default=None):
330326

331327
new_config.lora_rank_dim = safe_pop(self.lora_rank_dim, new_config.lora_rank_dim)
332328
new_config.min_snr_gamma = safe_pop(self.min_snr_gamma, new_config.min_snr_gamma)
333-
new_config.max_grad_norm = safe_pop(self.max_grad_norm, new_config.max_grad_norm)
329+
max_grad_norm_value = safe_pop(self.max_grad_norm, new_config.max_grad_norm)
330+
new_config.max_grad_norm = None if max_grad_norm_value == 0 else max_grad_norm_value
334331
new_config.train_batch_size = safe_pop(self.train_batch_size, new_config.train_batch_size)
335332
new_config.weight_dtype = safe_pop(self.weight_dtype, new_config.weight_dtype)
336333
new_config.mixed_precision = safe_pop(self.mixed_precision, new_config.mixed_precision)

src/invoke_training/ui/config_groups/sd_lora_config_group.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -109,12 +109,13 @@ def __init__(self):
109109
with gr.Row():
110110
self.unet_learning_rate = gr.Number(
111111
label="UNet Learning Rate",
112-
info="The UNet learning rate. If None, then it is inherited from the base optimizer learning rate.",
112+
info="The UNet learning rate. Set to 0 or leave empty to inherit from the base optimizer "
113+
"learning rate.",
113114
interactive=True,
114115
)
115116
self.text_encoder_learning_rate = gr.Number(
116117
label="Text Encoder Learning Rate",
117-
info="The text encoder learning rate. If None, then it is inherited from the base optimizer "
118+
info="The text encoder learning rate. Set to 0 or leave empty to inherit from the base optimizer "
118119
"learning rate.",
119120
interactive=True,
120121
)
@@ -153,7 +154,7 @@ def __init__(self):
153154
)
154155
self.max_grad_norm = gr.Number(
155156
label="Max Gradient Norm",
156-
info="Max gradient norm for clipping. Set to None for no clipping.",
157+
info="Max gradient norm for clipping. Set to 0 or leave empty for no clipping (null).",
157158
interactive=True,
158159
)
159160
self.train_batch_size = gr.Number(
@@ -223,13 +224,16 @@ def update_config_with_ui_component_data(
223224
new_config.hf_variant = ui_data.pop(self.hf_variant) or None
224225
new_config.max_checkpoints = ui_data.pop(self.max_checkpoints)
225226
new_config.train_unet = ui_data.pop(self.train_unet)
226-
new_config.unet_learning_rate = ui_data.pop(self.unet_learning_rate)
227+
unet_lr_value = ui_data.pop(self.unet_learning_rate)
228+
new_config.unet_learning_rate = None if unet_lr_value == 0 else unet_lr_value
227229
new_config.train_text_encoder = ui_data.pop(self.train_text_encoder)
228-
new_config.text_encoder_learning_rate = ui_data.pop(self.text_encoder_learning_rate)
230+
text_encoder_lr_value = ui_data.pop(self.text_encoder_learning_rate)
231+
new_config.text_encoder_learning_rate = None if text_encoder_lr_value == 0 else text_encoder_lr_value
229232
new_config.lr_scheduler = ui_data.pop(self.lr_scheduler)
230233
new_config.lr_warmup_steps = ui_data.pop(self.lr_warmup_steps)
231234
new_config.use_masks = ui_data.pop(self.use_masks)
232-
new_config.max_grad_norm = ui_data.pop(self.max_grad_norm)
235+
max_grad_norm_value = ui_data.pop(self.max_grad_norm)
236+
new_config.max_grad_norm = None if max_grad_norm_value == 0 else max_grad_norm_value
233237
new_config.train_batch_size = ui_data.pop(self.train_batch_size)
234238
new_config.cache_text_encoder_outputs = ui_data.pop(self.cache_text_encoder_outputs)
235239
new_config.cache_vae_outputs = ui_data.pop(self.cache_vae_outputs)

0 commit comments

Comments
 (0)