MCPcopy Create free account
hub / github.com/0xShug0/audio.cpp / same_attention

Function same_attention

src/models/stable_audio/same_autoencoder.cpp:206–230  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

204}
205
206core::TensorValue same_attention(
207 core::ModuleBuildContext & ctx,
208 const core::TensorValue & q_heads,
209 const core::TensorValue & k_heads,
210 const core::TensorValue & v_heads,
211 const core::TensorValue * attention_mask,
212 int64_t dim) {
213 const auto q = ensure_contiguous(ctx, q_heads);
214 const auto k = ensure_contiguous(ctx, k_heads);
215 const auto v = ensure_contiguous(ctx, v_heads);
216 auto * flash = ggml_flash_attn_ext(
217 ctx.ggml,
218 q.tensor,
219 k.tensor,
220 v.tensor,
221 attention_mask != nullptr ? attention_mask->tensor : nullptr,
222 1.0F / std::sqrt(static_cast<float>(dim)),
223 0.0F,
224 0.0F);
225 ggml_flash_attn_ext_set_prec(flash, GGML_PREC_F32);
226 return core::wrap_tensor(
227 flash,
228 core::TensorShape::from_dims({q.shape.dims[0], q.shape.dims[2], q.shape.dims[1], dim}),
229 GGML_TYPE_F32);
230}
231
232core::TensorValue same_self_attention(
233 core::ModuleBuildContext & ctx,

Callers 1

same_self_attentionFunction · 0.85

Calls 4

ggml_flash_attn_extFunction · 0.85
wrap_tensorFunction · 0.85
ensure_contiguousFunction · 0.70

Tested by

no test coverage detected