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

Function flow_attention

src/models/heartmula/codec.cpp:795–832  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

793 GGML_TYPE_F32);
794 context = core::reshape_tensor(ctx, core::ensure_backend_addressable_layout(ctx, context), core::TensorShape::from_dims({batch, frames, hidden_size}));
795 return modules::LinearModule({hidden_size, hidden_size, false, GGML_PREC_F32}).build(ctx, context, weights.o_proj);
796}
797
798core::TensorValue flow_mlp(
799 core::ModuleBuildContext & ctx,
800 const core::TensorValue & input,
801 const HeartCodecTransformerBlockWeights & weights,
802 int64_t hidden_size) {
803 const int64_t mlp_hidden_size = weights.mlp_gate.weight.shape.dims[0];
804 auto gate = modules::LinearModule({hidden_size, mlp_hidden_size, false, GGML_PREC_F32}).build(ctx, input, weights.mlp_gate);
805 gate = modules::SiluModule{}.build(ctx, gate);
806 auto up = modules::LinearModule({hidden_size, mlp_hidden_size, false, GGML_PREC_F32}).build(ctx, input, weights.mlp_up);
807 auto hidden = modules::MulModule{}.build(ctx, gate, up);
808 return modules::LinearModule({mlp_hidden_size, hidden_size, false, GGML_PREC_F32}).build(ctx, hidden, weights.mlp_down);
809}
810
811core::TensorValue flow_transformer_block(
812 core::ModuleBuildContext & ctx,
813 const core::TensorValue & input,
814 const core::TensorValue & timestep_mod,
815 const core::TensorValue & positions,
816 const HeartCodecTransformerBlockWeights & weights,
817 int64_t heads,
818 int64_t head_dim) {
819 const int64_t hidden_size = heads * head_dim;
820 const int64_t frames = input.shape.dims[1];
821 const auto parts = adaptive_block_parts(ctx, timestep_mod, weights.scale_shift_table, frames, hidden_size);
822
823 auto normed = modules::RMSNormModule({hidden_size, 1.0e-6F, true, false}).build(ctx, input, weights.attn_norm);
824 normed = modules::AddModule{}.build(
825 ctx,
826 modules::MulModule{}.build(ctx, normed, add_one(ctx, parts.scale_msa)),
827 parts.shift_msa);
828 auto attn = flow_attention(ctx, normed, positions, weights, heads, head_dim);
829 auto x = modules::AddModule{}.build(ctx, input, modules::MulModule{}.build(ctx, parts.gate_msa, attn));
830
831 normed = modules::RMSNormModule({hidden_size, 1.0e-6F, true, false}).build(ctx, x, weights.mlp_norm);
832 normed = modules::AddModule{}.build(
833 ctx,
834 modules::MulModule{}.build(ctx, normed, add_one(ctx, parts.scale_mlp)),
835 parts.shift_mlp);

Callers 1

flow_transformer_blockFunction · 0.85

Calls 9

LinearModuleClass · 0.85
reshape_tensorFunction · 0.85
RoPEModuleClass · 0.85
TransposeModuleClass · 0.85
ggml_flash_attn_extFunction · 0.85
wrap_tensorFunction · 0.85
buildMethod · 0.45

Tested by

no test coverage detected