MCPcopy Create free account
hub / github.com/YesianRohn/TextSSR / PixArtAlphaTextProjection

Class PixArtAlphaTextProjection

diffusers/src/diffusers/models/embeddings.py:1497–1523  ·  view source on GitHub ↗

Projects caption embeddings. Also handles dropout for classifier-free guidance. Adapted from https://github.com/PixArt-alpha/PixArt-alpha/blob/master/diffusion/model/nets/PixArt_blocks.py

Source from the content-addressed store, hash-verified

1495
1496
1497class PixArtAlphaTextProjection(nn.Module):
1498 """
1499 Projects caption embeddings. Also handles dropout for classifier-free guidance.
1500
1501 Adapted from https://github.com/PixArt-alpha/PixArt-alpha/blob/master/diffusion/model/nets/PixArt_blocks.py
1502 """
1503
1504 def __init__(self, in_features, hidden_size, out_features=None, act_fn="gelu_tanh"):
1505 super().__init__()
1506 if out_features is None:
1507 out_features = hidden_size
1508 self.linear_1 = nn.Linear(in_features=in_features, out_features=hidden_size, bias=True)
1509 if act_fn == "gelu_tanh":
1510 self.act_1 = nn.GELU(approximate="tanh")
1511 elif act_fn == "silu":
1512 self.act_1 = nn.SiLU()
1513 elif act_fn == "silu_fp32":
1514 self.act_1 = FP32SiLU()
1515 else:
1516 raise ValueError(f"Unknown activation function: {act_fn}")
1517 self.linear_2 = nn.Linear(in_features=hidden_size, out_features=out_features, bias=True)
1518
1519 def forward(self, caption):
1520 hidden_states = self.linear_1(caption)
1521 hidden_states = self.act_1(hidden_states)
1522 hidden_states = self.linear_2(hidden_states)
1523 return hidden_states
1524
1525
1526class IPAdapterPlusImageProjectionBlock(nn.Module):

Callers 8

__init__Method · 0.85
__init__Method · 0.85
__init__Method · 0.85
__init__Method · 0.85
__init__Method · 0.85
_init_patched_inputsMethod · 0.85
__init__Method · 0.85
__init__Method · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected