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

Function reshape_heads

src/models/roformer/runtime.cpp:233–242  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

231 const size_t rank = lhs.shape.rank;
232 for (size_t i = 0; i + 2 < rank; ++i) {
233 if (lhs.shape.dims[i] != rhs.shape.dims[i]) {
234 throw std::runtime_error("RoFormer matmul batch dimensions must match");
235 }
236 }
237 if (lhs.shape.dims[rank - 1] != rhs.shape.dims[rank - 2]) {
238 throw std::runtime_error("RoFormer matmul inner dimensions must match");
239 }
240
241 auto rhs_transposed = modules::TransposeModule({{0, 1, 3, 2}, rhs.shape.rank}).build(ctx, rhs);
242 rhs_transposed = ensure_contiguous(ctx, rhs_transposed);
243 core::TensorShape output_shape = lhs.shape;
244 output_shape.dims[rank - 1] = rhs.shape.dims[rank - 1];
245 ggml_tensor * output = ggml_mul_mat(ctx.ggml, rhs_transposed.tensor, lhs.tensor);

Callers 1

build_attentionFunction · 0.70

Calls 2

reshape_tensorFunction · 0.85
ensure_contiguousFunction · 0.70

Tested by

no test coverage detected