yum-archive/TaSTT-Whisper
High-performance GPGPU inference of OpenAI's Whisper automatic speech recognition (ASR) model
git clone https://git.yummers.dev/yum-archive/TaSTT-Whisper
8c4603c
master
1#pragma once 2#include <vector> 3#include "Tensor.h" 4#include "LargeBuffer.h" 5#if TENSOR_GGML_COMPAT 6#include "../source/ggml.h" 7#endif 8 9namespace CpuCompute 10{ 11// A set of tensors for one decoder's layer 12struct LayerDecoder 13 { 14// decoder.blocks.*.attn_ln 15TensorPair attnLn0 ; 16// decoder.blocks.*.attn.out 17TensorPair attnLn1 ; 18// decoder.blocks.*.attn.query 19TensorPair attnQuery ; 20// decoder.blocks.*.attn.key 21Tensor attnKey ; 22// decoder.blocks.*.attn.value 23TensorPair attnValue ; 24// decoder.blocks.*.cross_attn_ln 25TensorPair crossAttnLn0 ; 26// decoder.blocks.*.cross_attn.out 27TensorPair crossAttnLn1 ; 28// decoder.blocks.*.cross_attn.query 29TensorPair crossAttnQuery ; 30 31// decoder.blocks.*.cross_attn.key 32// Tensor crossAttnKey; 33// decoder.blocks.*.cross_attn.value 34// TensorPair crossAttnValue; 35 36// decoder.blocks.*.mlp_ln 37TensorPair mlpLn ; 38// decoder.blocks.*.mlp.0 39TensorPair mlp0 ; 40// decoder.blocks.*.mlp.2 41TensorPair mlp1 ; 42 43#if TENSOR_GGML_COMPAT 44// decoder.blocks.*.attn_ln 45ggml_tensor * attn_ln_0_w ; 46ggml_tensor * attn_ln_0_b ; 47 48// decoder.blocks.*.attn.out 49ggml_tensor * attn_ln_1_w ; 50ggml_tensor * attn_ln_1_b ; 51 52// decoder.blocks.*.attn.query 53ggml_tensor * attn_q_w ; 54ggml_tensor * attn_q_b ; 55 56// decoder.blocks.*.attn.key 57ggml_tensor * attn_k_w ; 58 59// decoder.blocks.*.attn.value 60ggml_tensor * attn_v_w ; 61ggml_tensor * attn_v_b ; 62 63// decoder.blocks.*.cross_attn_ln 64ggml_tensor * cross_attn_ln_0_w ; 65ggml_tensor * cross_attn_ln_0_b ; 66 67// decoder.blocks.*.cross_attn.out 68ggml_tensor * cross_attn_ln_1_w ; 69ggml_tensor * cross_attn_ln_1_b ; 70 71// decoder.blocks.*.cross_attn.query 72ggml_tensor * cross_attn_q_w ; 73ggml_tensor * cross_attn_q_b ; 74 75// decoder.blocks.*.mlp_ln 76ggml_tensor * mlp_ln_w ; 77ggml_tensor * mlp_ln_b ; 78 79// decoder.blocks.*.mlp.0 80ggml_tensor * mlp_0_w ; 81ggml_tensor * mlp_0_b ; 82 83// decoder.blocks.*.mlp.2 84ggml_tensor * mlp_1_w ; 85ggml_tensor * mlp_1_b ; 86#endif 87 }; 88 89struct DecoderTensors 90 { 91// decoder.positional_embedding 92Tensor positionalEmbedding ; 93 94// decoder.token_embedding 95Tensor tokenEmbedding ; 96 97// decoder.ln 98TensorPair ln ; 99// A vector of layers 100std ::vector < LayerDecoder > layers ; 101 102void setMemoryBuffer (LargeBuffer && mem )noexcept 103 { 104memory = std ::move (mem ); 105#if TENSOR_GGML_COMPAT 106makeCompatTensors (); 107#endif 108} 109 110#if TENSOR_GGML_COMPAT 111void makeCompatTensors (); 112 113// decoder.positional_embedding 114ggml_tensor * d_pe ; // DD 115 116// decoder.token_embedding 117ggml_tensor * d_te ; // DD 118 119// decoder.ln 120ggml_tensor * d_ln_w ; // DD 121ggml_tensor * d_ln_b ; // DD 122#endif 123 124private : 125// A smart pointer which owns the memory for all the above tensors 126LargeBuffer memory ; 127#if TENSOR_GGML_COMPAT 128std :: vector < ggml_tensor > ggml ; 129#endif 130 }; 131}