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
9e125d88
Unverified
Commit
9e125d88
authored
Jun 16, 2025
by
Jeffrey Morgan
Committed by
GitHub
Jun 16, 2025
Browse files
model: treat 'user defined' tokens as special tokens (#11077)
parent
a6fbfc88
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
17 additions
and
1 deletion
+17
-1
model/vocabulary.go
model/vocabulary.go
+1
-1
model/vocabulary_test.go
model/vocabulary_test.go
+16
-0
No files found.
model/vocabulary.go
View file @
9e125d88
...
@@ -87,7 +87,7 @@ func (v *Vocabulary) Decode(id int32) string {
...
@@ -87,7 +87,7 @@ func (v *Vocabulary) Decode(id int32) string {
func
(
v
*
Vocabulary
)
SpecialVocabulary
()
[]
string
{
func
(
v
*
Vocabulary
)
SpecialVocabulary
()
[]
string
{
v
.
specialOnce
.
Do
(
func
()
{
v
.
specialOnce
.
Do
(
func
()
{
for
i
:=
range
v
.
Values
{
for
i
:=
range
v
.
Values
{
if
v
.
Types
[
i
]
==
TOKEN_TYPE_CONTROL
{
if
v
.
Types
[
i
]
==
TOKEN_TYPE_CONTROL
||
v
.
Types
[
i
]
==
TOKEN_TYPE_USER_DEFINED
{
v
.
special
=
append
(
v
.
special
,
v
.
Values
[
i
])
v
.
special
=
append
(
v
.
special
,
v
.
Values
[
i
])
}
}
}
}
...
...
model/vocabulary_test.go
0 → 100644
View file @
9e125d88
package
model
import
"testing"
func
TestVocabulary_SpecialVocabulary
(
t
*
testing
.
T
)
{
vocab
:=
&
Vocabulary
{
Values
:
[]
string
{
"<|startoftext|>"
,
"<|endoftext|>"
,
"<|tool_call_start|>"
,
"<|tool_call_end|>"
,
"hi"
},
Types
:
[]
int32
{
TOKEN_TYPE_CONTROL
,
TOKEN_TYPE_CONTROL
,
TOKEN_TYPE_USER_DEFINED
,
TOKEN_TYPE_USER_DEFINED
,
TOKEN_TYPE_NORMAL
},
}
specialVocab
:=
vocab
.
SpecialVocabulary
()
if
len
(
specialVocab
)
!=
4
{
t
.
Errorf
(
"expected 4 special tokens, got %d"
,
len
(
specialVocab
))
}
}
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