MCPcopy Create free account
hub / github.com/OpenImagingLab/FlashVSR / forward

Method forward

diffsynth/models/sd3_dit.py:134–152  ·  view source on GitHub ↗
(self, hidden_states_a, hidden_states_b)

Source from the content-addressed store, hash-verified

132
133
134 def forward(self, hidden_states_a, hidden_states_b):
135 batch_size = hidden_states_a.shape[0]
136
137 qa, ka, va = self.process_qkv(hidden_states_a, self.a_to_qkv, self.norm_q_a, self.norm_k_a)
138 qb, kb, vb = self.process_qkv(hidden_states_b, self.b_to_qkv, self.norm_q_b, self.norm_k_b)
139 q = torch.concat([qa, qb], dim=2)
140 k = torch.concat([ka, kb], dim=2)
141 v = torch.concat([va, vb], dim=2)
142
143 hidden_states = torch.nn.functional.scaled_dot_product_attention(q, k, v)
144 hidden_states = hidden_states.transpose(1, 2).reshape(batch_size, -1, self.num_heads * self.head_dim)
145 hidden_states = hidden_states.to(q.dtype)
146 hidden_states_a, hidden_states_b = hidden_states[:, :hidden_states_a.shape[1]], hidden_states[:, hidden_states_a.shape[1]:]
147 hidden_states_a = self.a_to_out(hidden_states_a)
148 if self.only_out_a:
149 return hidden_states_a
150 else:
151 hidden_states_b = self.b_to_out(hidden_states_b)
152 return hidden_states_a, hidden_states_b
153
154
155

Callers

nothing calls this directly

Calls 2

process_qkvMethod · 0.95
toMethod · 0.45

Tested by

no test coverage detected