Skip to content

Commit a98a839

Browse files
leisuzz蒋硕sayakpaul
authored
Reduce Memory Cost in Flux Training (#9829)
* Improve NPU performance * Improve NPU performance * Improve NPU performance * Improve NPU performance * [bugfix] bugfix for npu free memory * [bugfix] bugfix for npu free memory * [bugfix] bugfix for npu free memory * Reduce memory cost for flux training process --------- Co-authored-by: 蒋硕 <[email protected]> Co-authored-by: Sayak Paul <[email protected]>
1 parent 3deed72 commit a98a839

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

examples/dreambooth/train_dreambooth_flux.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1740,6 +1740,9 @@ def get_sigmas(timesteps, n_dim=4, dtype=torch.float32):
17401740
torch_npu.npu.empty_cache()
17411741
gc.collect()
17421742

1743+
images = None
1744+
del pipeline
1745+
17431746
# Save the lora layers
17441747
accelerator.wait_for_everyone()
17451748
if accelerator.is_main_process:
@@ -1798,6 +1801,9 @@ def get_sigmas(timesteps, n_dim=4, dtype=torch.float32):
17981801
ignore_patterns=["step_*", "epoch_*"],
17991802
)
18001803

1804+
images = None
1805+
del pipeline
1806+
18011807
accelerator.end_training()
18021808

18031809

examples/dreambooth/train_dreambooth_lora_flux.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1844,6 +1844,9 @@ def get_sigmas(timesteps, n_dim=4, dtype=torch.float32):
18441844
del text_encoder_one, text_encoder_two
18451845
free_memory()
18461846

1847+
images = None
1848+
del pipeline
1849+
18471850
# Save the lora layers
18481851
accelerator.wait_for_everyone()
18491852
if accelerator.is_main_process:
@@ -1908,6 +1911,9 @@ def get_sigmas(timesteps, n_dim=4, dtype=torch.float32):
19081911
ignore_patterns=["step_*", "epoch_*"],
19091912
)
19101913

1914+
images = None
1915+
del pipeline
1916+
19111917
accelerator.end_training()
19121918

19131919

0 commit comments

Comments
 (0)