| 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); |
no test coverage detected