From dd89015c1300a8341e00b5f5cdfd10dc0861265d Mon Sep 17 00:00:00 2001 From: cebtenzzre Date: Fri, 17 Nov 2023 07:57:11 -0500 Subject: [PATCH] simplify std::string specialization --- llama.cpp | 38 ++++++++++++++++---------------------- 1 file changed, 16 insertions(+), 22 deletions(-) diff --git a/llama.cpp b/llama.cpp index 626905426..e42e5f5ef 100644 --- a/llama.cpp +++ b/llama.cpp @@ -1708,6 +1708,14 @@ namespace GGUFMeta { template<> struct GKV_Base: GKV_Base_Type {}; template<> struct GKV_Base: GKV_Base_Type {}; + template<> struct GKV_Base { + static constexpr gguf_type gt = GGUF_TYPE_STRING; + + static std::string getter(const gguf_context * ctx, const int kid) { + return gguf_get_val_str(ctx, kid); + } + }; + struct ArrayInfo{ const gguf_type gt; const size_t length; @@ -1741,9 +1749,6 @@ namespace GGUFMeta { return GKV::getter(ctx, k); } - // This can't be uncommented. - // template static bool try_override(OT & target, const struct llama_model_kv_override *override) = delete; - template static typename std::enable_if::value, bool>::type try_override(OT & target, const struct llama_model_kv_override *override) { @@ -1786,6 +1791,14 @@ namespace GGUFMeta { return true; } + template + static typename std::enable_if::value, bool>::type + try_override(T & target, const struct llama_model_kv_override *override) { + (void)target; + (void)override; + return false; // cannot override str + } + static bool set(const gguf_context * ctx, const int k, T & target, const struct llama_model_kv_override *override = nullptr) { if (try_override(target, override)) { return true; @@ -1808,25 +1821,6 @@ namespace GGUFMeta { return GKV::set(ctx, key.c_str(), target, override); } }; - - template<> - class GKV: public GKV_Base { - using BT = const char *; - public: - static bool set(const gguf_context * ctx, const int k, std::string & target, const struct llama_model_kv_override *override = nullptr) { - (void)override; - target = std::string(GKV::get_kv(ctx, k)); - return true; - } - - static bool set(const gguf_context * ctx, const char * key, std::string & target, const struct llama_model_kv_override *override = nullptr) { - return GKV::set(ctx, key, target, override); - } - - static bool set(const gguf_context * ctx, const std::string & key, std::string & target, const struct llama_model_kv_override *override = nullptr) { - return GKV::set(ctx, key, target, override); - } - }; } struct llama_model_loader {