Update all files for BitDance-Tokenizer-diffusers
Browse files
bitdance_diffusers/modeling_projector.py
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from __future__ import annotations
|
| 2 |
+
|
| 3 |
+
import torch
|
| 4 |
+
from torch import nn
|
| 5 |
+
|
| 6 |
+
from diffusers.configuration_utils import ConfigMixin, register_to_config
|
| 7 |
+
from diffusers.models.modeling_utils import ModelMixin
|
| 8 |
+
from transformers.activations import ACT2FN
|
| 9 |
+
|
| 10 |
+
|
| 11 |
+
class BitDanceProjector(ModelMixin, ConfigMixin):
|
| 12 |
+
@register_to_config
|
| 13 |
+
def __init__(
|
| 14 |
+
self,
|
| 15 |
+
in_dim: int,
|
| 16 |
+
out_dim: int,
|
| 17 |
+
hidden_act: str = "gelu_pytorch_tanh",
|
| 18 |
+
) -> None:
|
| 19 |
+
super().__init__()
|
| 20 |
+
self.activation_fn = ACT2FN[hidden_act]
|
| 21 |
+
self.fc1 = nn.Linear(in_dim, out_dim)
|
| 22 |
+
self.fc2 = nn.Linear(out_dim, out_dim)
|
| 23 |
+
|
| 24 |
+
def forward(self, hidden_states: torch.Tensor) -> torch.Tensor:
|
| 25 |
+
hidden_states = hidden_states.to(self.fc1.weight.dtype)
|
| 26 |
+
hidden_states = self.fc1(hidden_states)
|
| 27 |
+
hidden_states = self.activation_fn(hidden_states)
|
| 28 |
+
hidden_states = self.fc2(hidden_states)
|
| 29 |
+
return hidden_states
|