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
gaoqiong
lm-evaluation-harness
Commits
5c6e9b50
Commit
5c6e9b50
authored
Oct 15, 2025
by
Baber
Browse files
fix duplicate `bos` token when `context==""`
parent
ad506a13
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
11 additions
and
13 deletions
+11
-13
lm_eval/api/model.py
lm_eval/api/model.py
+5
-2
lm_eval/models/huggingface.py
lm_eval/models/huggingface.py
+6
-11
No files found.
lm_eval/api/model.py
View file @
5c6e9b50
...
...
@@ -378,11 +378,14 @@ class TemplateLM(LM):
new_reqs
=
[]
for
context
,
continuation
in
[
req
.
args
for
req
in
requests
]:
if
context
==
""
:
continuation_enc
=
self
.
tok_encode
(
continuation
)
# BOS or EOS as context
context_enc
,
continuation_enc
=
(
[
self
.
prefix_token_id
],
self
.
tok_encode
(
continuation
),
([
self
.
prefix_token_id
],
continuation_enc
)
if
self
.
prefix_token_id
!=
continuation_enc
[
0
]
else
(
continuation_enc
[:
1
],
continuation_enc
[
1
:])
)
# BOS or EOS as context
else
:
context_enc
,
continuation_enc
=
self
.
_encode_pair
(
context
,
continuation
)
...
...
lm_eval/models/huggingface.py
View file @
5c6e9b50
...
...
@@ -864,17 +864,12 @@ class HFLM(TemplateLM):
""" """
# default for None - empty dict, use predefined tokenizer param
# used for all models except for CausalLM or predefined value
special_tokens_kwargs
=
{}
# by default for CausalLM - false or self.add_bos_token is set
if
add_special_tokens
is
None
:
if
self
.
backend
==
"causal"
:
special_tokens_kwargs
=
{
"add_special_tokens"
:
False
or
self
.
add_bos_token
}
# otherwise the method explicitly defines the value
else
:
special_tokens_kwargs
=
{
"add_special_tokens"
:
add_special_tokens
}
special_tokens_kwargs
=
(
{
"add_special_tokens"
:
False
or
self
.
add_bos_token
}
if
self
.
backend
==
"causal"
# otherwise the method explicitly defines the value
else
{
"add_special_tokens"
:
add_special_tokens
}
)
encoding
=
self
.
tokenizer
.
encode
(
string
,
**
special_tokens_kwargs
)
...
...
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