MCPcopy Create free account
hub / github.com/aigc3d/LHM / __init__

Method __init__

LHM/models/block.py:95–114  ·  view source on GitHub ↗
(self, inner_dim: int, cond_dim: int, mod_dim: int, num_heads: int, eps: float,
                 attn_drop: float = 0., attn_bias: bool = False,
                 mlp_ratio: float = 4., mlp_drop: float = 0.)

Source from the content-addressed store, hash-verified

93 """
94 # Block contains a cross-attention layer, a self-attention layer, and an MLP
95 def __init__(self, inner_dim: int, cond_dim: int, mod_dim: int, num_heads: int, eps: float,
96 attn_drop: float = 0., attn_bias: bool = False,
97 mlp_ratio: float = 4., mlp_drop: float = 0.):
98 super().__init__()
99 self.norm1 = ModLN(inner_dim, mod_dim, eps)
100 self.cross_attn = nn.MultiheadAttention(
101 embed_dim=inner_dim, num_heads=num_heads, kdim=cond_dim, vdim=cond_dim,
102 dropout=attn_drop, bias=attn_bias, batch_first=True)
103 self.norm2 = ModLN(inner_dim, mod_dim, eps)
104 self.self_attn = nn.MultiheadAttention(
105 embed_dim=inner_dim, num_heads=num_heads,
106 dropout=attn_drop, bias=attn_bias, batch_first=True)
107 self.norm3 = ModLN(inner_dim, mod_dim, eps)
108 self.mlp = nn.Sequential(
109 nn.Linear(inner_dim, int(inner_dim * mlp_ratio)),
110 nn.GELU(),
111 nn.Dropout(mlp_drop),
112 nn.Linear(int(inner_dim * mlp_ratio), inner_dim),
113 nn.Dropout(mlp_drop),
114 )
115
116 def forward(self, x, cond, mod):
117 # x: [N, L, D]

Callers

nothing calls this directly

Calls 2

ModLNClass · 0.85
__init__Method · 0.45

Tested by

no test coverage detected