Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
OpenDAS
ollama
Commits
53d2990d
Commit
53d2990d
authored
Feb 26, 2025
by
Michael Yang
Browse files
model: add bos token if configured
parent
e185c08a
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
32 additions
and
2 deletions
+32
-2
fs/ggml/ggml.go
fs/ggml/ggml.go
+5
-1
ml/backend.go
ml/backend.go
+1
-0
model/models/llama/model.go
model/models/llama/model.go
+2
-0
model/models/mllama/model.go
model/models/mllama/model.go
+2
-0
model/process_text.go
model/process_text.go
+22
-1
No files found.
fs/ggml/ggml.go
View file @
53d2990d
...
...
@@ -100,6 +100,10 @@ func (kv KV) Float(key string, defaultValue ...float32) float32 {
return
keyValue
(
kv
,
key
,
append
(
defaultValue
,
0
)
...
)
}
func
(
kv
KV
)
Bool
(
key
string
,
defaultValue
...
bool
)
bool
{
return
keyValue
(
kv
,
key
,
append
(
defaultValue
,
false
)
...
)
}
func
(
kv
KV
)
Strings
(
key
string
,
defaultValue
...
[]
string
)
[]
string
{
r
:=
keyValue
(
kv
,
key
,
&
array
{})
s
:=
make
([]
string
,
r
.
size
)
...
...
@@ -120,7 +124,7 @@ func (kv KV) Uints(key string, defaultValue ...[]uint32) []uint32 {
return
s
}
func
keyValue
[
T
string
|
uint32
|
uint64
|
float32
|
*
array
](
kv
KV
,
key
string
,
defaultValue
...
T
)
T
{
func
keyValue
[
T
string
|
uint32
|
uint64
|
float32
|
*
array
|
bool
](
kv
KV
,
key
string
,
defaultValue
...
T
)
T
{
if
!
strings
.
HasPrefix
(
key
,
"tokenizer."
)
&&
!
strings
.
HasPrefix
(
key
,
"general."
)
{
key
=
kv
.
Architecture
()
+
"."
+
key
}
...
...
ml/backend.go
View file @
53d2990d
...
...
@@ -14,6 +14,7 @@ type Config interface {
String
(
string
,
...
string
)
string
Uint
(
string
,
...
uint32
)
uint32
Float
(
string
,
...
float32
)
float32
Bool
(
string
,
...
bool
)
bool
Strings
(
string
,
...
[]
string
)
[]
string
Uints
(
string
,
...
[]
uint32
)
[]
uint32
...
...
model/models/llama/model.go
View file @
53d2990d
...
...
@@ -37,7 +37,9 @@ func New(c ml.Config) (model.Model, error) {
Types
:
c
.
Uints
(
"tokenizer.ggml.token_type"
),
Merges
:
c
.
Strings
(
"tokenizer.ggml.merges"
),
BOS
:
int32
(
c
.
Uint
(
"tokenizer.ggml.bos_token_id"
)),
AddBOS
:
c
.
Bool
(
"tokenizer.ggml.add_bos_token"
,
true
),
EOS
:
int32
(
c
.
Uint
(
"tokenizer.ggml.eos_token_id"
)),
AddEOS
:
c
.
Bool
(
"tokenizer.ggml.add_eos_token"
,
false
),
},
),
Layers
:
make
([]
Layer
,
c
.
Uint
(
"block_count"
)),
...
...
model/models/mllama/model.go
View file @
53d2990d
...
...
@@ -33,7 +33,9 @@ func New(c ml.Config) (model.Model, error) {
Types
:
c
.
Uints
(
"tokenizer.ggml.token_type"
),
Merges
:
c
.
Strings
(
"tokenizer.ggml.merges"
),
BOS
:
int32
(
c
.
Uint
(
"tokenizer.ggml.bos_token_id"
)),
AddBOS
:
c
.
Bool
(
"tokenizer.ggml.add_bos_token"
,
true
),
EOS
:
int32
(
c
.
Uint
(
"tokenizer.ggml.eos_token_id"
)),
AddEOS
:
c
.
Bool
(
"tokenizer.ggml.add_eos_token"
,
false
),
},
),
ImageProcessor
:
newImageProcessor
(
c
),
...
...
model/process_text.go
View file @
53d2990d
...
...
@@ -31,6 +31,7 @@ type Vocabulary struct {
Merges
[]
string
BOS
,
EOS
int32
AddBOS
,
AddEOS
bool
specialOnce
sync
.
Once
special
[]
string
...
...
@@ -281,6 +282,26 @@ func (bpe BytePairEncoding) Encode(s string) ([]int32, error) {
}
}
if
len
(
ids
)
>
0
{
if
bpe
.
vocab
.
AddBOS
{
if
ids
[
0
]
==
bpe
.
vocab
.
BOS
{
slog
.
Warn
(
"adding bos token to prompt which already has it"
,
"id"
,
bpe
.
vocab
.
BOS
)
}
slog
.
Debug
(
"adding bos token to prompt"
,
"id"
,
bpe
.
vocab
.
BOS
)
ids
=
append
([]
int32
{
bpe
.
vocab
.
BOS
},
ids
...
)
}
if
bpe
.
vocab
.
AddEOS
{
if
ids
[
len
(
ids
)
-
1
]
==
bpe
.
vocab
.
EOS
{
slog
.
Warn
(
"adding eos token to prompt which already has it"
,
"id"
,
bpe
.
vocab
.
EOS
)
}
slog
.
Debug
(
"adding eos token to prompt"
,
"id"
,
bpe
.
vocab
.
EOS
)
ids
=
append
(
ids
,
bpe
.
vocab
.
EOS
)
}
}
return
ids
,
nil
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment