Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions examples/dreambooth/test_dreambooth_lora_flux2.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import json
import logging
import os
import shutil
import sys
import tempfile

Expand Down Expand Up @@ -111,6 +112,38 @@ def test_dreambooth_lora_latent_caching(self):
starts_with_transformer = all(key.startswith("transformer") for key in lora_state_dict.keys())
self.assertTrue(starts_with_transformer)

def test_dreambooth_lora_flux2_prior_preservation_batch_size_two(self):
with tempfile.TemporaryDirectory() as tmpdir:
class_data_dir = os.path.join(tmpdir, "class_data")
os.makedirs(class_data_dir)
for image_name in os.listdir(self.instance_data_dir)[:2]:
shutil.copy(os.path.join(self.instance_data_dir, image_name), class_data_dir)

test_args = f"""
{self.script_path}
--pretrained_model_name_or_path {self.pretrained_model_name_or_path}
--instance_data_dir {self.instance_data_dir}
--instance_prompt {self.instance_prompt}
--with_prior_preservation
--class_data_dir {class_data_dir}
--class_prompt dog
--num_class_images 2
Comment on lines +127 to +130
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I updated both tests to use a dedicated temporary class_data directory and copy two fixture images into it, so the tests no longer reuse the instance data directory for class images.

--resolution 64
--train_batch_size 2
--gradient_accumulation_steps 1
--max_train_steps 1
--learning_rate 5.0e-04
--scale_lr
--lr_scheduler constant
--lr_warmup_steps 0
--max_sequence_length 8
--text_encoder_out_layers 1
--output_dir {tmpdir}
""".split()
Comment thread
azolotenkov marked this conversation as resolved.

run_command(self._launch_args + test_args)
self.assertTrue(os.path.isfile(os.path.join(tmpdir, "pytorch_lora_weights.safetensors")))

def test_dreambooth_lora_layers(self):
with tempfile.TemporaryDirectory() as tmpdir:
test_args = f"""
Expand Down
33 changes: 33 additions & 0 deletions examples/dreambooth/test_dreambooth_lora_flux2_klein.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import json
import logging
import os
import shutil
import sys
import tempfile

Expand Down Expand Up @@ -111,6 +112,38 @@ def test_dreambooth_lora_latent_caching(self):
starts_with_transformer = all(key.startswith("transformer") for key in lora_state_dict.keys())
self.assertTrue(starts_with_transformer)

def test_dreambooth_lora_flux2_klein_prior_preservation_batch_size_two(self):
with tempfile.TemporaryDirectory() as tmpdir:
class_data_dir = os.path.join(tmpdir, "class_data")
os.makedirs(class_data_dir)
for image_name in os.listdir(self.instance_data_dir)[:2]:
shutil.copy(os.path.join(self.instance_data_dir, image_name), class_data_dir)

test_args = f"""
{self.script_path}
--pretrained_model_name_or_path {self.pretrained_model_name_or_path}
--instance_data_dir {self.instance_data_dir}
--instance_prompt {self.instance_prompt}
--with_prior_preservation
--class_data_dir {class_data_dir}
--class_prompt dog
--num_class_images 2
Comment thread
azolotenkov marked this conversation as resolved.
--resolution 64
--train_batch_size 2
--gradient_accumulation_steps 1
--max_train_steps 1
--learning_rate 5.0e-04
--scale_lr
--lr_scheduler constant
--lr_warmup_steps 0
--max_sequence_length 8
--text_encoder_out_layers 1
--output_dir {tmpdir}
""".split()

run_command(self._launch_args + test_args)
self.assertTrue(os.path.isfile(os.path.join(tmpdir, "pytorch_lora_weights.safetensors")))

def test_dreambooth_lora_layers(self):
with tempfile.TemporaryDirectory() as tmpdir:
test_args = f"""
Expand Down
Loading