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
b56dee4e
Commit
b56dee4e
authored
Jun 27, 2023
by
Matt Hoffner
Browse files
add loglikelihood_rolling
parent
97d31082
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
32 additions
and
5 deletions
+32
-5
lm_eval/models/ggml.py
lm_eval/models/ggml.py
+19
-5
tests/test_ggml.py
tests/test_ggml.py
+13
-0
tests/testdata/ggml_test_18f981234b6b471823bff9f977aad7f72439244c6c4d5f091b1f0984a71c8f11.pkl
...b471823bff9f977aad7f72439244c6c4d5f091b1f0984a71c8f11.pkl
+0
-0
tests/testdata/ggml_test_e768167d669b5de84c99743c4b55bc85889d4894d1901d9f955626e0622059a6.pkl
...b5de84c99743c4b55bc85889d4894d1901d9f955626e0622059a6.pkl
+0
-0
No files found.
lm_eval/models/ggml.py
View file @
b56dee4e
import
requests
import
requests
import
logging
import
logging
import
time
import
time
from
lm_eval.utils
import
Reorderer
from
lm_eval.base
import
BaseLM
from
tqdm
import
tqdm
from
tqdm
import
tqdm
from
requests.exceptions
import
RequestException
from
requests.exceptions
import
RequestException
from
lm_eval.utils
import
Reorderer
from
lm_eval.base
import
BaseLM
logger
=
logging
.
getLogger
(
__name__
)
logger
=
logging
.
getLogger
(
__name__
)
def
ggml_completion
(
base_url
,
retries
=
3
,
delay
=
5
,
**
kwargs
):
def
ggml_completion
(
base_url
,
retries
=
3
,
delay
=
5
,
**
kwargs
):
...
@@ -74,6 +75,20 @@ class GGMLLM(BaseLM):
...
@@ -74,6 +75,20 @@ class GGMLLM(BaseLM):
res
.
append
(
None
)
# Add default value in case of error
res
.
append
(
None
)
# Add default value in case of error
return
reorderer
.
get_original
(
res
)
return
reorderer
.
get_original
(
res
)
def
loglikelihood_rolling
(
self
,
requests
):
results
=
[]
for
request
in
requests
:
logprobs
=
[]
for
i
in
range
(
0
,
len
(
request
),
self
.
max_length
):
chunk
=
request
[
i
:
i
+
self
.
max_length
]
chunk_loglikelihood
=
self
.
loglikelihood
([(
chunk
,
request
[
i
+
1
:
i
+
self
.
max_length
+
1
])])
logprobs
.
extend
(
chunk_loglikelihood
)
avg_loglikelihood
=
sum
([
logprob
for
logprob
,
_
in
logprobs
])
/
len
(
logprobs
)
results
.
append
((
avg_loglikelihood
,
True
))
return
results
def
_model_call
(
self
,
inps
):
def
_model_call
(
self
,
inps
):
...
@@ -100,9 +115,8 @@ class GGMLLM(BaseLM):
...
@@ -100,9 +115,8 @@ class GGMLLM(BaseLM):
raise
NotImplementedError
()
raise
NotImplementedError
()
@
property
@
property
def
max_length
(
self
):
def
max_length
(
self
):
# Placeholder implementation
return
1024
raise
NotImplementedError
()
@
property
@
property
def
max_gen_toks
(
self
):
def
max_gen_toks
(
self
):
...
...
tests/test_ggml.py
View file @
b56dee4e
...
@@ -62,5 +62,18 @@ class GGMLLMTest(unittest.TestCase):
...
@@ -62,5 +62,18 @@ class GGMLLMTest(unittest.TestCase):
expected_res
=
[
"generated text until stop1"
,
"generated text until stop1"
]
expected_res
=
[
"generated text until stop1"
,
"generated text until stop1"
]
self
.
assertEqual
(
res
,
expected_res
)
self
.
assertEqual
(
res
,
expected_res
)
@
patch
(
'lm_eval.models.ggml.ggml_completion'
,
side_effect
=
ggml_completion_mock
)
def
test_loglikelihood_rolling
(
self
,
ggml_completion_mock
):
lm
=
GGMLLM
(
base_url
)
# Test loglikelihood_rolling
requests
=
[
"input1"
,
"input2"
]
res
=
lm
.
loglikelihood_rolling
(
requests
)
# Assert the loglikelihood_rolling response is correct
expected_res
=
[(
-
1.2345
,
True
),
(
-
1.2345
,
True
)]
self
.
assertEqual
(
res
,
expected_res
)
if
__name__
==
"__main__"
:
if
__name__
==
"__main__"
:
unittest
.
main
()
unittest
.
main
()
tests/testdata/ggml_test_18f981234b6b471823bff9f977aad7f72439244c6c4d5f091b1f0984a71c8f11.pkl
0 → 100644
View file @
b56dee4e
File added
tests/testdata/ggml_test_e768167d669b5de84c99743c4b55bc85889d4894d1901d9f955626e0622059a6.pkl
0 → 100644
View file @
b56dee4e
File added
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