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
ac9f4be2
"src/include/blockwise_4d_tensor_op.cuh" did not exist on "057c10e57e9b6dacda4d8129a9340039fce57e8b"
Commit
ac9f4be2
authored
Jun 26, 2023
by
Matt Hoffner
Browse files
rename to ggml
parent
3ee4c2e2
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
19 additions
and
19 deletions
+19
-19
lm_eval/models/__init__.py
lm_eval/models/__init__.py
+2
-2
lm_eval/models/ggml.py
lm_eval/models/ggml.py
+4
-4
tests/test_ggml.py
tests/test_ggml.py
+13
-13
No files found.
lm_eval/models/__init__.py
View file @
ac9f4be2
...
...
@@ -4,7 +4,7 @@ from . import anthropic_llms
from
.
import
huggingface
from
.
import
textsynth
from
.
import
dummy
from
.
import
llama
from
.
import
ggml
MODEL_REGISTRY
=
{
"hf"
:
gpt2
.
HFLM
,
...
...
@@ -16,7 +16,7 @@ MODEL_REGISTRY = {
"anthropic"
:
anthropic_llms
.
AnthropicLM
,
"textsynth"
:
textsynth
.
TextSynthLM
,
"dummy"
:
dummy
.
DummyLM
,
"
llama"
:
llama
.
LlamaCpp
LM
"
ggml"
:
ggml
.
GGML
LM
}
...
...
lm_eval/models/
llama
.py
→
lm_eval/models/
ggml
.py
View file @
ac9f4be2
...
...
@@ -9,7 +9,7 @@ import time
logger
=
logging
.
getLogger
(
__name__
)
def
llama
_completion
(
base_url
,
prompt
,
**
kwargs
):
def
ggml
_completion
(
base_url
,
prompt
,
**
kwargs
):
try
:
response
=
requests
.
post
(
f
"
{
base_url
}
/v1/completions"
,
json
=
kwargs
)
response
.
raise_for_status
()
...
...
@@ -18,7 +18,7 @@ def llama_completion(base_url, prompt, **kwargs):
print
(
f
"RequestException:
{
e
}
"
)
return
None
class
LlamaCpp
LM
(
BaseLM
):
class
GGML
LM
(
BaseLM
):
def
__init__
(
self
,
base_url
,
truncate
=
False
):
super
().
__init__
()
self
.
base_url
=
base_url
...
...
@@ -27,7 +27,7 @@ class LlamaCppLM(BaseLM):
def
loglikelihood
(
self
,
requests
):
res
=
[]
for
context
,
continuation
in
tqdm
(
requests
):
response
=
llama
_completion
(
self
.
base_url
,
context
,
continuation
=
continuation
)
response
=
ggml
_completion
(
self
.
base_url
,
context
,
continuation
=
continuation
)
print
(
f
"Loglikelihood response:
{
response
}
"
)
if
response
and
"choices"
in
response
and
response
[
"choices"
]:
choice
=
response
[
"choices"
][
0
]
...
...
@@ -49,7 +49,7 @@ class LlamaCppLM(BaseLM):
inp
=
request
[
0
]
request_args
=
request
[
1
]
until
=
request_args
[
"until"
]
response
=
self
.
llama
_completion
(
inp
,
context
=
res
,
stop
=
until
)
# Pass the context
response
=
self
.
ggml
_completion
(
inp
,
context
=
res
,
stop
=
until
)
# Pass the context
print
(
f
"Greedy_until response:
{
response
}
"
)
if
response
and
"text"
in
response
:
generated_text
=
response
[
"text"
].
strip
()
...
...
tests/test_
llama
.py
→
tests/test_
ggml
.py
View file @
ac9f4be2
import
unittest
from
unittest.mock
import
MagicMock
from
lm_eval.models.
llama
import
LlamaCpp
LM
from
lm_eval.models.
ggml
import
GGML
LM
class
LlamaCpp
LMTest
(
unittest
.
TestCase
):
class
GGML
LMTest
(
unittest
.
TestCase
):
def
test_loglikelihood
(
self
):
base_url
=
"https://matthoffner-ggml-llm-api.hf.space"
lm
=
LlamaCpp
LM
(
base_url
)
lm
=
GGML
LM
(
base_url
)
# Create a MagicMock object to mock
llama
_completion
llama
_completion_mock
=
MagicMock
()
# Create a MagicMock object to mock
ggml
_completion
ggml
_completion_mock
=
MagicMock
()
# Set the return value for the mocked function
llama
_completion_mock
.
return_value
=
{
ggml
_completion_mock
.
return_value
=
{
"logprob"
:
-
1.2345
,
"is_greedy"
:
True
}
# Patch the
llama
_completion function with the mocked function
lm
.
llama
_completion
=
llama
_completion_mock
# Patch the
ggml
_completion function with the mocked function
lm
.
ggml
_completion
=
ggml
_completion_mock
# Test loglikelihood
requests
=
[(
"context1"
,
"continuation1"
),
(
"context2"
,
"continuation2"
)]
...
...
@@ -29,16 +29,16 @@ class LlamaCppLMTest(unittest.TestCase):
def
test_greedy_until
(
self
):
base_url
=
"https://matthoffner-ggml-llm-api.hf.space"
lm
=
LlamaCpp
LM
(
base_url
)
lm
=
GGML
LM
(
base_url
)
# Define the
llama
_completion method with the desired behavior
def
llama
_completion_mock
(
url
,
context
,
stop
=
None
):
# Define the
ggml
_completion method with the desired behavior
def
ggml
_completion_mock
(
url
,
context
,
stop
=
None
):
if
stop
is
not
None
:
return
{
"text"
:
f
"generated_text
{
stop
[
-
1
]
}
"
}
return
{
"text"
:
"generated_text"
}
# Set the
llama
_completion method to the defined mock
lm
.
llama
_completion
=
llama
_completion_mock
# Set the
ggml
_completion method to the defined mock
lm
.
ggml
_completion
=
ggml
_completion_mock
# Test greedy_until
requests
=
[(
"input1"
,
{
"until"
:
"stop1"
}),
(
"input2"
,
{
"until"
:
"stop2"
})]
...
...
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