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

Function build_vibevoice_decoder_layer

src/models/vibevoice/decoder.cpp:1769–1861  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1767 required_capacity,
1768 1024ull * 1024ull * 1024ull));
1769 graph = cached_batch_graphs_.back().get();
1770 graph->import_states(states);
1771 }
1772 return graph->run_step(embeddings);
1773}
1774
1775VibeVoiceDecoderLayerOutputs build_vibevoice_decoder_layer(
1776 core::ModuleBuildContext & ctx,
1777 const core::TensorValue & input,
1778 const core::TensorValue & positions,
1779 const VibeVoiceDecoderLayerWeights & weights,
1780 const VibeVoiceDecoderConfig & config,
1781 core::ConstantTensorCache & constants,
1782 const std::optional<core::TensorValue> & prefix_key,
1783 const std::optional<core::TensorValue> & prefix_value,
1784 const std::optional<core::TensorValue> & attention_mask) {
1785 if (prefix_key.has_value() != prefix_value.has_value()) {
1786 throw std::runtime_error("VibeVoice decoder layer requires both prefix key and value or neither");
1787 }
1788 const int64_t dim = require_head_dim(config);
1789 const int64_t kv_repeats = config.num_attention_heads / config.num_key_value_heads;
1790 const modules::LinearModule q_proj(
1791 binding::linear_config(config.hidden_size, config.num_attention_heads * dim, true));
1792 const modules::LinearModule k_proj(
1793 binding::linear_config(config.hidden_size, config.num_key_value_heads * dim, true));
1794 const modules::LinearModule v_proj(
1795 binding::linear_config(config.hidden_size, config.num_key_value_heads * dim, true));
1796 const modules::LinearModule o_proj(
1797 binding::linear_config(config.num_attention_heads * dim, config.hidden_size, false));
1798 const modules::RMSNormModule hidden_norm({config.hidden_size, config.rms_norm_eps, true, false});
1799 const modules::AddModule add;
1800
1801 auto attn_in = hidden_norm.build(ctx, input, binding::norm_data(constants, weights.input_norm));
1802 auto q = q_proj.build(
1803 ctx,
1804 attn_in,
1805 binding::linear_data(constants, weights.self_attention.q_weight, weights.self_attention.q_bias));
1806 auto k = k_proj.build(
1807 ctx,
1808 attn_in,
1809 binding::linear_data(constants, weights.self_attention.k_weight, weights.self_attention.k_bias));
1810 auto v = v_proj.build(
1811 ctx,
1812 attn_in,
1813 binding::linear_data(constants, weights.self_attention.v_weight, weights.self_attention.v_bias));
1814 q = reshape_heads(ctx, q, config.num_attention_heads, dim);
1815 k = reshape_heads(ctx, k, config.num_key_value_heads, dim);
1816 v = reshape_heads(ctx, v, config.num_key_value_heads, dim);
1817 q = modules::RoPEModule({dim, GGML_ROPE_TYPE_NEOX, config.rope_theta}).build(ctx, q, positions);
1818 k = modules::RoPEModule({dim, GGML_ROPE_TYPE_NEOX, config.rope_theta}).build(ctx, k, positions);
1819 k = core::ensure_backend_addressable_layout(ctx, k);
1820 v = core::ensure_backend_addressable_layout(ctx, v);
1821
1822 auto q_heads = modules::TransposeModule({{0, 2, 1, 3}, q.shape.rank}).build(ctx, q);
1823 auto all_k = prefix_key.has_value() ? modules::ConcatModule({1}).build(ctx, *prefix_key, k) : k;
1824 auto all_v = prefix_value.has_value() ? modules::ConcatModule({1}).build(ctx, *prefix_value, v) : v;
1825 core::TensorValue context;
1826 if (!prefix_key.has_value() && attention_mask.has_value()) {

Callers 2

LayerGraphMethod · 0.85

Calls 15

linear_configFunction · 0.85
norm_dataFunction · 0.85
linear_dataFunction · 0.85
RoPEModuleClass · 0.85
TransposeModuleClass · 0.85
ConcatModuleClass · 0.85
wrap_tensorFunction · 0.85
ggml_contFunction · 0.85
reshape_tensorFunction · 0.85
LinearModuleClass · 0.85

Tested by

no test coverage detected