| 204 | } |
| 205 | |
| 206 | core::TensorValue same_attention( |
| 207 | core::ModuleBuildContext & ctx, |
| 208 | const core::TensorValue & q_heads, |
| 209 | const core::TensorValue & k_heads, |
| 210 | const core::TensorValue & v_heads, |
| 211 | const core::TensorValue * attention_mask, |
| 212 | int64_t dim) { |
| 213 | const auto q = ensure_contiguous(ctx, q_heads); |
| 214 | const auto k = ensure_contiguous(ctx, k_heads); |
| 215 | const auto v = ensure_contiguous(ctx, v_heads); |
| 216 | auto * flash = ggml_flash_attn_ext( |
| 217 | ctx.ggml, |
| 218 | q.tensor, |
| 219 | k.tensor, |
| 220 | v.tensor, |
| 221 | attention_mask != nullptr ? attention_mask->tensor : nullptr, |
| 222 | 1.0F / std::sqrt(static_cast<float>(dim)), |
| 223 | 0.0F, |
| 224 | 0.0F); |
| 225 | ggml_flash_attn_ext_set_prec(flash, GGML_PREC_F32); |
| 226 | return core::wrap_tensor( |
| 227 | flash, |
| 228 | core::TensorShape::from_dims({q.shape.dims[0], q.shape.dims[2], q.shape.dims[1], dim}), |
| 229 | GGML_TYPE_F32); |
| 230 | } |
| 231 | |
| 232 | core::TensorValue same_self_attention( |
| 233 | core::ModuleBuildContext & ctx, |
no test coverage detected