MCPcopy Create free account
hub / github.com/appdevforall/CodeOnTheGo / create_memory

Method create_memory

subprojects/llama.cpp/src/llama-model.cpp:7478–7622  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

7476}
7477
7478llama_memory_i * llama_model::create_memory(const llama_memory_params & params, const llama_cparams & cparams) const {
7479 llama_memory_i * res;
7480
7481 switch (arch) {
7482 // Models that need specific instantiation should be handled in the
7483 // switch statement
7484 case LLM_ARCH_BERT:
7485 case LLM_ARCH_JINA_BERT_V2:
7486 case LLM_ARCH_JINA_BERT_V3:
7487 case LLM_ARCH_NOMIC_BERT:
7488 case LLM_ARCH_NOMIC_BERT_MOE:
7489 case LLM_ARCH_NEO_BERT:
7490 case LLM_ARCH_WAVTOKENIZER_DEC:
7491 case LLM_ARCH_MODERN_BERT:
7492 case LLM_ARCH_GEMMA_EMBEDDING:
7493 case LLM_ARCH_DREAM:
7494 case LLM_ARCH_LLADA:
7495 case LLM_ARCH_LLADA_MOE:
7496 case LLM_ARCH_RND1:
7497 {
7498 res = nullptr;
7499 } break;
7500 // Models that need standard caching should rely on recurrent/hybrid
7501 // checks
7502 default:
7503 {
7504 if (llm_arch_is_recurrent(arch)) {
7505 res = new llama_memory_recurrent(
7506 *this,
7507 GGML_TYPE_F32,
7508 GGML_TYPE_F32,
7509 cparams.offload_kqv,
7510 std::max((uint32_t) 1, cparams.n_seq_max),
7511 cparams.n_seq_max,
7512 nullptr);
7513 } else if (llm_arch_is_hybrid(arch)) {
7514
7515 // The main difference between hybrid architectures is the
7516 // layer filters, so pick the right one here
7517 llama_memory_hybrid::layer_filter_cb filter_attn = nullptr;
7518 llama_memory_hybrid::layer_filter_cb filter_recr = nullptr;
7519 if (arch == LLM_ARCH_FALCON_H1) {
7520 filter_attn = [&](int32_t) { return true; };
7521 filter_recr = [&](int32_t) { return true; };
7522 } else if (arch == LLM_ARCH_NEMOTRON_H || arch == LLM_ARCH_NEMOTRON_H_MOE) {
7523 filter_attn = [&](int32_t il) {
7524 return !hparams.is_recurrent(il) && hparams.n_ff(il) == 0;
7525 };
7526 filter_recr = [&](int32_t il) {
7527 return hparams.is_recurrent(il) && hparams.n_ff(il) == 0;
7528 };
7529 }
7530
7531 if (hparams.swa_type != LLAMA_SWA_TYPE_NONE) {
7532 // Use hybrid-iswa for hybrid models with SWA
7533 res = new llama_memory_hybrid_iswa(
7534 /* model */ *this,
7535 /* attn_type_k */ params.type_k,

Callers 1

llama_contextMethod · 0.80

Calls 7

llm_arch_is_recurrentFunction · 0.85
maxFunction · 0.85
llm_arch_is_hybridFunction · 0.85
is_recurrentMethod · 0.80
n_ffMethod · 0.80
is_swaMethod · 0.80
is_swa_anyMethod · 0.80

Tested by

no test coverage detected