Instructions to use BiliSakura/BitDance-Tokenizer-diffusers with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Diffusers
How to use BiliSakura/BitDance-Tokenizer-diffusers with Diffusers:
pip install -U diffusers transformers accelerate
import torch from diffusers import DiffusionPipeline from diffusers.utils import load_image # switch to "mps" for apple devices pipe = DiffusionPipeline.from_pretrained("BiliSakura/BitDance-Tokenizer-diffusers", dtype=torch.bfloat16, device_map="cuda") prompt = "Turn this cat into a dog" input_image = load_image("https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/diffusers/cat.png") image = pipe(image=input_image, prompt=prompt).images[0] - Notebooks
- Google Colab
- Kaggle
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
|