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

Function repeat_kv_heads

src/models/vibevoice/decoder.cpp:75–95  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

73}
74
75core::TensorValue repeat_kv_heads(core::ModuleBuildContext & ctx, const core::TensorValue & input, int64_t repeats) {
76 if (repeats == 1) {
77 return input;
78 }
79 const auto contiguous = core::ensure_backend_addressable_layout(ctx, input);
80 const int64_t batch = contiguous.shape.dims[0];
81 const int64_t kv_heads = contiguous.shape.dims[1];
82 const int64_t steps = contiguous.shape.dims[2];
83 const int64_t dim = contiguous.shape.dims[3];
84 auto expanded = core::reshape_tensor(
85 ctx,
86 contiguous,
87 core::TensorShape::from_dims({batch, kv_heads, 1, steps * dim}));
88 expanded = modules::RepeatModule({core::TensorShape::from_dims({batch, kv_heads, repeats, steps * dim})})
89 .build(ctx, expanded);
90 expanded = core::ensure_backend_addressable_layout(ctx, expanded);
91 return core::reshape_tensor(
92 ctx,
93 expanded,
94 core::TensorShape::from_dims({batch, kv_heads * repeats, steps, dim}));
95}
96
97core::TensorValue attention_from_heads(
98 core::ModuleBuildContext & ctx,

Calls 4

reshape_tensorFunction · 0.85
RepeatModuleClass · 0.85
buildMethod · 0.45

Tested by

no test coverage detected