From 884ee8ba603dc445f3f9fb9dc098d6bb0613c039 Mon Sep 17 00:00:00 2001 From: Ettore Di Giacinto Date: Sat, 8 Jun 2024 11:43:03 +0200 Subject: [PATCH] Small fixups Signed-off-by: Ettore Di Giacinto --- core/config/backend_config.go | 2 +- core/config/guesser.go | 51 ++++++++++++++++++++++++++++------- 2 files changed, 43 insertions(+), 10 deletions(-) diff --git a/core/config/backend_config.go b/core/config/backend_config.go index 17ae87de8ee..b9c8dd652ca 100644 --- a/core/config/backend_config.go +++ b/core/config/backend_config.go @@ -369,7 +369,7 @@ func (cfg *BackendConfig) SetDefaults(opts ...ConfigLoaderOption) { cfg.Debug = &trueV } - guessTemplate(cfg, lo.modelPath) + guessDefaultsFromFile(cfg, lo.modelPath) } func (c *BackendConfig) Validate() bool { diff --git a/core/config/guesser.go b/core/config/guesser.go index aa79d5db0fd..8f172085400 100644 --- a/core/config/guesser.go +++ b/core/config/guesser.go @@ -1,15 +1,29 @@ package config import ( - "fmt" "path/filepath" + "github.com/rs/zerolog/log" + gguf "github.com/thxcode/gguf-parser-go" ) -func guessTemplate(cfg *BackendConfig, modelPath string) { +type FamilyType uint8 + +const ( + Unknown FamilyType = iota + LLaMa3 = iota + LLama2 = iota +) + +var defaultsTemplate map[FamilyType]TemplateConfig = map[FamilyType]TemplateConfig{ + LLaMa3: {}, +} + +func guessDefaultsFromFile(cfg *BackendConfig, modelPath string) { if modelPath == "" { + log.Debug().Msgf("guessDefaultsFromFile: %s", "modelPath is empty") return } @@ -17,15 +31,14 @@ func guessTemplate(cfg *BackendConfig, modelPath string) { f, err := gguf.ParseGGUFFile(filepath.Join(modelPath, cfg.ModelFileName())) if err != nil { // Only valid for gguf files + log.Debug().Msgf("guessDefaultsFromFile: %s", "not a GGUF file") return } - fmt.Println(f.Architecture().Architecture) - fmt.Println("Model name", f.Model().Name) - fmt.Printf("%+v\n", f.Model()) - fmt.Println("EOS Token", f.Tokenizer().EOSTokenID) - - fmt.Println(f.Tokenizer()) + log.Debug(). + Any("eosTokenID", f.Tokenizer().EOSTokenID). + Any("modelName", f.Model().Name). + Any("architecture", f.Architecture().Architecture).Msgf("Model file loaded: %s", cfg.ModelFileName()) if cfg.Name == "" { cfg.Name = f.Model().Name @@ -35,6 +48,26 @@ func guessTemplate(cfg *BackendConfig, modelPath string) { return } - panic("foo") + family := identifyFamily(f) + + if family == Unknown { + log.Debug().Msgf("guessDefaultsFromFile: %s", "family not identified") + return + } + + templ, ok := defaultsTemplate[family] + if ok { + cfg.TemplateConfig = templ + } + +} + +func identifyFamily(f *gguf.GGUFFile) FamilyType { + + switch { + case f.Model().Name == "llama": + return LLaMa3 + } + return Unknown }