Skip to content
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

[training] fixes to the quantization training script and add AdEMAMix optimizer as an option #9806

Merged
merged 4 commits into from
Oct 31, 2024

Conversation

sayakpaul
Copy link
Member

What does this PR do?

@sayakpaul sayakpaul requested a review from linoytsaban October 30, 2024 05:35
@@ -1059,7 +1076,7 @@ def get_sigmas(timesteps, n_dim=4, dtype=torch.float32):
)

# handle guidance
if transformer.config.guidance_embeds:
if unwrap_model(transformer).config.guidance_embeds:
Copy link
Member Author

Choose a reason for hiding this comment

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

So that things are compatible with DeepSpeed.

Comment on lines +1040 to 1047
vae_scale_factor = 2 ** (len(vae_config_block_out_channels) - 1)

latent_image_ids = FluxPipeline._prepare_latent_image_ids(
model_input.shape[0],
model_input.shape[2],
model_input.shape[3],
model_input.shape[2] // 2,
model_input.shape[3] // 2,
accelerator.device,
weight_dtype,
Copy link
Member Author

Choose a reason for hiding this comment

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

Follows what we do in the Flux LoRA scripts.

Comment on lines +1102 to +1103
height=model_input.shape[2] * vae_scale_factor,
width=model_input.shape[3] * vae_scale_factor,
Copy link
Member Author

Choose a reason for hiding this comment

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

Same as above.

@HuggingFaceDocBuilderDev

The docs for this PR live here. All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update.

Copy link
Collaborator

@linoytsaban linoytsaban left a comment

Choose a reason for hiding this comment

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

Cool! did you get a chance to play with AdEMAMix? should we consider adding it to the other scripts as well?

@sayakpaul
Copy link
Member Author

Cool! did you get a chance to play with AdEMAMix? should we consider adding it to the other scripts as well?

Testing the memory requirement as we speak. Will report back.

else:
optimizer_class = bnb.optim.AdEMAMix

optimizer = optimizer_class(params_to_optimize)
Copy link
Collaborator

Choose a reason for hiding this comment

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

should we support betas and weight_decay here?
We could use the existing args like we did for prodigy, i.e.

optimizer = optimizer_class(params_to_optimize,
betas=(args.adam_beta1, args.adam_beta2),
weight_decay=args.adam_weight_decay)

Copy link
Member Author

Choose a reason for hiding this comment

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

Umm I didn't want to actually to keep the separations of concern very clear. We could maybe revisit if the community finds the optimizer worth the go?

@sayakpaul
Copy link
Member Author

sayakpaul commented Oct 30, 2024

@linoytsaban seems identical to me:
https://wandb.ai/sayakpaul/dreambooth-flux-dev-lora-nf4/

Let's maybe wait a bit before we propagate this to canonical scripts? Meanwhile can I merge this PR?

Internal thread: https://huggingface.slack.com/archives/C04NNCRFYUQ/p1730299681912129

Optimizer Visualization
Adam Adam
AdEMAMix AdEMAMix

With

...

image = pipeline(
    "a puppy in a pond, yarn art style", num_inference_steps=28, guidance_scale=3.5, height=768
).images[0]

@linoytsaban
Copy link
Collaborator

@sayakpaul yeah sounds good to me :) let's 🛳️

@sayakpaul sayakpaul merged commit 09b8aeb into main Oct 31, 2024
11 checks passed
@sayakpaul sayakpaul deleted the fix-quantization-training branch October 31, 2024 10:16
a-r-r-o-w pushed a commit that referenced this pull request Nov 1, 2024
sayakpaul added a commit that referenced this pull request Dec 23, 2024
… optimizer as an option (#9806)

* fixes

* more fixes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants