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
opencompass
Commits
49c46745
Unverified
Commit
49c46745
authored
Sep 08, 2023
by
Leymore
Committed by
GitHub
Sep 08, 2023
Browse files
[Feature] Update llama2 (#372)
parent
3871188c
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
12 additions
and
6 deletions
+12
-6
opencompass/models/llama2.py
opencompass/models/llama2.py
+12
-6
No files found.
opencompass/models/llama2.py
View file @
49c46745
...
@@ -59,12 +59,18 @@ class Llama2(BaseModel):
...
@@ -59,12 +59,18 @@ class Llama2(BaseModel):
self
.
tokenizer
=
Tokenizer
(
tokenizer_path
)
self
.
tokenizer
=
Tokenizer
(
tokenizer_path
)
def
generate
(
self
,
inputs
:
List
[
str
],
max_out_len
:
int
)
->
List
[
str
]:
def
generate
(
self
,
inputs
:
List
[
str
],
max_out_len
:
int
)
->
List
[
str
]:
out
=
self
.
generator
.
text_completion
(
prompt_tokens
=
[]
inputs
,
for
input
in
inputs
:
temperature
=
0
,
tokens
=
self
.
tokenizer
.
encode
(
input
,
True
,
False
)
num_token
=
min
(
self
.
model
.
params
.
max_seq_len
,
len
(
tokens
))
prompt_tokens
.
append
(
tokens
[
-
num_token
:])
generation_tokens
,
_
=
self
.
generator
.
generate
(
prompt_tokens
=
prompt_tokens
,
max_gen_len
=
max_out_len
,
max_gen_len
=
max_out_len
,
temperature
=
0
,
)
)
return
[
i
[
'generation'
]
for
i
in
out
]
results
=
[
self
.
tokenizer
.
decode
(
t
)
for
t
in
generation_tokens
]
return
results
def
get_ppl
(
self
,
def
get_ppl
(
self
,
inputs
:
List
[
str
],
inputs
:
List
[
str
],
...
@@ -183,8 +189,8 @@ class Llama2Chat(BaseModel):
...
@@ -183,8 +189,8 @@ class Llama2Chat(BaseModel):
)
)
return
[
r
[
'generation'
][
'content'
]
for
r
in
results
]
return
[
r
[
'generation'
][
'content'
]
for
r
in
results
]
except
AssertionError
:
except
AssertionError
:
self
.
warning
(
'Batched data max token limit exceeded, '
self
.
logger
.
warning
(
'Batched data max token limit exceeded, '
'try to run one by one...'
)
'try to run one by one...'
)
results
=
[]
results
=
[]
for
dialog
in
dialogs
:
for
dialog
in
dialogs
:
...
...
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