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#include "stdafx.h" 2#include "DecoderTensors.h" 3using namespace CpuCompute ; 4 5#if TENSOR_GGML_COMPAT 6namespace 7{ 8class CompatContext 9 { 10 std::vector < ggml_tensor >& vec ; 11size_t index ; 12 13public : 14CompatContext ( std::vector < ggml_tensor >& dest ,size_t layers ) : 15vec (dest ) 16 { 17constexpr size_t tensorsPerLayer = 21 ; 18const size_t count = tensorsPerLayer * layers + 4 ; 19vec .resize (count ); 20index = 0 ; 21 } 22 23void add (const Tensor & rsi ,ggml_tensor *& res ) 24 { 25ggml_tensor & ten = vec [index ]; 26index ++ ; 27ten = rsi .ggml (); 28res = & ten ; 29 } 30 31void add2 (const TensorPair & rsi ,ggml_tensor *& w ,ggml_tensor *& b ) 32 { 33add (rsi .w ,w ); 34add (rsi .b ,b ); 35 } 36 37bool isComplete ()const 38 { 39return index == vec .size (); 40 } 41 }; 42} 43 44void DecoderTensors ::makeCompatTensors () 45{ 46CompatContext ctx (ggml ,layers .size () ); 47 48ctx .add (positionalEmbedding ,d_pe ); 49ctx .add (tokenEmbedding ,d_te ); 50ctx .add2 (ln ,d_ln_w ,d_ln_b ); 51 52for (auto & i :layers ) 53 { 54ctx .add2 (i .attnLn0 ,i .attn_ln_0_w ,i .attn_ln_0_b ); 55ctx .add2 (i .attnLn1 ,i .attn_ln_1_w ,i .attn_ln_1_b ); 56ctx .add2 (i .attnQuery ,i .attn_q_w ,i .attn_q_b ); 57ctx .add (i .attnKey ,i .attn_k_w ); 58ctx .add2 (i .attnValue ,i .attn_v_w ,i .attn_v_b ); 59ctx .add2 (i .crossAttnLn0 ,i .cross_attn_ln_0_w ,i .cross_attn_ln_0_b ); 60ctx .add2 (i .crossAttnLn1 ,i .cross_attn_ln_1_w ,i .cross_attn_ln_1_b ); 61ctx .add2 (i .crossAttnQuery ,i .cross_attn_q_w ,i .cross_attn_q_b ); 62ctx .add2 (i .mlpLn ,i .mlp_ln_w ,i .mlp_ln_b ); 63ctx .add2 (i .mlp0 ,i .mlp_0_w ,i .mlp_0_b ); 64ctx .add2 (i .mlp1 ,i .mlp_1_w ,i .mlp_1_b ); 65 } 66assert (ctx .isComplete () ); 67} 68#endif