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
5a85f9bb
Commit
5a85f9bb
authored
Mar 15, 2024
by
lintangsutawika
Browse files
fixed encoding for seq2seq models
parent
a85e0150
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
10 additions
and
6 deletions
+10
-6
lm_eval/api/model.py
lm_eval/api/model.py
+10
-4
lm_eval/models/huggingface.py
lm_eval/models/huggingface.py
+0
-2
No files found.
lm_eval/api/model.py
View file @
5a85f9bb
...
@@ -4,6 +4,7 @@ import json
...
@@ -4,6 +4,7 @@ import json
import
logging
import
logging
import
os
import
os
from
typing
import
List
,
Optional
,
Tuple
,
Type
,
TypeVar
from
typing
import
List
,
Optional
,
Tuple
,
Type
,
TypeVar
import
transformers
from
sqlitedict
import
SqliteDict
from
sqlitedict
import
SqliteDict
from
tqdm
import
tqdm
from
tqdm
import
tqdm
...
@@ -296,12 +297,17 @@ class TemplateLM(LM):
...
@@ -296,12 +297,17 @@ class TemplateLM(LM):
continuation
=
context
[
-
n_spaces
:]
+
continuation
continuation
=
context
[
-
n_spaces
:]
+
continuation
context
=
context
[:
-
n_spaces
]
context
=
context
[:
-
n_spaces
]
whole_enc
=
self
.
tok_encode
(
context
+
continuation
)
if
self
.
AUTO_MODEL_CLASS
==
transformers
.
AutoModelForCausalLM
:
context_enc
=
self
.
tok_encode
(
context
)
whole_enc
=
self
.
tok_encode
(
context
+
continuation
,
add_special_tokens
=
False
)
context_enc
=
self
.
tok_encode
(
context
,
add_special_tokens
=
False
)
context_enc_len
=
len
(
context_enc
)
context_enc_len
=
len
(
context_enc
)
continuation_enc
=
whole_enc
[
context_enc_len
:]
continuation_enc
=
whole_enc
[
context_enc_len
:]
elif
self
.
AUTO_MODEL_CLASS
==
transformers
.
AutoModelForSeq2SeqLM
:
context_enc
=
self
.
tok_encode
(
context
,
add_special_tokens
=
True
)
continuation_enc
=
self
.
tok_encode
(
continuation
,
add_special_tokens
=
True
)
return
context_enc
,
continuation_enc
return
context_enc
,
continuation_enc
def
loglikelihood
(
def
loglikelihood
(
...
...
lm_eval/models/huggingface.py
View file @
5a85f9bb
...
@@ -707,8 +707,6 @@ class HFLM(TemplateLM):
...
@@ -707,8 +707,6 @@ class HFLM(TemplateLM):
encoding
[
"attention_mask"
]
=
encoding
[
"attention_mask"
][
encoding
[
"attention_mask"
]
=
encoding
[
"attention_mask"
][
:,
-
left_truncate_len
:
:,
-
left_truncate_len
:
]
]
# print(encoding["input_ids"][0])
# import sys; sys.exit()
self
.
tokenizer
.
padding_side
=
old_padding_side
self
.
tokenizer
.
padding_side
=
old_padding_side
return
encoding
[
"input_ids"
],
encoding
[
"attention_mask"
]
return
encoding
[
"input_ids"
],
encoding
[
"attention_mask"
]
...
...
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