MCPcopy Create free account
hub / github.com/VisionXLab/OF-Diff / __init__

Method __init__

ldm/modules/attention.py:146–161  ·  view source on GitHub ↗
(self, query_dim, context_dim=None, heads=8, dim_head=64, dropout=0.)

Source from the content-addressed store, hash-verified

144
145class CrossAttention(nn.Module):
146 def __init__(self, query_dim, context_dim=None, heads=8, dim_head=64, dropout=0.):
147 super().__init__()
148 inner_dim = dim_head * heads
149 context_dim = default(context_dim, query_dim)
150
151 self.scale = dim_head ** -0.5
152 self.heads = heads
153
154 self.to_q = nn.Linear(query_dim, inner_dim, bias=False)
155 self.to_k = nn.Linear(context_dim, inner_dim, bias=False)
156 self.to_v = nn.Linear(context_dim, inner_dim, bias=False)
157
158 self.to_out = nn.Sequential(
159 nn.Linear(inner_dim, query_dim),
160 nn.Dropout(dropout)
161 )
162
163 def forward(self, x, context=None, mask=None):
164 h = self.heads

Callers

nothing calls this directly

Calls 2

defaultFunction · 0.70
__init__Method · 0.45

Tested by

no test coverage detected