-
Notifications
You must be signed in to change notification settings - Fork 6.5k
Flax support for Stable Diffusion 2 #1423
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
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
76bb311
Flax: start adapting to Stable Diffusion 2
pcuenca a87c3d9
More changes.
pcuenca 9924277
attention_head_dim can be a tuple.
pcuenca b684d8c
Fix typos
pcuenca 7782f50
Add simple SD 2 integration test.
pcuenca 40f7550
Add simple UNet integration tests for Flax.
pcuenca 0cf9dbd
Apply suggestions from code review
pcuenca 0d375e9
Merge remote-tracking branch 'origin/main' into flax-sd-2
pcuenca 084d83a
Typos and style
pcuenca ff84ecc
Tests: verify jax is available.
pcuenca 93d833d
Style
pcuenca eee35b8
Make flake happy
pcuenca 783d8cd
Remove typo.
pcuenca a32af1f
Simple Flax SD 2 pipeline tests.
pcuenca 383dacd
Import order
pcuenca d99411b
Remove unused import.
pcuenca 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
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 |
|---|---|---|
|
|
@@ -639,3 +639,29 @@ def test_compvis_sd_inpaint_fp16(self, seed, timestep, expected_slice): | |
| expected_output_slice = torch.tensor(expected_slice) | ||
|
|
||
| assert torch_all_close(output_slice, expected_output_slice, atol=5e-3) | ||
|
|
||
| @parameterized.expand( | ||
| [ | ||
| # fmt: off | ||
| [83, 4, [0.1514, 0.0807, 0.1624, 0.1016, -0.1896, 0.0263, 0.0677, 0.2310]], | ||
| [17, 0.55, [0.1164, -0.0216, 0.0170, 0.1589, -0.3120, 0.1005, -0.0581, -0.1458]], | ||
| [8, 0.89, [-0.1758, -0.0169, 0.1004, -0.1411, 0.1312, 0.1103, -0.1996, 0.2139]], | ||
| [3, 1000, [0.1214, 0.0352, -0.0731, -0.1562, -0.0994, -0.0906, -0.2340, -0.0539]], | ||
| # fmt: on | ||
| ] | ||
| ) | ||
| @require_torch_gpu | ||
| def test_stabilityai_sd_v2_fp16(self, seed, timestep, expected_slice): | ||
| model = self.get_unet_model(model_id="stabilityai/stable-diffusion-2", fp16=True) | ||
|
Contributor
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. Thanks a lot for adding this! |
||
| latents = self.get_latents(seed, shape=(4, 4, 96, 96), fp16=True) | ||
| encoder_hidden_states = self.get_encoder_hidden_states(seed, shape=(4, 77, 1024), fp16=True) | ||
|
|
||
| with torch.no_grad(): | ||
| sample = model(latents, timestep=timestep, encoder_hidden_states=encoder_hidden_states).sample | ||
|
|
||
| assert sample.shape == latents.shape | ||
|
|
||
| output_slice = sample[-1, -2:, -2:, :2].flatten().float().cpu() | ||
| expected_output_slice = torch.tensor(expected_slice) | ||
|
|
||
| assert torch_all_close(output_slice, expected_output_slice, atol=5e-3) | ||
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.