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
1fdc005e
Unverified
Commit
1fdc005e
authored
Nov 03, 2023
by
Hailey Schoelkopf
Committed by
GitHub
Nov 03, 2023
Browse files
cleanup and fix variable names for GGUF model
parent
97bc9780
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
9 additions
and
23 deletions
+9
-23
lm_eval/models/gguf.py
lm_eval/models/gguf.py
+9
-23
No files found.
lm_eval/models/gguf.py
View file @
1fdc005e
...
@@ -10,14 +10,14 @@ from lm_eval.base import BaseLM
...
@@ -10,14 +10,14 @@ from lm_eval.base import BaseLM
logger
=
logging
.
getLogger
(
__name__
)
logger
=
logging
.
getLogger
(
__name__
)
def
get_result
(
logprobs
,
context_leng
h
t
):
def
get_result
(
logprobs
,
context_lengt
h
):
is_greedy
=
True
is_greedy
=
True
offsets
=
logprobs
[
'text_offset'
]
offsets
=
logprobs
[
'text_offset'
]
tokens
=
logprobs
[
'tokens'
]
tokens
=
logprobs
[
'tokens'
]
tokens_logprobs
=
logprobs
[
'token_logprobs'
]
tokens_logprobs
=
logprobs
[
'token_logprobs'
]
idx
=
0
idx
=
0
while
offsets
[
idx
]
<
context_leng
h
t
:
while
offsets
[
idx
]
<
context_lengt
h
:
idx
+=
1
idx
+=
1
continuation_logprobs
=
sum
(
tokens_logprobs
[
idx
:
-
1
])
continuation_logprobs
=
sum
(
tokens_logprobs
[
idx
:
-
1
])
for
i
in
range
(
idx
,
len
(
tokens
)):
for
i
in
range
(
idx
,
len
(
tokens
)):
...
@@ -32,21 +32,19 @@ def get_result(logprobs, context_lenght):
...
@@ -32,21 +32,19 @@ def get_result(logprobs, context_lenght):
class
GGUFLM
(
BaseLM
):
class
GGUFLM
(
BaseLM
):
def
__init__
(
self
,
base_url
,
truncate
=
False
):
def
__init__
(
self
,
base_url
,
max_length
=
2048
):
super
().
__init__
()
super
().
__init__
()
self
.
base_url
=
base_url
self
.
base_url
=
base_url
self
.
truncate
=
truncate
self
.
truncate
=
truncate
self
.
tokenizer
=
transformers
.
GPT2TokenizerFast
.
from_pretrained
(
"gpt2"
)
self
.
logprobs
=
10
self
.
logpobs
=
10
self
.
temperature
=
0.0
self
.
temperature
=
0.0
self
.
max_length
=
1024
self
.
max_length
=
max_length
self
.
vocab_size
=
self
.
tokenizer
.
vocab_size
def
gguf_completion
(
self
,
context
,
continuation
=
None
,
stop
=
None
,
retries
=
3
,
delay
=
5
,
**
kwargs
):
def
gguf_completion
(
self
,
context
,
continuation
=
None
,
stop
=
None
,
retries
=
3
,
delay
=
5
,
**
kwargs
):
for
_
in
range
(
retries
):
for
_
in
range
(
retries
):
try
:
try
:
prompt
=
context
prompt
=
context
request
=
{
'prompt'
:
prompt
,
'logprobs'
:
self
.
logpobs
,
request
=
{
'prompt'
:
prompt
,
'logprobs'
:
self
.
logp
r
obs
,
'temperature'
:
self
.
temperature
}
'temperature'
:
self
.
temperature
}
if
continuation
:
if
continuation
:
prompt
+=
continuation
prompt
+=
continuation
...
@@ -105,19 +103,7 @@ class GGUFLM(BaseLM):
...
@@ -105,19 +103,7 @@ class GGUFLM(BaseLM):
return
res
return
res
def
loglikelihood_rolling
(
self
,
requests
):
def
loglikelihood_rolling
(
self
,
requests
):
results
=
[]
raise
NotImplementedError
(
"loglikelihood_rolling not yet supported for GGUF models"
)
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
):
# Placeholder implementation
# Placeholder implementation
...
@@ -128,10 +114,10 @@ class GGUFLM(BaseLM):
...
@@ -128,10 +114,10 @@ class GGUFLM(BaseLM):
raise
NotImplementedError
()
raise
NotImplementedError
()
def
tok_encode
(
self
,
string
:
str
):
def
tok_encode
(
self
,
string
:
str
):
r
eturn
self
.
tokenizer
.
encode
(
string
,
add_special_tokens
=
False
)
r
aise
NotImplementedError
(
)
def
tok_decode
(
self
,
tokens
):
def
tok_decode
(
self
,
tokens
):
r
eturn
self
.
tokenizer
.
decode
(
tokens
)
r
aise
NotImplementedError
(
)
@
property
@
property
def
batch_size
(
self
):
def
batch_size
(
self
):
...
...
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