-
Notifications
You must be signed in to change notification settings - Fork 6.2k
[wan2.2] follow-up #12024
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
Open
yiyixuxu
wants to merge
14
commits into
main
Choose a base branch
from
wan22-followup
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+897
−74
Open
[wan2.2] follow-up #12024
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
cdcac4a
up
yiyixuxu 5c995d9
up
yiyixuxu dd1328d
Merge branch 'main' into wan22-followup
yiyixuxu 2fd1e25
make it work with batch_sie >1
yiyixuxu 5e17dde
add tests
yiyixuxu 67347f6
Merge branch 'wan22-followup' of github.com:huggingface/diffusers int…
yiyixuxu a7bce5f
tests
yiyixuxu 1189a35
add more tests
yiyixuxu d710e59
style
yiyixuxu bc7a833
up
yiyixuxu 359bc7b
jpdate test after fixing 5b patchify
yiyixuxu c82d4fa
Update tests/pipelines/wan/test_wan_22.py
yiyixuxu 7a66c4c
up
yiyixuxu 04fa6f4
Merge branch 'main' into wan22-followup
yiyixuxu 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 |
---|---|---|
|
@@ -13,8 +13,10 @@ | |
# limitations under the License. | ||
|
||
import gc | ||
import tempfile | ||
import unittest | ||
|
||
import numpy as np | ||
import torch | ||
from transformers import AutoTokenizer, T5EncoderModel | ||
|
||
|
@@ -85,29 +87,13 @@ def get_dummy_components(self): | |
rope_max_seq_len=32, | ||
) | ||
|
||
torch.manual_seed(0) | ||
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. revert the change in #12004 |
||
transformer_2 = WanTransformer3DModel( | ||
patch_size=(1, 2, 2), | ||
num_attention_heads=2, | ||
attention_head_dim=12, | ||
in_channels=16, | ||
out_channels=16, | ||
text_dim=32, | ||
freq_dim=256, | ||
ffn_dim=32, | ||
num_layers=2, | ||
cross_attn_norm=True, | ||
qk_norm="rms_norm_across_heads", | ||
rope_max_seq_len=32, | ||
) | ||
|
||
components = { | ||
"transformer": transformer, | ||
"vae": vae, | ||
"scheduler": scheduler, | ||
"text_encoder": text_encoder, | ||
"tokenizer": tokenizer, | ||
"transformer_2": transformer_2, | ||
"transformer_2": None, | ||
} | ||
return components | ||
|
||
|
@@ -155,6 +141,45 @@ def test_inference(self): | |
def test_attention_slicing_forward_pass(self): | ||
pass | ||
|
||
# _optional_components include transformer, transformer_2, but only transformer_2 is optional for this wan2.1 t2v pipeline | ||
def test_save_load_optional_components(self, expected_max_difference=1e-4): | ||
optional_component = "transformer_2" | ||
|
||
components = self.get_dummy_components() | ||
components[optional_component] = None | ||
pipe = self.pipeline_class(**components) | ||
for component in pipe.components.values(): | ||
if hasattr(component, "set_default_attn_processor"): | ||
component.set_default_attn_processor() | ||
pipe.to(torch_device) | ||
pipe.set_progress_bar_config(disable=None) | ||
|
||
generator_device = "cpu" | ||
inputs = self.get_dummy_inputs(generator_device) | ||
torch.manual_seed(0) | ||
output = pipe(**inputs)[0] | ||
|
||
with tempfile.TemporaryDirectory() as tmpdir: | ||
pipe.save_pretrained(tmpdir, safe_serialization=False) | ||
pipe_loaded = self.pipeline_class.from_pretrained(tmpdir) | ||
for component in pipe_loaded.components.values(): | ||
if hasattr(component, "set_default_attn_processor"): | ||
component.set_default_attn_processor() | ||
pipe_loaded.to(torch_device) | ||
pipe_loaded.set_progress_bar_config(disable=None) | ||
|
||
self.assertTrue( | ||
getattr(pipe_loaded, optional_component) is None, | ||
f"`{optional_component}` did not stay set to None after loading.", | ||
) | ||
|
||
inputs = self.get_dummy_inputs(generator_device) | ||
torch.manual_seed(0) | ||
output_loaded = pipe_loaded(**inputs)[0] | ||
|
||
max_diff = np.abs(output.detach().cpu().numpy() - output_loaded.detach().cpu().numpy()).max() | ||
self.assertLess(max_diff, expected_max_difference) | ||
|
||
|
||
@slow | ||
@require_torch_accelerator | ||
|
Oops, something went wrong.
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.
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.
so that it works with batch_size > 1