-
Notifications
You must be signed in to change notification settings - Fork 6.1k
[Examples] Test all examples on CPU #2289
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
ffaa1a5
[Examples] Test all examples on CPU
patrickvonplaten 576a84d
Merge branch 'main' into add_more_example_tests
patrickvonplaten 6bb4150
add
patrickvonplaten a7ec4f4
correct
patrickvonplaten 7317335
Apply suggestions from code review
patrickvonplaten File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,7 +22,7 @@ | |
from diffusers import DDPMPipeline, DDPMScheduler, UNet2DModel | ||
from diffusers.optimization import get_scheduler | ||
from diffusers.training_utils import EMAModel | ||
from diffusers.utils import check_min_version | ||
from diffusers.utils import check_min_version, is_tensorboard_available | ||
|
||
|
||
# Will error if the minimal version of diffusers is not installed. Remove at your own risks. | ||
|
@@ -67,6 +67,12 @@ def parse_args(): | |
default=None, | ||
help="The config of the Dataset, leave as None if there's only one config.", | ||
) | ||
parser.add_argument( | ||
"--model_config_name_or_path", | ||
type=str, | ||
default=None, | ||
help="The config of the UNet model to train, leave as None to use standard DDPM configuration.", | ||
) | ||
Comment on lines
+70
to
+75
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nice! |
||
parser.add_argument( | ||
"--train_data_dir", | ||
type=str, | ||
|
@@ -222,6 +228,7 @@ def parse_args(): | |
help="Whether the model should predict the 'epsilon'/noise error or directly the reconstructed image 'x0'.", | ||
) | ||
parser.add_argument("--ddpm_num_steps", type=int, default=1000) | ||
parser.add_argument("--ddpm_num_inference_steps", type=int, default=1000) | ||
parser.add_argument("--ddpm_beta_schedule", type=str, default="linear") | ||
parser.add_argument( | ||
"--checkpointing_steps", | ||
|
@@ -340,29 +347,33 @@ def load_model_hook(models, input_dir): | |
os.makedirs(args.output_dir, exist_ok=True) | ||
|
||
# Initialize the model | ||
model = UNet2DModel( | ||
sample_size=args.resolution, | ||
in_channels=3, | ||
out_channels=3, | ||
layers_per_block=2, | ||
block_out_channels=(128, 128, 256, 256, 512, 512), | ||
down_block_types=( | ||
"DownBlock2D", | ||
"DownBlock2D", | ||
"DownBlock2D", | ||
"DownBlock2D", | ||
"AttnDownBlock2D", | ||
"DownBlock2D", | ||
), | ||
up_block_types=( | ||
"UpBlock2D", | ||
"AttnUpBlock2D", | ||
"UpBlock2D", | ||
"UpBlock2D", | ||
"UpBlock2D", | ||
"UpBlock2D", | ||
), | ||
) | ||
if args.model_config_name_or_path is None: | ||
model = UNet2DModel( | ||
sample_size=args.resolution, | ||
in_channels=3, | ||
out_channels=3, | ||
layers_per_block=2, | ||
block_out_channels=(128, 128, 256, 256, 512, 512), | ||
down_block_types=( | ||
"DownBlock2D", | ||
"DownBlock2D", | ||
"DownBlock2D", | ||
"DownBlock2D", | ||
"AttnDownBlock2D", | ||
"DownBlock2D", | ||
), | ||
up_block_types=( | ||
"UpBlock2D", | ||
"AttnUpBlock2D", | ||
"UpBlock2D", | ||
"UpBlock2D", | ||
"UpBlock2D", | ||
"UpBlock2D", | ||
), | ||
) | ||
else: | ||
config = UNet2DModel.load_config(args.model_config_name_or_path) | ||
model = UNet2DModel.from_config(config) | ||
|
||
# Create EMA for the model. | ||
if args.use_ema: | ||
|
@@ -586,13 +597,14 @@ def transform_images(examples): | |
images = pipeline( | ||
generator=generator, | ||
batch_size=args.eval_batch_size, | ||
num_inference_steps=args.ddpm_num_inference_steps, | ||
output_type="numpy", | ||
).images | ||
|
||
# denormalize the images and save to tensorboard | ||
images_processed = (images * 255).round().astype("uint8") | ||
|
||
if args.logger == "tensorboard": | ||
if args.logger == "tensorboard" and is_tensorboard_available(): | ||
accelerator.get_tracker("tensorboard").add_images( | ||
"test_samples", images_processed.transpose(0, 3, 1, 2), epoch | ||
) | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
tensorboard is in the requirements for the
text_to_image
andtextual_inversion
examples, but I actually prefer it this way.