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

Method build

src/framework/modules/attention/transformer_blocks.cpp:24–49  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

22}
23
24core::TensorValue TransformerEncoderBlockModule::build(
25 core::ModuleBuildContext & ctx,
26 const core::TensorValue & input,
27 const TransformerEncoderBlockWeights & weights) const {
28 validate_sequence_input(input, config_.hidden_size, "input");
29
30 const LayerNormModule norm1(make_norm_config(config_.hidden_size, config_.eps));
31 const SelfAttentionModule self_attention({config_.hidden_size, config_.num_heads, config_.use_bias});
32 const LayerNormModule norm2(make_norm_config(config_.hidden_size, config_.eps));
33 const FeedForwardModule feed_forward(
34 {config_.hidden_size, config_.intermediate_size, config_.use_bias, GeluApproximation::ExactErf});
35 const ResidualAddModule add;
36
37 auto cur = norm1.build(ctx, input, weights.norm1);
38 cur = self_attention.build(ctx, cur, weights.self_attention);
39 if (weights.layer_scale1.has_value()) {
40 cur = LayerScaleModule().build(ctx, cur, *weights.layer_scale1);
41 }
42 cur = add.build(ctx, input, cur);
43 auto ff_in = norm2.build(ctx, cur, weights.norm2);
44 auto ff_out = feed_forward.build(ctx, ff_in, weights.feed_forward);
45 if (weights.layer_scale2.has_value()) {
46 ff_out = LayerScaleModule().build(ctx, ff_out, *weights.layer_scale2);
47 }
48 return add.build(ctx, cur, ff_out);
49}
50
51const core::ModuleSchema & TransformerEncoderBlockModule::static_schema() noexcept {
52 return kTransformerEncoderBlockSchema;

Callers

nothing calls this directly

Calls 12

make_norm_configFunction · 0.85
LayerScaleModuleClass · 0.85
validate_rank_betweenFunction · 0.85
ensure_contiguous_layoutFunction · 0.85
LinearModuleClass · 0.85
validate_sequence_inputFunction · 0.70
permute_tensorFunction · 0.70
sizeMethod · 0.45

Tested by

no test coverage detected