MCPcopy Create free account
hub / github.com/UVA-Computer-Vision-Lab/FrameINO / PixArtAlphaTextProjection

Class PixArtAlphaTextProjection

architecture/embeddings.py:2247–2273  ·  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

2245
2246
2247class PixArtAlphaTextProjection(nn.Module):
2248 """
2249 Projects caption embeddings. Also handles dropout for classifier-free guidance.
2250
2251 Adapted from https://github.com/PixArt-alpha/PixArt-alpha/blob/master/diffusion/model/nets/PixArt_blocks.py
2252 """
2253
2254 def __init__(self, in_features, hidden_size, out_features=None, act_fn="gelu_tanh"):
2255 super().__init__()
2256 if out_features is None:
2257 out_features = hidden_size
2258 self.linear_1 = nn.Linear(in_features=in_features, out_features=hidden_size, bias=True)
2259 if act_fn == "gelu_tanh":
2260 self.act_1 = nn.GELU(approximate="tanh")
2261 elif act_fn == "silu":
2262 self.act_1 = nn.SiLU()
2263 elif act_fn == "silu_fp32":
2264 self.act_1 = FP32SiLU()
2265 else:
2266 raise ValueError(f"Unknown activation function: {act_fn}")
2267 self.linear_2 = nn.Linear(in_features=hidden_size, out_features=out_features, bias=True)
2268
2269 def forward(self, caption):
2270 hidden_states = self.linear_1(caption)
2271 hidden_states = self.act_1(hidden_states)
2272 hidden_states = self.linear_2(hidden_states)
2273 return hidden_states
2274
2275
2276class IPAdapterPlusImageProjectionBlock(nn.Module):

Callers 5

__init__Method · 0.90
__init__Method · 0.85
__init__Method · 0.85
__init__Method · 0.85
__init__Method · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected