LLM inference in C/C++
C++ ggml
models : move build_arch_graph() after graph() template specialization (#28934)
Chris Peterson9e7171624711
diff --git a/src/models/dflash.cpp b/src/models/dflash.cppindex da84f30b63..ed5366d808 100644--- a/src/models/dflash.cpp+++ b/src/models/dflash.cpp@@ -240,21 +240,6 @@ void llama_model_dflash::load_arch_tensors(llama_model_loader &) {}}-std::unique_ptr<llm_graph_context> llama_model_dflash::build_arch_graph(const llm_graph_params & params) const {- switch (params.gtype) {- case LLM_GRAPH_TYPE_ENCODER:- return std::make_unique<graph<true>>(*this, params);- case LLM_GRAPH_TYPE_DEFAULT:- case LLM_GRAPH_TYPE_DECODER:- if (hparams.dsv4_hc_mult > 0) {- return std::make_unique<graph_dsv4>(*this, params);- }- return std::make_unique<graph<false>>(*this, params);- default:- GGML_ABORT("invalid graph type");- };-}-template <>ggml_tensor * llama_model_dflash::graph<true>::build_inp_embd_enc() const {const int64_t n_embd_inp = hparams.n_embd_inp_enc();@@ -999,3 +984,18 @@ llama_model_dflash::graph_dsv4::graph_dsv4(const llama_model & model, const llm_build_dspark_markov_head(*this, model, inp_tokens);}}++std::unique_ptr<llm_graph_context> llama_model_dflash::build_arch_graph(const llm_graph_params & params) const {+ switch (params.gtype) {+ case LLM_GRAPH_TYPE_ENCODER:+ return std::make_unique<graph<true>>(*this, params);+ case LLM_GRAPH_TYPE_DEFAULT:+ case LLM_GRAPH_TYPE_DECODER:+ if (hparams.dsv4_hc_mult > 0) {+ return std::make_unique<graph_dsv4>(*this, params);+ }+ return std::make_unique<graph<false>>(*this, params);+ default:+ GGML_ABORT("invalid graph type");+ };+}diff --git a/src/models/eagle3.cpp b/src/models/eagle3.cppindex be466056df..bfde35e43b 100644--- a/src/models/eagle3.cpp+++ b/src/models/eagle3.cpp@@ -100,18 +100,6 @@ void llama_model_eagle3::load_arch_tensors(llama_model_loader &) {}}-std::unique_ptr<llm_graph_context> llama_model_eagle3::build_arch_graph(const llm_graph_params & params) const {- switch (params.gtype) {- case LLM_GRAPH_TYPE_ENCODER:- return std::make_unique<graph<true>>(*this, params);- case LLM_GRAPH_TYPE_DEFAULT:- case LLM_GRAPH_TYPE_DECODER:- return std::make_unique<graph<false>>(*this, params);- default:- GGML_ABORT("invalid graph type");- };-}-template <>ggml_tensor * llama_model_eagle3::graph<true>::build_inp_embd_enc() const {ggml_tensor * cur = nullptr;@@ -336,3 +324,15 @@ llama_model_eagle3::graph<false>::graph(const llama_model & model, const llm_graggml_build_forward_expand(gf, cur);}++std::unique_ptr<llm_graph_context> llama_model_eagle3::build_arch_graph(const llm_graph_params & params) const {+ switch (params.gtype) {+ case LLM_GRAPH_TYPE_ENCODER:+ return std::make_unique<graph<true>>(*this, params);+ case LLM_GRAPH_TYPE_DEFAULT:+ case LLM_GRAPH_TYPE_DECODER:+ return std::make_unique<graph<false>>(*this, params);+ default:+ GGML_ABORT("invalid graph type");+ };+}diff --git a/src/models/t5.cpp b/src/models/t5.cppindex b0e3f06257..e2bf12b6b1 100644--- a/src/models/t5.cpp+++ b/src/models/t5.cpp@@ -106,18 +106,6 @@ void llama_model_t5::load_arch_tensors(llama_model_loader &) {}}-std::unique_ptr<llm_graph_context> llama_model_t5::build_arch_graph(const llm_graph_params & params) const {- switch (params.gtype) {- case LLM_GRAPH_TYPE_ENCODER:- return std::make_unique<graph<true>>(*this, params);- case LLM_GRAPH_TYPE_DEFAULT:- case LLM_GRAPH_TYPE_DECODER:- return std::make_unique<graph<false>>(*this, params);- default:- GGML_ABORT("invalid graph type");- };-}-template <>llama_model_t5::graph<false>::graph(const llama_model & model, const llm_graph_params & params) : llm_graph_context(params) {const int64_t n_embd_head = hparams.n_embd_head_v();@@ -368,3 +356,15 @@ llama_model_t5::graph<true>::graph(const llama_model & model, const llm_graph_paggml_build_forward_expand(gf, cur);}++std::unique_ptr<llm_graph_context> llama_model_t5::build_arch_graph(const llm_graph_params & params) const {+ switch (params.gtype) {+ case LLM_GRAPH_TYPE_ENCODER:+ return std::make_unique<graph<true>>(*this, params);+ case LLM_GRAPH_TYPE_DEFAULT:+ case LLM_GRAPH_TYPE_DECODER:+ return std::make_unique<graph<false>>(*this, params);+ default:+ GGML_ABORT("invalid graph type");+ };+}