@@ -8,16 +8,19 @@ import (
8
8
gguf "github.com/thxcode/gguf-parser-go"
9
9
)
10
10
11
- type FamilyType uint8
11
+ type familyType uint8
12
12
13
13
const (
14
- Unknown FamilyType = iota
14
+ Unknown familyType = iota
15
15
LLaMa3 = iota
16
16
LLama2 = iota
17
17
)
18
18
19
- var defaultsTemplate map [FamilyType ]TemplateConfig = map [FamilyType ]TemplateConfig {
20
- LLaMa3 : {},
19
+ var defaultsTemplate map [familyType ]TemplateConfig = map [familyType ]TemplateConfig {
20
+ LLaMa3 : {
21
+ Chat : "<|begin_of_text|>{{.Input }}\n <|start_header_id|>assistant<|end_header_id|>" ,
22
+ ChatMessage : "<|start_header_id|>{{ .RoleName }}<|end_header_id|>\n \n {{.Content }}<|eot_id|>" ,
23
+ },
21
24
}
22
25
23
26
func guessDefaultsFromFile (cfg * BackendConfig , modelPath string ) {
@@ -26,8 +29,13 @@ func guessDefaultsFromFile(cfg *BackendConfig, modelPath string) {
26
29
log .Debug ().Msgf ("guessDefaultsFromFile: %s" , "modelPath is empty" )
27
30
return
28
31
}
32
+ if cfg .HasTemplate () || cfg .Name != "" {
33
+ // nothing to guess here
34
+ log .Debug ().Any ("name" , cfg .Name ).Msgf ("guessDefaultsFromFile: %s" , "template or name already set" )
35
+ return
36
+ }
29
37
30
- // We try to guess only if we don't have a template defined already+
38
+ // We try to guess only if we don't have a template defined already
31
39
f , err := gguf .ParseGGUFFile (filepath .Join (modelPath , cfg .ModelFileName ()))
32
40
if err != nil {
33
41
// Only valid for gguf files
@@ -37,17 +45,15 @@ func guessDefaultsFromFile(cfg *BackendConfig, modelPath string) {
37
45
38
46
log .Debug ().
39
47
Any ("eosTokenID" , f .Tokenizer ().EOSTokenID ).
48
+ Any ("bosTokenID" , f .Tokenizer ().BOSTokenID ).
40
49
Any ("modelName" , f .Model ().Name ).
41
50
Any ("architecture" , f .Architecture ().Architecture ).Msgf ("Model file loaded: %s" , cfg .ModelFileName ())
42
51
52
+ // guess the name
43
53
if cfg .Name == "" {
44
54
cfg .Name = f .Model ().Name
45
55
}
46
56
47
- if cfg .HasTemplate () {
48
- return
49
- }
50
-
51
57
family := identifyFamily (f )
52
58
53
59
if family == Unknown {
@@ -58,14 +64,15 @@ func guessDefaultsFromFile(cfg *BackendConfig, modelPath string) {
58
64
templ , ok := defaultsTemplate [family ]
59
65
if ok {
60
66
cfg .TemplateConfig = templ
67
+ log .Debug ().Any ("family" , family ).Msgf ("guessDefaultsFromFile: guessed template %+v" , cfg .TemplateConfig )
68
+ } else {
69
+ log .Debug ().Any ("family" , family ).Msgf ("guessDefaultsFromFile: no template found for family" )
61
70
}
62
-
63
71
}
64
72
65
- func identifyFamily (f * gguf.GGUFFile ) FamilyType {
66
-
73
+ func identifyFamily (f * gguf.GGUFFile ) familyType {
67
74
switch {
68
- case f .Model ().Name == "llama" :
75
+ case f .Architecture ().Architecture == "llama" && f . Tokenizer (). EOSTokenID == 128009 :
69
76
return LLaMa3
70
77
}
71
78
0 commit comments