Team Ai
Apppublic

KBaba7/llama.cpp

sourceHugging Faceapache-2.0updated 2y agoView on Hugging Face
0likes
llama-hparams.cpp72 linesDownload Raw Back to src
1#include "llama-hparams.h"2 3#include "ggml.h"4 5uint32_t llama_hparams::n_head(uint32_t il) const {6    if (il < n_layer) {7        return n_head_arr[il];8    }9 10    GGML_ABORT("fatal error");11}12 13uint32_t llama_hparams::n_head_kv(uint32_t il) const {14    if (il < n_layer) {15        return n_head_kv_arr[il];16    }17 18    GGML_ABORT("fatal error");19}20 21uint32_t llama_hparams::n_ff(uint32_t il) const {22    if (il < n_layer) {23        return n_ff_arr[il];24    }25 26    GGML_ABORT("fatal error");27}28 29uint32_t llama_hparams::n_gqa(uint32_t il) const {30    const uint32_t n_head    = this->n_head(il);31    const uint32_t n_head_kv = this->n_head_kv(il);32 33    if (n_head_kv == 0) {34        return 0;35    }36 37    return n_head/n_head_kv;38}39 40uint32_t llama_hparams::n_embd_k_gqa(uint32_t il) const {41    const uint32_t n_head_kv = this->n_head_kv(il);42 43    return n_embd_head_k * n_head_kv;44}45 46uint32_t llama_hparams::n_embd_v_gqa(uint32_t il) const {47    const uint32_t n_head_kv = this->n_head_kv(il);48 49    return n_embd_head_v * n_head_kv;50}51 52uint32_t llama_hparams::n_embd_k_s() const {53    if (wkv_head_size != 0) {54        // for RWKV models55        return token_shift_count * n_embd;56    }57 58    // TODO: maybe support other convolution strides than 159    // NOTE: since the first column of the conv_state is shifted out each time, it's not actually needed60    return (ssm_d_conv > 0 ? ssm_d_conv - 1 : 0) * ssm_d_inner;61}62 63uint32_t llama_hparams::n_embd_v_s() const {64    if (wkv_head_size != 0) {65        // corresponds to RWKV's wkv_states size66        return n_embd * wkv_head_size;67    }68 69    // corresponds to Mamba's ssm_states size70    return ssm_d_state * ssm_d_inner;71}72