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
eb9c6a57
Commit
eb9c6a57
authored
Apr 24, 2024
by
lintangsutawika
Browse files
add group config
parent
cd0ad1b4
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
49 additions
and
0 deletions
+49
-0
lm_eval/api/task.py
lm_eval/api/task.py
+49
-0
No files found.
lm_eval/api/task.py
View file @
eb9c6a57
...
@@ -51,6 +51,55 @@ ALL_OUTPUT_TYPES = [
...
@@ -51,6 +51,55 @@ ALL_OUTPUT_TYPES = [
eval_logger
=
logging
.
getLogger
(
"lm-eval"
)
eval_logger
=
logging
.
getLogger
(
"lm-eval"
)
@
dataclass
class
GroupConfig
(
dict
):
group
:
Optional
[
Union
[
str
,
list
]]
=
None
aggregate_metric
:
Optional
[
str
]
=
False
aggregate_fn
:
Optional
[
str
]
=
"mean"
weight_by_size
:
Optional
[
str
]
=
False
def
__getitem__
(
self
,
item
):
return
getattr
(
self
,
item
)
def
__setitem__
(
self
,
item
,
value
):
return
setattr
(
self
,
item
,
value
)
def
to_dict
(
self
,
keep_callable
:
bool
=
False
)
->
dict
:
"""dumps the current config as a dictionary object, as a printable format.
null fields will not be printed.
Used for dumping results alongside full task configuration
:return: dict
A printable dictionary version of the TaskConfig object.
# TODO: should any default value in the TaskConfig not be printed?
"""
cfg_dict
=
asdict
(
self
)
# remove values that are `None`
for
k
,
v
in
list
(
cfg_dict
.
items
()):
if
v
is
None
:
cfg_dict
.
pop
(
k
)
elif
callable
(
v
):
cfg_dict
[
k
]
=
self
.
serialize_function
(
v
,
keep_callable
=
keep_callable
)
return
cfg_dict
def
serialize_function
(
self
,
value
:
Union
[
Callable
,
str
],
keep_callable
=
False
)
->
Union
[
Callable
,
str
]:
"""Serializes a given function or string.
If 'keep_callable' is True, the original callable is returned.
Otherwise, attempts to return the source code of the callable using 'getsource'.
"""
if
keep_callable
:
return
value
else
:
try
:
return
getsource
(
value
)
except
(
TypeError
,
OSError
):
return
str
(
value
)
@
dataclass
@
dataclass
class
TaskConfig
(
dict
):
class
TaskConfig
(
dict
):
# task naming/registry
# task naming/registry
...
...
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