Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 7.3k
[LoRA] Support LTX Video#10228
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
Uh oh!
There was an error while loading. Please reload this page.
Merged
[LoRA] Support LTX Video #10228
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
7d96d94
add lora support for ltx
a-r-r-o-w 598596a
Merge branch 'main' into ltx-lora-support
sayakpaul 307b797
Merge branch 'main' into ltx-lora-support
a-r-r-o-w 6809572
add tests
a-r-r-o-w 7c6e385
fix copied from comments
a-r-r-o-w 5b0e7aa
update
a-r-r-o-w 3583908
Merge branch 'main' into ltx-lora-support
sayakpaul File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading. Please reload this page.
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 |
|---|---|---|
| @@ -21,8 +21,8 @@ | ||
| import torch.nn.functional as F | ||
| from ...configuration_utils import ConfigMixin, register_to_config | ||
| from ...loaders import FromOriginalModelMixin | ||
| from ...utils import is_torch_version, logging | ||
| from ...loaders import FromOriginalModelMixin, PeftAdapterMixin | ||
| from ...utils import USE_PEFT_BACKEND, is_torch_version, logging, scale_lora_layers, unscale_lora_layers | ||
| from ...utils.torch_utils import maybe_allow_in_graph | ||
| from ..attention import FeedForward | ||
| from ..attention_processor import Attention | ||
| @@ -267,7 +267,7 @@ def forward( | ||
| @maybe_allow_in_graph | ||
| class LTXVideoTransformer3DModel(ModelMixin, ConfigMixin, FromOriginalModelMixin): | ||
| class LTXVideoTransformer3DModel(ModelMixin, ConfigMixin, FromOriginalModelMixin, PeftAdapterMixin): | ||
| r""" | ||
| A Transformer model for video-like data used in [LTX](https://huggingface.co/Lightricks/LTX-Video). | ||
| @@ -374,8 +374,24 @@ def forward( | ||
| height: int, | ||
| width: int, | ||
| rope_interpolation_scale: Optional[Tuple[float, float, float]] = None, | ||
| attention_kwargs: Optional[Dict[str, Any]] = None, | ||
a-r-r-o-w marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| return_dict: bool = True, | ||
| ) -> torch.Tensor: | ||
| if attention_kwargs is not None: | ||
| attention_kwargs = attention_kwargs.copy() | ||
| lora_scale = attention_kwargs.pop("scale", 1.0) | ||
| else: | ||
| lora_scale = 1.0 | ||
| if USE_PEFT_BACKEND: | ||
| # weight the lora layers by setting `lora_scale` for each PEFT layer | ||
| scale_lora_layers(self, lora_scale) | ||
| else: | ||
| if attention_kwargs is not None and attention_kwargs.get("scale", None) is not None: | ||
| logger.warning( | ||
| "Passing `scale` via `attention_kwargs` when not using the PEFT backend is ineffective." | ||
| ) | ||
| image_rotary_emb = self.rope(hidden_states, num_frames, height, width, rope_interpolation_scale) | ||
| # convert encoder_attention_mask to a bias the same way we do for attention_mask | ||
| @@ -436,6 +452,10 @@ def custom_forward(*inputs): | ||
| hidden_states = hidden_states * (1 + scale) + shift | ||
| output = self.proj_out(hidden_states) | ||
| if USE_PEFT_BACKEND: | ||
| # remove `lora_scale` from each PEFT layer | ||
| unscale_lora_layers(self, lora_scale) | ||
| if not return_dict: | ||
| return (output,) | ||
| return Transformer2DModelOutput(sample=output) | ||
Oops, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
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.