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
408115ea
Unverified
Commit
408115ea
authored
Oct 20, 2023
by
Lintang Sutawika
Committed by
GitHub
Oct 20, 2023
Browse files
Merge pull request #935 from EleutherAI/fix-default-metric-call
parents
cf617ab1
1428ad57
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
55 additions
and
20 deletions
+55
-20
lm_eval/api/metrics.py
lm_eval/api/metrics.py
+14
-0
lm_eval/api/registry.py
lm_eval/api/registry.py
+8
-8
lm_eval/api/task.py
lm_eval/api/task.py
+10
-5
lm_eval/models/huggingface.py
lm_eval/models/huggingface.py
+18
-4
lm_eval/tasks/__init__.py
lm_eval/tasks/__init__.py
+2
-1
lm_eval/tasks/benchmarks/pythia.yaml
lm_eval/tasks/benchmarks/pythia.yaml
+1
-1
lm_eval/tasks/super_glue/boolq/seq2seq.yaml
lm_eval/tasks/super_glue/boolq/seq2seq.yaml
+2
-1
No files found.
lm_eval/api/metrics.py
View file @
408115ea
...
@@ -5,6 +5,7 @@ import numpy as np
...
@@ -5,6 +5,7 @@ import numpy as np
import
sacrebleu
import
sacrebleu
import
sklearn.metrics
import
sklearn.metrics
import
random
import
random
import
evaluate
from
lm_eval.api.registry
import
register_metric
,
register_aggregation
from
lm_eval.api.registry
import
register_metric
,
register_aggregation
...
@@ -135,6 +136,19 @@ def acc_mutual_info_fn(items): # This is a passthrough function
...
@@ -135,6 +136,19 @@ def acc_mutual_info_fn(items): # This is a passthrough function
return
items
return
items
exact_match
=
evaluate
.
load
(
"exact_match"
)
@
register_metric
(
metric
=
"exact_match"
,
higher_is_better
=
True
,
output_type
=
"generate_until"
,
aggregation
=
"mean"
,
)
def
exact_match_fn
(
**
kwargs
):
return
exact_match
.
compute
(
**
kwargs
)
@
register_metric
(
@
register_metric
(
metric
=
"perplexity"
,
metric
=
"perplexity"
,
higher_is_better
=
False
,
higher_is_better
=
False
,
...
...
lm_eval/api/registry.py
View file @
408115ea
...
@@ -68,10 +68,10 @@ def register_group(name):
...
@@ -68,10 +68,10 @@ def register_group(name):
return
decorate
return
decorate
AGGREGATION_REGISTRY
=
{}
DEFAULT_AGGREGATION_REGISTRY
=
{}
METRIC_REGISTRY
=
{}
OUTPUT_TYPE_REGISTRY
=
{}
OUTPUT_TYPE_REGISTRY
=
{}
METRIC_REGISTRY
=
{}
METRIC_AGGREGATION_REGISTRY
=
{}
AGGREGATION_REGISTRY
=
{}
HIGHER_IS_BETTER_REGISTRY
=
{}
HIGHER_IS_BETTER_REGISTRY
=
{}
DEFAULT_METRIC_REGISTRY
=
{
DEFAULT_METRIC_REGISTRY
=
{
...
@@ -95,8 +95,7 @@ def register_metric(**args):
...
@@ -95,8 +95,7 @@ def register_metric(**args):
for
key
,
registry
in
[
for
key
,
registry
in
[
(
"metric"
,
METRIC_REGISTRY
),
(
"metric"
,
METRIC_REGISTRY
),
(
"higher_is_better"
,
HIGHER_IS_BETTER_REGISTRY
),
(
"higher_is_better"
,
HIGHER_IS_BETTER_REGISTRY
),
# ("output_type", OUTPUT_TYPE_REGISTRY),
(
"aggregation"
,
METRIC_AGGREGATION_REGISTRY
),
(
"aggregation"
,
DEFAULT_AGGREGATION_REGISTRY
),
]:
]:
if
key
in
args
:
if
key
in
args
:
...
@@ -158,12 +157,13 @@ def get_aggregation(name):
...
@@ -158,12 +157,13 @@ def get_aggregation(name):
)
)
def
get_default_aggregation
(
metric_name
):
def
get_metric_aggregation
(
name
):
try
:
try
:
return
DEFAULT
_AGGREGATION_REGISTRY
[
metric_
name
]
return
METRIC
_AGGREGATION_REGISTRY
[
name
]
except
KeyError
:
except
KeyError
:
eval_logger
.
warning
(
eval_logger
.
warning
(
f
"No default aggregation metric for metric '
{
metric_name
}
'!"
"{} metric is not assigned a default aggregation!"
.
format
(
name
),
)
)
...
...
lm_eval/api/task.py
View file @
408115ea
...
@@ -33,7 +33,7 @@ from lm_eval.api.metrics import (
...
@@ -33,7 +33,7 @@ from lm_eval.api.metrics import (
from
lm_eval.api.registry
import
(
from
lm_eval.api.registry
import
(
get_metric
,
get_metric
,
get_aggregation
,
get_aggregation
,
get_
default
_aggregation
,
get_
metric
_aggregation
,
is_higher_better
,
is_higher_better
,
DEFAULT_METRIC_REGISTRY
,
DEFAULT_METRIC_REGISTRY
,
OUTPUT_TYPE_REGISTRY
,
OUTPUT_TYPE_REGISTRY
,
...
@@ -538,12 +538,14 @@ class ConfigurableTask(Task):
...
@@ -538,12 +538,14 @@ class ConfigurableTask(Task):
self
.
_aggregation_list
=
{}
self
.
_aggregation_list
=
{}
self
.
_higher_is_better
=
{}
self
.
_higher_is_better
=
{}
_metric_list
=
DEFAULT_METRIC_REGISTRY
[
self
.
config
.
output_type
]
if
self
.
config
.
metric_list
is
None
:
if
self
.
config
.
metric_list
is
None
:
# TODO: handle this in TaskConfig.__post_init__ ?
# TODO: handle this in TaskConfig.__post_init__ ?
_metric_list
=
DEFAULT_METRIC_REGISTRY
[
self
.
config
.
output_type
]
for
metric_name
in
_metric_list
:
for
metric_name
in
_metric_list
:
self
.
_metric_fn_list
[
metric_name
]
=
get_metric
(
metric_name
)
self
.
_metric_fn_list
[
metric_name
]
=
get_metric
(
metric_name
)
self
.
_aggregation_list
[
metric_name
]
=
get_default_aggregation
(
self
.
_metric_fn_kwargs
[
metric_name
]
=
{}
self
.
_aggregation_list
[
metric_name
]
=
get_metric_aggregation
(
metric_name
metric_name
)
)
self
.
_higher_is_better
[
metric_name
]
=
is_higher_better
(
metric_name
)
self
.
_higher_is_better
[
metric_name
]
=
is_higher_better
(
metric_name
)
...
@@ -586,7 +588,7 @@ class ConfigurableTask(Task):
...
@@ -586,7 +588,7 @@ class ConfigurableTask(Task):
]
]
else
:
else
:
INV_AGG_REGISTRY
=
{
v
:
k
for
k
,
v
in
AGGREGATION_REGISTRY
.
items
()}
INV_AGG_REGISTRY
=
{
v
:
k
for
k
,
v
in
AGGREGATION_REGISTRY
.
items
()}
metric_agg
=
get_
default
_aggregation
(
metric_name
)
metric_agg
=
get_
metric
_aggregation
(
metric_name
)
eval_logger
.
warning
(
eval_logger
.
warning
(
f
"[Task:
{
self
.
_config
.
task
}
] metric
{
metric_name
}
is defined, but aggregation is not. "
f
"[Task:
{
self
.
_config
.
task
}
] metric
{
metric_name
}
is defined, but aggregation is not. "
f
"using default "
f
"using default "
...
@@ -687,7 +689,10 @@ class ConfigurableTask(Task):
...
@@ -687,7 +689,10 @@ class ConfigurableTask(Task):
for
choice
in
check_choices
:
for
choice
in
check_choices
:
choice_has_whitespace
=
True
if
choice
[
0
].
isspace
()
else
False
choice_has_whitespace
=
True
if
choice
[
0
].
isspace
()
else
False
delimiter_has_whitespace
=
(
delimiter_has_whitespace
=
(
True
if
self
.
config
.
target_delimiter
[
-
1
].
isspace
()
else
False
True
if
self
.
config
.
target_delimiter
.
rstrip
()
==
self
.
config
.
target_delimiter
else
False
)
)
if
delimiter_has_whitespace
and
choice_has_whitespace
:
if
delimiter_has_whitespace
and
choice_has_whitespace
:
...
...
lm_eval/models/huggingface.py
View file @
408115ea
...
@@ -663,8 +663,16 @@ class HFLM(LM):
...
@@ -663,8 +663,16 @@ class HFLM(LM):
chunks
=
utils
.
chunks
(
chunks
=
utils
.
chunks
(
re_ord
.
get_reordered
(),
re_ord
.
get_reordered
(),
n
=
self
.
batch_size
if
self
.
batch_size
!=
"auto"
else
override_bs
if
override_bs
is
not
None
else
0
,
n
=
self
.
batch_size
fn
=
self
.
_batch_scheduler
if
self
.
batch_size
==
"auto"
and
n_reordered_requests
>
0
and
not
override_bs
else
None
,
if
self
.
batch_size
!=
"auto"
else
override_bs
if
override_bs
is
not
None
else
0
,
fn
=
self
.
_batch_scheduler
if
self
.
batch_size
==
"auto"
and
n_reordered_requests
>
0
and
not
override_bs
else
None
,
)
)
for
chunk
in
tqdm
(
chunks
,
disable
=
(
disable_tqdm
or
(
self
.
rank
!=
0
))):
for
chunk
in
tqdm
(
chunks
,
disable
=
(
disable_tqdm
or
(
self
.
rank
!=
0
))):
...
@@ -840,8 +848,14 @@ class HFLM(LM):
...
@@ -840,8 +848,14 @@ class HFLM(LM):
for
key
,
re_ord
in
re_ords
.
items
():
for
key
,
re_ord
in
re_ords
.
items
():
chunks
=
utils
.
chunks
(
chunks
=
utils
.
chunks
(
re_ord
.
get_reordered
(),
re_ord
.
get_reordered
(),
n
=
self
.
batch_size
if
self
.
batch_size
!=
"auto"
else
adaptive_batch_size
if
adaptive_batch_size
is
not
None
else
0
,
n
=
self
.
batch_size
fn
=
self
.
_batch_scheduler
if
self
.
batch_size
==
"auto"
and
not
adaptive_batch_size
else
None
,
if
self
.
batch_size
!=
"auto"
else
adaptive_batch_size
if
adaptive_batch_size
is
not
None
else
0
,
fn
=
self
.
_batch_scheduler
if
self
.
batch_size
==
"auto"
and
not
adaptive_batch_size
else
None
,
)
)
for
chunk
in
tqdm
(
chunks
,
disable
=
self
.
rank
!=
0
):
for
chunk
in
tqdm
(
chunks
,
disable
=
self
.
rank
!=
0
):
contexts
,
all_gen_kwargs
=
zip
(
*
chunk
)
contexts
,
all_gen_kwargs
=
zip
(
*
chunk
)
...
...
lm_eval/tasks/__init__.py
View file @
408115ea
...
@@ -15,7 +15,8 @@ from lm_eval.api.registry import (
...
@@ -15,7 +15,8 @@ from lm_eval.api.registry import (
import
logging
import
logging
eval_logger
=
logging
.
getLogger
(
'lm-eval'
)
eval_logger
=
logging
.
getLogger
(
"lm-eval"
)
def
register_configurable_task
(
config
:
Dict
[
str
,
str
])
->
int
:
def
register_configurable_task
(
config
:
Dict
[
str
,
str
])
->
int
:
SubClass
=
type
(
SubClass
=
type
(
...
...
lm_eval/tasks/benchmarks/pythia.yaml
View file @
408115ea
...
@@ -9,4 +9,4 @@ task:
...
@@ -9,4 +9,4 @@ task:
-
wsc
-
wsc
-
ai2_arc
-
ai2_arc
-
blimp
-
blimp
-
hendrycksTest*
-
mmlu
lm_eval/tasks/super_glue/boolq/seq2seq.yaml
View file @
408115ea
...
@@ -8,7 +8,8 @@ training_split: train
...
@@ -8,7 +8,8 @@ training_split: train
validation_split
:
validation
validation_split
:
validation
doc_to_text
:
"
{{passage}}
\n
Question:
{{question}}?
\n
Answer:"
doc_to_text
:
"
{{passage}}
\n
Question:
{{question}}?
\n
Answer:"
doc_to_target
:
label
doc_to_target
:
label
doc_to_choice
:
[
'
no'
,
'
yes'
]
doc_to_choice
:
[
'
no'
,
'
yes'
]
target_delimiter
:
"
"
generation_kwargs
:
generation_kwargs
:
until
:
until
:
-
"
\n\n
"
-
"
\n\n
"
...
...
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