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
d53969b5
Commit
d53969b5
authored
Oct 04, 2020
by
Anish Thite
Browse files
Merge branch 'master' of
https://github.com/EleutherAI/lm_evaluation_harness
parents
ec4d3615
d9e50f87
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
6 additions
and
5 deletions
+6
-5
lm_eval/models/gpt2.py
lm_eval/models/gpt2.py
+6
-3
lm_eval/models/gpt3.py
lm_eval/models/gpt3.py
+0
-2
No files found.
lm_eval/models/gpt2.py
View file @
d53969b5
...
@@ -17,19 +17,22 @@ class GPT2LM(LM):
...
@@ -17,19 +17,22 @@ class GPT2LM(LM):
return
cls
(
device
=
args
.
get
(
"device"
,
"cpu"
))
return
cls
(
device
=
args
.
get
(
"device"
,
"cpu"
))
def
generate
(
self
,
context
,
max_gen_length
,
truncate
=
True
):
def
generate
(
self
,
context
,
max_gen_length
,
truncate
=
True
):
context_tensor
=
torch
.
tensor
([
self
.
tokenizer
.
encode
(
context
.
strip
())],
dtype
=
torch
.
long
).
to
(
self
.
device
)
# when too long to fit in context, truncate from the left
context_tensor
=
torch
.
tensor
([
self
.
tokenizer
.
encode
(
context
.
strip
())[
max_gen_length
-
1024
:]],
dtype
=
torch
.
long
).
to
(
self
.
device
)
res
=
self
.
gpt2
.
generate
(
res
=
self
.
gpt2
.
generate
(
context_tensor
,
context_tensor
,
# TODO: change to have until rather than using eos_token_id
eos_token_id
=
self
.
tokenizer
.
eos_token_id
,
eos_token_id
=
self
.
tokenizer
.
eos_token_id
,
do_sample
=
False
,
do_sample
=
False
,
max_length
=
self
.
num_tokens
(
context
)
+
max_gen_length
,
max_length
=
self
.
num_tokens
(
context
)
+
max_gen_length
,
)
)
# chop off the prompt and the final eos token
# chop off the prompt and the final eos token
return
self
.
tokenizer
.
decode
(
res
[
0
][
len
(
context
[
0
]):
-
1
]).
strip
()
return
self
.
tokenizer
.
decode
(
res
[
0
][
min
(
1024
-
max_gen_length
,
len
(
context
_tensor
[
0
])
)
:
-
1
]).
strip
()
def
loglikelihood
(
self
,
context
,
continuation
,
truncate
=
True
):
def
loglikelihood
(
self
,
context
,
continuation
,
truncate
=
True
):
inp
=
torch
.
tensor
([
self
.
tokenizer
.
encode
(
context
+
continuation
)],
dtype
=
torch
.
long
).
to
(
self
.
device
)
# when too long to fit in context, truncate from the left
inp
=
torch
.
tensor
([
self
.
tokenizer
.
encode
(
context
+
continuation
)[
-
1024
:]],
dtype
=
torch
.
long
).
to
(
self
.
device
)
ctxlen
=
len
(
self
.
tokenizer
.
encode
(
context
.
strip
()))
ctxlen
=
len
(
self
.
tokenizer
.
encode
(
context
.
strip
()))
cont_toks
=
inp
[:,
ctxlen
:]
# [batch, seq]
cont_toks
=
inp
[:,
ctxlen
:]
# [batch, seq]
...
...
lm_eval/models/gpt3.py
View file @
d53969b5
...
@@ -2,10 +2,8 @@ import os
...
@@ -2,10 +2,8 @@ import os
import
transformers
import
transformers
from
lm_eval.base
import
LM
from
lm_eval.base
import
LM
from
lm_eval
import
utils
from
lm_eval
import
utils
from
.
import
MODEL_REGISTRY
@
MODEL_REGISTRY
.
register
(
"gpt3"
)
class
GPT3LM
(
LM
):
class
GPT3LM
(
LM
):
MAX_LENGTH
=
2048
MAX_LENGTH
=
2048
...
...
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