-
Couldn't load subscription status.
- Fork 6.5k
Hidream refactoring follow ups #11299
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 27 commits
Commits
Show all changes
29 commits
Select commit
Hold shift + click to select a range
642203e
HiDream Image
hlky 3b5e03b
update
hlky a40c95f
-einops
hlky eb798ed
Merge branch 'main' into hidream
hlky a90372e
py3.8
hlky f94d68e
Merge branch 'hidream' of https://github.com/hlky/diffusers into hidream
hlky b8aa38d
fix -einops
hlky 9d43a32
mixins, offload_seq, option_components
hlky e1766a1
docs
hlky 8fbc630
Apply style fixes
github-actions[bot] b6b9b45
trigger tests
hlky 8dd065b
Apply suggestions from code review
hlky 8b2670d
joint_attention_kwargs -> attention_kwargs, fixes
hlky f2aa727
fast tests
hlky 8e328f3
-_init_weights
hlky 7c4eced
style tests
hlky 07c670e
move reshape logic
hlky efc44ea
update slice 😴
hlky 745bcec
supports_dduf
hlky c1abec6
🤷🏻♂️
hlky 9eb0b8b
Update src/diffusers/models/transformers/transformer_hidream_image.py
hlky 32af5ce
address review comments
a-r-r-o-w 3ec1896
update tests
a-r-r-o-w 2d65aa2
doc updates
a-r-r-o-w 72c9667
Merge branch 'main' into hidream
a-r-r-o-w 5e0bca0
update
a-r-r-o-w 3044fe0
Merge branch 'main' into refactor/hidream
a-r-r-o-w a68c103
Update src/diffusers/models/transformers/transformer_hidream_image.py
a-r-r-o-w 13a9016
Apply style fixes
github-actions[bot] 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -604,8 +604,7 @@ def __init__( | |
| ): | ||
| super().__init__() | ||
| self.out_channels = out_channels or in_channels | ||
| self.inner_dim = self.config.num_attention_heads * self.config.attention_head_dim | ||
| self.llama_layers = llama_layers | ||
| self.inner_dim = num_attention_heads * attention_head_dim | ||
|
|
||
| self.t_embedder = HiDreamImageTimestepEmbed(self.inner_dim) | ||
| self.p_embedder = HiDreamImagePooledEmbed(text_emb_dim, self.inner_dim) | ||
|
|
@@ -621,13 +620,13 @@ def __init__( | |
| HiDreamBlock( | ||
| HiDreamImageTransformerBlock( | ||
| dim=self.inner_dim, | ||
| num_attention_heads=self.config.num_attention_heads, | ||
| attention_head_dim=self.config.attention_head_dim, | ||
| num_attention_heads=num_attention_heads, | ||
| attention_head_dim=attention_head_dim, | ||
| num_routed_experts=num_routed_experts, | ||
| num_activated_experts=num_activated_experts, | ||
| ) | ||
| ) | ||
| for _ in range(self.config.num_layers) | ||
| for _ in range(num_layers) | ||
| ] | ||
| ) | ||
|
|
||
|
|
@@ -636,43 +635,25 @@ def __init__( | |
| HiDreamBlock( | ||
| HiDreamImageSingleTransformerBlock( | ||
| dim=self.inner_dim, | ||
| num_attention_heads=self.config.num_attention_heads, | ||
| attention_head_dim=self.config.attention_head_dim, | ||
| num_attention_heads=num_attention_heads, | ||
| attention_head_dim=attention_head_dim, | ||
| num_routed_experts=num_routed_experts, | ||
| num_activated_experts=num_activated_experts, | ||
| ) | ||
| ) | ||
| for _ in range(self.config.num_single_layers) | ||
| for _ in range(num_single_layers) | ||
| ] | ||
| ) | ||
|
|
||
| self.final_layer = HiDreamImageOutEmbed(self.inner_dim, patch_size, self.out_channels) | ||
|
|
||
| caption_channels = [ | ||
| caption_channels[1], | ||
| ] * (num_layers + num_single_layers) + [ | ||
| caption_channels[0], | ||
| ] | ||
| caption_channels = [caption_channels[1]] * (num_layers + num_single_layers) + [caption_channels[0]] | ||
| caption_projection = [] | ||
| for caption_channel in caption_channels: | ||
| caption_projection.append(TextProjection(in_features=caption_channel, hidden_size=self.inner_dim)) | ||
| self.caption_projection = nn.ModuleList(caption_projection) | ||
| self.max_seq = max_resolution[0] * max_resolution[1] // (patch_size * patch_size) | ||
|
|
||
| def expand_timesteps(self, timesteps, batch_size, device): | ||
|
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. This is not needed because:
|
||
| if not torch.is_tensor(timesteps): | ||
| is_mps = device.type == "mps" | ||
| if isinstance(timesteps, float): | ||
| dtype = torch.float32 if is_mps else torch.float64 | ||
| else: | ||
| dtype = torch.int32 if is_mps else torch.int64 | ||
| timesteps = torch.tensor([timesteps], dtype=dtype, device=device) | ||
| elif len(timesteps.shape) == 0: | ||
| timesteps = timesteps[None].to(device) | ||
| # broadcast to batch dimension in a way that's compatible with ONNX/Core ML | ||
| timesteps = timesteps.expand(batch_size) | ||
| return timesteps | ||
|
|
||
| def unpatchify(self, x: torch.Tensor, img_sizes: List[Tuple[int, int]], is_training: bool) -> List[torch.Tensor]: | ||
| if is_training: | ||
| B, S, F = x.shape | ||
|
|
@@ -773,7 +754,6 @@ def forward( | |
| hidden_states = out | ||
|
|
||
| # 0. time | ||
| timesteps = self.expand_timesteps(timesteps, batch_size, hidden_states.device) | ||
| timesteps = self.t_embedder(timesteps, hidden_states_type) | ||
| p_embedder = self.p_embedder(pooled_embeds) | ||
| temb = timesteps + p_embedder | ||
|
|
@@ -793,7 +773,7 @@ def forward( | |
|
|
||
| T5_encoder_hidden_states = encoder_hidden_states[0] | ||
| encoder_hidden_states = encoder_hidden_states[-1] | ||
| encoder_hidden_states = [encoder_hidden_states[k] for k in self.llama_layers] | ||
| encoder_hidden_states = [encoder_hidden_states[k] for k in self.config.llama_layers] | ||
|
|
||
| if self.caption_projection is not None: | ||
| new_encoder_hidden_states = [] | ||
|
|
||
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.