Skip to content

Commit f1d9550

Browse files
committed
set_grads_to_none remove.
1 parent 7dfe378 commit f1d9550

File tree

4 files changed

+3
-21
lines changed

4 files changed

+3
-21
lines changed

examples/control-lora/README.md renamed to examples/flux-control/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Training Control LoRA with Flux
22

3-
This (experimental) example shows how to train Control LoRAs with [Flux](https://huggingface.co/black-forest-labs/FLUX.1-dev) by conditioning it with additional structural controls (like depth maps, poses, etc.).
3+
This (experimental) example shows how to train Control LoRAs with [Flux](https://huggingface.co/black-forest-labs/FLUX.1-dev) by conditioning it with additional structural controls (like depth maps, poses, etc.). We provide a script for full fine-tuning, too, refer to [this section](#full-fine-tuning).
44

55
To incorporate additional condition latents, we expand the input features of Flux.1-Dev from 64 to 128. The first 64 channels correspond to the original input latents to be denoised, while the latter 64 channels correspond to control latents. This expansion happens on the `x_embedder` layer, where the combined latents are projected to the expected feature dimension of rest of the network. Inference is performed using the `FluxControlPipeline`.
66

File renamed without changes.

examples/control-lora/train_control_flux.py renamed to examples/flux-control/train_control_flux.py

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -411,15 +411,6 @@ def parse_args(input_args=None):
411411
" flag passed with the `accelerate.launch` command. Use this argument to override the accelerate config."
412412
),
413413
)
414-
parser.add_argument(
415-
"--set_grads_to_none",
416-
action="store_true",
417-
help=(
418-
"Save more memory by using setting grads to None instead of zero. Be aware, that this changes certain"
419-
" behaviors, so disable this argument if it causes any problems. More info:"
420-
" https://pytorch.org/docs/stable/generated/torch.optim.Optimizer.zero_grad.html"
421-
),
422-
)
423414
parser.add_argument(
424415
"--dataset_name",
425416
type=str,
@@ -1110,7 +1101,7 @@ def get_sigmas(timesteps, n_dim=4, dtype=torch.float32):
11101101
accelerator.clip_grad_norm_(params_to_clip, args.max_grad_norm)
11111102
optimizer.step()
11121103
lr_scheduler.step()
1113-
optimizer.zero_grad(set_to_none=args.set_grads_to_none)
1104+
optimizer.zero_grad()
11141105

11151106
# Checks if the accelerator has performed an optimization step behind the scenes
11161107
if accelerator.sync_gradients:

examples/control-lora/train_control_lora_flux.py renamed to examples/flux-control/train_control_lora_flux.py

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -443,15 +443,6 @@ def parse_args(input_args=None):
443443
" flag passed with the `accelerate.launch` command. Use this argument to override the accelerate config."
444444
),
445445
)
446-
parser.add_argument(
447-
"--set_grads_to_none",
448-
action="store_true",
449-
help=(
450-
"Save more memory by using setting grads to None instead of zero. Be aware, that this changes certain"
451-
" behaviors, so disable this argument if it causes any problems. More info:"
452-
" https://pytorch.org/docs/stable/generated/torch.optim.Optimizer.zero_grad.html"
453-
),
454-
)
455446
parser.add_argument(
456447
"--dataset_name",
457448
type=str,
@@ -1251,7 +1242,7 @@ def get_sigmas(timesteps, n_dim=4, dtype=torch.float32):
12511242
accelerator.clip_grad_norm_(params_to_clip, args.max_grad_norm)
12521243
optimizer.step()
12531244
lr_scheduler.step()
1254-
optimizer.zero_grad(set_to_none=args.set_grads_to_none)
1245+
optimizer.zero_grad()
12551246

12561247
# Checks if the accelerator has performed an optimization step behind the scenes
12571248
if accelerator.sync_gradients:

0 commit comments

Comments
 (0)