Skip to content

Commit

Permalink
Small fixups
Browse files Browse the repository at this point in the history
Signed-off-by: Ettore Di Giacinto <[email protected]>
  • Loading branch information
mudler committed Jun 8, 2024
1 parent 218649b commit 884ee8b
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 10 deletions.
2 changes: 1 addition & 1 deletion core/config/backend_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
51 changes: 42 additions & 9 deletions core/config/guesser.go
Original file line number Diff line number Diff line change
@@ -1,31 +1,44 @@
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
}

// We try to guess only if we don't have a template defined already+
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
Expand All @@ -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
}

0 comments on commit 884ee8b

Please sign in to comment.