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

Flax pipeline pndm #583

Merged
merged 30 commits into from
Sep 27, 2022
Merged

Flax pipeline pndm #583

merged 30 commits into from
Sep 27, 2022

Conversation

pcuenca
Copy link
Member

@pcuenca pcuenca commented Sep 20, 2022

WIP for PNDM scheduler support in Flax pipeline. Includes #577 and #581 (which I need for testing).

@HuggingFaceDocBuilderDev
Copy link

HuggingFaceDocBuilderDev commented Sep 20, 2022

The documentation is not available anymore as the PR was closed or merged.

src/diffusers/configuration_utils.py Outdated Show resolved Hide resolved
src/diffusers/schedulers/scheduling_ddim_flax.py Outdated Show resolved Hide resolved
src/diffusers/schedulers/scheduling_pndm_flax.py Outdated Show resolved Hide resolved
src/diffusers/schedulers/scheduling_pndm_flax.py Outdated Show resolved Hide resolved
src/diffusers/schedulers/scheduling_pndm_flax.py Outdated Show resolved Hide resolved
Values returned still not verified for correctness.
Base automatically changed from flax_pipeline to main September 20, 2022 19:30
@pcuenca
Copy link
Member Author

pcuenca commented Sep 21, 2022

This is ready for review, I just synced with main. There are almost more commits than line changes lol, because I kept changes from other PRs that I needed to test.

I tested a generation with the current Flax pipeline using the FlaxPNDMScheduler and it worked fine, so we may want to set it as the default for Stable Diffusion after we verify everything's correct. In that regard, I tested the plms steps extensively when I was working in Suraj's repo, and I haven't tested the prk steps at all – just checked that they run. Perhaps we can use @kashif's tests to verify.

Copy link
Contributor

@patil-suraj patil-suraj left a comment

Choose a reason for hiding this comment

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

Very cool @pcuenca , just left tiny nits.

And yes, we can set this as default scheduler, maybe in a follow-up PR.

Thanks a lot for working on this :)

src/diffusers/schedulers/scheduling_pndm_flax.py Outdated Show resolved Hide resolved
src/diffusers/schedulers/scheduling_pndm_flax.py Outdated Show resolved Hide resolved
src/diffusers/schedulers/scheduling_pndm_flax.py Outdated Show resolved Hide resolved
src/diffusers/schedulers/scheduling_pndm_flax.py Outdated Show resolved Hide resolved
@patrickvonplaten
Copy link
Contributor

Should we merge this one?

@pcuenca
Copy link
Member Author

pcuenca commented Sep 27, 2022

Should we merge this one?

I think I addressed all the comments, so it should be ok to merge.

We still need to verify the numerical outputs of the PRK steps (not used in Stable Diffusion afaik). I'll try to do it today.

@patrickvonplaten
Copy link
Contributor

Merging then! Think we don't need to verify prk as it's Flax. Let's only dive into it if people ask for it

@patrickvonplaten patrickvonplaten merged commit ab3fd67 into main Sep 27, 2022
@patrickvonplaten patrickvonplaten deleted the flax_pipeline_pndm branch September 27, 2022 12:16
prathikr pushed a commit to prathikr/diffusers that referenced this pull request Oct 26, 2022
* WIP: flax FlaxDiffusionPipeline & FlaxStableDiffusionPipeline

* todo comment

* Fix imports

* Fix imports

* add dummies

* Fix empty init

* make pipeline work

* up

* Allow dtype to be overridden on model load.

This may be a temporary solution until huggingface#567 is addressed.

* Convert params to bfloat16 or fp16 after loading.

This deals with the weights, not the model.

* Use Flax schedulers (typing, docstring)

* PNDM: replace control flow with jax functions.

Otherwise jitting/parallelization don't work properly as they don't know
how to deal with traced objects.

I temporarily removed `step_prk`.

* Pass latents shape to scheduler set_timesteps()

PNDMScheduler uses it to reserve space, other schedulers will just
ignore it.

* Wrap model imports inside availability checks.

* Optionally return state in from_config.

Useful for Flax schedulers.

* Do not convert model weights to dtype.

* Re-enable PRK steps with functional implementation.

Values returned still not verified for correctness.

* Remove left over has_state var.

* make style

* Apply suggestion list -> tuple

Co-authored-by: Suraj Patil <[email protected]>

* Apply suggestion list -> tuple

Co-authored-by: Suraj Patil <[email protected]>

* Remove unused comments.

* Use zeros instead of empty.

Co-authored-by: Mishig Davaadorj <[email protected]>
Co-authored-by: Mishig Davaadorj <[email protected]>
Co-authored-by: Patrick von Platen <[email protected]>
Co-authored-by: Suraj Patil <[email protected]>
yoonseokjin pushed a commit to yoonseokjin/diffusers that referenced this pull request Dec 25, 2023
* WIP: flax FlaxDiffusionPipeline & FlaxStableDiffusionPipeline

* todo comment

* Fix imports

* Fix imports

* add dummies

* Fix empty init

* make pipeline work

* up

* Allow dtype to be overridden on model load.

This may be a temporary solution until huggingface#567 is addressed.

* Convert params to bfloat16 or fp16 after loading.

This deals with the weights, not the model.

* Use Flax schedulers (typing, docstring)

* PNDM: replace control flow with jax functions.

Otherwise jitting/parallelization don't work properly as they don't know
how to deal with traced objects.

I temporarily removed `step_prk`.

* Pass latents shape to scheduler set_timesteps()

PNDMScheduler uses it to reserve space, other schedulers will just
ignore it.

* Wrap model imports inside availability checks.

* Optionally return state in from_config.

Useful for Flax schedulers.

* Do not convert model weights to dtype.

* Re-enable PRK steps with functional implementation.

Values returned still not verified for correctness.

* Remove left over has_state var.

* make style

* Apply suggestion list -> tuple

Co-authored-by: Suraj Patil <[email protected]>

* Apply suggestion list -> tuple

Co-authored-by: Suraj Patil <[email protected]>

* Remove unused comments.

* Use zeros instead of empty.

Co-authored-by: Mishig Davaadorj <[email protected]>
Co-authored-by: Mishig Davaadorj <[email protected]>
Co-authored-by: Patrick von Platen <[email protected]>
Co-authored-by: Suraj Patil <[email protected]>
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.

5 participants