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
77d4b087
Commit
77d4b087
authored
Feb 07, 2021
by
Leo Gao
Browse files
Fix caching
parent
1b467c57
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
9 additions
and
10 deletions
+9
-10
lm_eval/base.py
lm_eval/base.py
+9
-10
No files found.
lm_eval/base.py
View file @
77d4b087
...
...
@@ -275,13 +275,9 @@ import json
import
hashlib
from
sqlitedict
import
SqliteDict
def
hash_args
(
args
):
dat
=
b
""
for
arg
in
args
:
assert
isinstance
(
arg
,
str
)
or
isinstance
(
arg
,
int
)
dat
+=
str
(
arg
).
encode
()
dat
+=
b
"
\0
"
return
hashlib
.
sha256
(
dat
).
hexdigest
()
def
hash_args
(
attr
,
args
):
dat
=
json
.
dumps
([
attr
]
+
list
(
args
))
return
hashlib
.
sha256
(
dat
.
encode
(
'utf-8'
)).
hexdigest
()
class
CachingLM
:
...
...
@@ -298,7 +294,7 @@ class CachingLM:
# figure out which ones are cached and which ones are new
for
req
in
requests
:
hsh
=
attr
+
'_'
+
hash_args
(
req
)
hsh
=
hash_args
(
attr
,
req
)
if
hsh
in
self
.
dbdict
:
ob
=
self
.
dbdict
[
hsh
]
...
...
@@ -320,9 +316,9 @@ class CachingLM:
res
[
resptr
]
=
r
# caching
hsh
=
attr
+
'_'
+
hash_args
(
req
)
hsh
=
hash_args
(
attr
,
req
)
self
.
dbdict
[
hsh
]
=
r
self
.
dbdict
.
commit
()
return
res
return
fn
...
...
@@ -344,6 +340,9 @@ class Request:
def
__getitem__
(
self
,
i
):
return
Request
(
self
.
type
,
self
.
args
,
i
)
def
__eq__
(
self
,
other
):
return
self
.
type
==
other
.
type
and
self
.
args
==
other
.
args
and
self
.
index
==
other
.
index
class
RequestFactory
:
...
...
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