forked from ddPn08/Radiata
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
137 additions
and
28 deletions.
There are no files selected for viewing
This file contains 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 |
---|---|---|
@@ -0,0 +1,2 @@ | ||
* | ||
!.gitignore |
This file contains 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 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 |
---|---|---|
@@ -0,0 +1,50 @@ | ||
from losalina import hypernetwork | ||
|
||
loaded_networks = [] | ||
|
||
|
||
def apply_single_hypernetwork( | ||
hypernetwork: hypernetwork, hidden_states, encoder_hidden_states | ||
): | ||
context_k, context_v = hypernetwork.forward(hidden_states, encoder_hidden_states) | ||
return context_k, context_v | ||
|
||
|
||
def apply_hypernetworks(context_k, context_v, layer=None): | ||
if len(loaded_networks) == 0: | ||
return context_v, context_v | ||
for hypernetwork in loaded_networks: | ||
context_k, context_v = hypernetwork.forward(context_k, context_v) | ||
|
||
context_k = context_k.to(dtype=context_k.dtype) | ||
context_v = context_v.to(dtype=context_k.dtype) | ||
|
||
return context_k, context_v | ||
|
||
|
||
def apply_to(self: hypernetwork): | ||
loaded_networks.append(self) | ||
|
||
|
||
def restore(self: hypernetwork, *args): | ||
loaded_networks.clear() | ||
|
||
|
||
def hijack_hypernetwork(): | ||
hypernetwork.Hypernetwork.apply_to = apply_to | ||
hypernetwork.Hypernetwork.restore = restore | ||
|
||
import diffusers.models.attention_processor | ||
|
||
from . import attentions | ||
|
||
# replace the forward function of the attention processors for the hypernetworks | ||
diffusers.models.attention_processor.XFormersAttnProcessor.__call__ = ( | ||
attentions.xformers_forward | ||
) | ||
diffusers.models.attention_processor.SlicedAttnProcessor.__call__ = ( | ||
attentions.sliced_attn_forward | ||
) | ||
diffusers.models.attention_processor.AttnProcessor2_0.__call__ = ( | ||
attentions.v2_0_forward | ||
) |
This file contains 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 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 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 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 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 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 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 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