-
Notifications
You must be signed in to change notification settings - Fork 6.6k
Add support for Magcache #12744
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
AlanPonnachan
wants to merge
11
commits into
huggingface:main
Choose a base branch
from
AlanPonnachan:feat/mag-cache
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.
+746
−2
Open
Add support for Magcache #12744
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
8dbb673
add magcache
AlanPonnachan a8a57c6
formatting
AlanPonnachan cbf4b5e
Merge branch 'main' into feat/mag-cache
AlanPonnachan a6a9fb4
add magcache support with calibration mode
AlanPonnachan bb0a069
Merge branch 'main' into feat/mag-cache
AlanPonnachan 37f8826
add imports
AlanPonnachan 0a05bec
improvements
AlanPonnachan 535a14e
Merge branch 'main' into feat/mag-cache
AlanPonnachan ebbebbe
Apply style fixes
github-actions[bot] 00e9b96
fix kandinsky errors
AlanPonnachan 3603e6c
Merge branch 'main' into feat/mag-cache
AlanPonnachan 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -23,7 +23,13 @@ | |
| _ATTENTION_CLASSES = (Attention, MochiAttention, AttentionModuleMixin) | ||
| _FEEDFORWARD_CLASSES = (FeedForward, LuminaFeedForward) | ||
|
|
||
| _SPATIAL_TRANSFORMER_BLOCK_IDENTIFIERS = ("blocks", "transformer_blocks", "single_transformer_blocks", "layers") | ||
| _SPATIAL_TRANSFORMER_BLOCK_IDENTIFIERS = ( | ||
| "blocks", | ||
| "transformer_blocks", | ||
| "single_transformer_blocks", | ||
| "layers", | ||
|
Member
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. For ZImage I am guessing? |
||
| "visual_transformer_blocks", | ||
| ) | ||
| _TEMPORAL_TRANSFORMER_BLOCK_IDENTIFIERS = ("temporal_transformer_blocks",) | ||
| _CROSS_TRANSFORMER_BLOCK_IDENTIFIERS = ("blocks", "transformer_blocks", "layers") | ||
|
|
||
|
|
||
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 |
|---|---|---|
|
|
@@ -26,6 +26,7 @@ class AttentionProcessorMetadata: | |
| class TransformerBlockMetadata: | ||
| return_hidden_states_index: int = None | ||
| return_encoder_hidden_states_index: int = None | ||
| hidden_states_argument_name: str = "hidden_states" | ||
|
|
||
| _cls: Type = None | ||
| _cached_parameter_indices: Dict[str, int] = None | ||
|
|
@@ -169,7 +170,7 @@ def _register_attention_processors_metadata(): | |
|
|
||
|
|
||
| def _register_transformer_blocks_metadata(): | ||
| from ..models.attention import BasicTransformerBlock | ||
| from ..models.attention import BasicTransformerBlock, JointTransformerBlock | ||
| from ..models.transformers.cogvideox_transformer_3d import CogVideoXBlock | ||
| from ..models.transformers.transformer_bria import BriaTransformerBlock | ||
| from ..models.transformers.transformer_cogview4 import CogView4TransformerBlock | ||
|
|
@@ -184,6 +185,7 @@ def _register_transformer_blocks_metadata(): | |
| HunyuanImageSingleTransformerBlock, | ||
| HunyuanImageTransformerBlock, | ||
| ) | ||
| from ..models.transformers.transformer_kandinsky import Kandinsky5TransformerDecoderBlock | ||
| from ..models.transformers.transformer_ltx import LTXVideoTransformerBlock | ||
| from ..models.transformers.transformer_mochi import MochiTransformerBlock | ||
| from ..models.transformers.transformer_qwenimage import QwenImageTransformerBlock | ||
|
|
@@ -331,6 +333,24 @@ def _register_transformer_blocks_metadata(): | |
| ), | ||
| ) | ||
|
|
||
| TransformerBlockRegistry.register( | ||
| model_class=JointTransformerBlock, | ||
| metadata=TransformerBlockMetadata( | ||
| return_hidden_states_index=1, | ||
| return_encoder_hidden_states_index=0, | ||
| ), | ||
| ) | ||
|
Comment on lines
+336
to
+342
Member
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. For SD3 I am guessing? |
||
|
|
||
| # Kandinsky 5.0 (Kandinsky5TransformerDecoderBlock) | ||
| TransformerBlockRegistry.register( | ||
| model_class=Kandinsky5TransformerDecoderBlock, | ||
| metadata=TransformerBlockMetadata( | ||
| return_hidden_states_index=0, | ||
| return_encoder_hidden_states_index=None, | ||
| hidden_states_argument_name="visual_embed", | ||
| ), | ||
| ) | ||
|
|
||
|
|
||
| # fmt: off | ||
| def _skip_attention___ret___hidden_states(self, *args, **kwargs): | ||
|
|
||
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.
It's fine if we don't expose it this publicly. Since these are still a bit experimental in nature, I would prefer it to stay within the core MagCache implementation file.