|
55 | 55 | from diffusers.training_utils import ( |
56 | 56 | _set_state_dict_into_text_encoder, |
57 | 57 | cast_training_params, |
58 | | - clear_objs_and_retain_memory, |
59 | 58 | compute_density_for_timestep_sampling, |
60 | 59 | compute_loss_weighting_for_sd3, |
| 60 | + free_memory, |
61 | 61 | ) |
62 | 62 | from diffusers.utils import ( |
63 | 63 | check_min_version, |
@@ -211,7 +211,8 @@ def log_validation( |
211 | 211 | } |
212 | 212 | ) |
213 | 213 |
|
214 | | - clear_objs_and_retain_memory(objs=[pipeline]) |
| 214 | + del pipeline |
| 215 | + free_memory() |
215 | 216 |
|
216 | 217 | return images |
217 | 218 |
|
@@ -1106,7 +1107,8 @@ def main(args): |
1106 | 1107 | image_filename = class_images_dir / f"{example['index'][i] + cur_class_images}-{hash_image}.jpg" |
1107 | 1108 | image.save(image_filename) |
1108 | 1109 |
|
1109 | | - clear_objs_and_retain_memory(objs=[pipeline]) |
| 1110 | + del pipeline |
| 1111 | + free_memory() |
1110 | 1112 |
|
1111 | 1113 | # Handle the repository creation |
1112 | 1114 | if accelerator.is_main_process: |
@@ -1453,9 +1455,9 @@ def compute_text_embeddings(prompt, text_encoders, tokenizers): |
1453 | 1455 | # Clear the memory here |
1454 | 1456 | if not args.train_text_encoder and not train_dataset.custom_instance_prompts: |
1455 | 1457 | # Explicitly delete the objects as well, otherwise only the lists are deleted and the original references remain, preventing garbage collection |
1456 | | - clear_objs_and_retain_memory( |
1457 | | - objs=[tokenizers, text_encoders, text_encoder_one, text_encoder_two, text_encoder_three] |
1458 | | - ) |
| 1458 | + del tokenizers, text_encoders |
| 1459 | + del text_encoder_one, text_encoder_two, text_encoder_three |
| 1460 | + free_memory() |
1459 | 1461 |
|
1460 | 1462 | # If custom instance prompts are NOT provided (i.e. the instance prompt is used for all images), |
1461 | 1463 | # pack the statically computed variables appropriately here. This is so that we don't |
@@ -1791,11 +1793,9 @@ def get_sigmas(timesteps, n_dim=4, dtype=torch.float32): |
1791 | 1793 | epoch=epoch, |
1792 | 1794 | torch_dtype=weight_dtype, |
1793 | 1795 | ) |
1794 | | - objs = [] |
1795 | | - if not args.train_text_encoder: |
1796 | | - objs.extend([text_encoder_one, text_encoder_two, text_encoder_three]) |
1797 | 1796 |
|
1798 | | - clear_objs_and_retain_memory(objs=objs) |
| 1797 | + del text_encoder_one, text_encoder_two, text_encoder_three |
| 1798 | + free_memory() |
1799 | 1799 |
|
1800 | 1800 | # Save the lora layers |
1801 | 1801 | accelerator.wait_for_everyone() |
|
0 commit comments