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
932f9db4
Commit
932f9db4
authored
Jun 26, 2023
by
Matt Hoffner
Browse files
add llama model
parent
b281b092
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
53 additions
and
0 deletions
+53
-0
lm_eval/models/__init__.py
lm_eval/models/__init__.py
+2
-0
lm_eval/models/llama.py
lm_eval/models/llama.py
+51
-0
No files found.
lm_eval/models/__init__.py
View file @
932f9db4
...
@@ -4,6 +4,7 @@ from . import anthropic_llms
...
@@ -4,6 +4,7 @@ from . import anthropic_llms
from
.
import
huggingface
from
.
import
huggingface
from
.
import
textsynth
from
.
import
textsynth
from
.
import
dummy
from
.
import
dummy
from
.
import
llama
MODEL_REGISTRY
=
{
MODEL_REGISTRY
=
{
"hf"
:
gpt2
.
HFLM
,
"hf"
:
gpt2
.
HFLM
,
...
@@ -15,6 +16,7 @@ MODEL_REGISTRY = {
...
@@ -15,6 +16,7 @@ MODEL_REGISTRY = {
"anthropic"
:
anthropic_llms
.
AnthropicLM
,
"anthropic"
:
anthropic_llms
.
AnthropicLM
,
"textsynth"
:
textsynth
.
TextSynthLM
,
"textsynth"
:
textsynth
.
TextSynthLM
,
"dummy"
:
dummy
.
DummyLM
,
"dummy"
:
dummy
.
DummyLM
,
"llama"
:
llama
.
LlamaLM
}
}
...
...
lm_eval/models/llama.py
0 → 100644
View file @
932f9db4
import
requests
import
json
from
tqdm
import
tqdm
from
requests.exceptions
import
RequestException
import
time
def
llama_completion
(
base_url
,
prompt
,
**
kwargs
):
try
:
response
=
requests
.
post
(
f
"
{
base_url
}
/v1/completions"
,
json
=
kwargs
)
response
.
raise_for_status
()
return
response
.
json
()
except
RequestException
as
e
:
print
(
f
"RequestException:
{
e
}
"
)
return
None
class
LlamaLM
(
BaseLM
):
def
__init__
(
self
,
base_url
,
truncate
=
False
):
super
().
__init__
()
self
.
base_url
=
base_url
self
.
truncate
=
truncate
def
loglikelihood
(
self
,
requests
):
res
=
[]
for
context
,
continuation
in
tqdm
(
requests
):
response
=
llama_completion
(
self
.
base_url
,
context
,
continuation
=
continuation
)
if
response
and
"logprob"
in
response
:
logprob
=
response
[
"logprob"
]
is_greedy
=
response
[
"is_greedy"
]
res
.
append
((
logprob
,
is_greedy
))
else
:
logger
.
error
(
"Invalid response for loglikelihood"
)
assert
False
return
res
def
greedy_until
(
self
,
requests
):
if
not
requests
:
return
[]
res
=
[]
for
request
in
tqdm
(
requests
):
inp
=
request
[
0
]
request_args
=
request
[
1
]
until
=
request_args
[
"until"
]
response
=
llama_completion
(
self
.
base_url
,
inp
,
stop
=
until
)
if
response
and
"text"
in
response
:
s
=
response
[
"text"
]
res
.
append
(
s
)
else
:
logger
.
error
(
"Invalid response for greedy_until"
)
assert
False
return
res
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