-
Notifications
You must be signed in to change notification settings - Fork 12
/
ifeval.py
177 lines (166 loc) · 6.79 KB
/
ifeval.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
import os
from typing import Any, Optional
from eureka_ml_insights.core import (
DataProcessing,
Inference,
PromptProcessing,
)
from eureka_ml_insights.core.eval_reporting import EvalReporting
from eureka_ml_insights.data_utils import ColumnRename
from eureka_ml_insights.data_utils.data import (
DataLoader,
DataReader,
HFDataReader,
)
from eureka_ml_insights.data_utils.transform import RunPythonTransform
from eureka_ml_insights.metrics.ifeval_metrics import IFEvalMetric
from eureka_ml_insights.metrics.reports import (
AverageAggregator,
TwoColumnSumAverageAggregator,
)
from .config import (
AggregatorConfig,
DataProcessingConfig,
DataSetConfig,
EvalReportingConfig,
InferenceConfig,
MetricConfig,
ModelConfig,
PipelineConfig,
PromptProcessingConfig,
)
from .experiment_config import ExperimentConfig
class IFEval_PIPELINE(ExperimentConfig):
"""This class specifies the config for running IFEval benchmark on any model"""
def configure_pipeline(
self, model_config: ModelConfig, resume_from: str = None,
**kwargs: dict[str, Any]) -> PipelineConfig:
# data preprocessing
self.data_processing_comp = PromptProcessingConfig(
component_type=PromptProcessing,
data_reader_config=DataSetConfig(
HFDataReader,
{
"path": "google/IFEval",
"split": "train",
},
),
output_dir=os.path.join(self.log_dir, "data_processing_output"),
)
# inference component
self.inference_comp = InferenceConfig(
component_type=Inference,
model_config=model_config,
data_loader_config=DataSetConfig(
DataLoader,
{"path": os.path.join(self.data_processing_comp.output_dir, "transformed_data.jsonl")},
),
output_dir=os.path.join(self.log_dir, "inference_result"),
resume_from=resume_from,
)
# Configure the evaluation and reporting component for evaluation and dataset level aggregation
self.evalreporting_comp = EvalReportingConfig(
component_type=EvalReporting,
data_reader_config=DataSetConfig(
DataReader,
{
"path": os.path.join(self.inference_comp.output_dir, "inference_result.jsonl"),
"format": ".jsonl",
"transform": ColumnRename(name_mapping={"model_output": "response"}),
},
),
metric_config=MetricConfig(IFEvalMetric),
aggregator_configs=[
AggregatorConfig(
AverageAggregator,
{
"column_names": [
"IFEvalMetric_strict_follow_all_instructions",
"IFEvalMetric_loose_follow_all_instructions",
],
"filename_base": "IFEvalAccuracyMetrics_Aggregated",
},
),
AggregatorConfig(
TwoColumnSumAverageAggregator,
{
"numerator_column_name": "IFEvalMetric_strict_follow_instruction_list_sum",
"denominator_column_name": "IFEvalMetric_strict_instruction_list_len",
"filename_base": "IFEvalStrictInfoFollowRateMetric_Aggregated",
},
),
AggregatorConfig(
TwoColumnSumAverageAggregator,
{
"numerator_column_name": "IFEvalMetric_loose_follow_instruction_list_sum",
"denominator_column_name": "IFEvalMetric_loose_instruction_list_len",
"filename_base": "IFEvalLooseInfoFollowRateMetric_Aggregated",
},
),
],
output_dir=os.path.join(self.log_dir, "eval_report"),
)
# Configure the eval post processing component to explode instruction types
self.eval_post_processing_comp = DataProcessingConfig(
component_type=DataProcessing,
data_reader_config=DataSetConfig(
DataReader,
{
"path": os.path.join(self.evalreporting_comp.output_dir, "metric_results.jsonl"),
"format": ".jsonl",
"transform": RunPythonTransform(
"df = df.explode(['instruction_id_list', 'IFEvalMetric_tier0_instructions', "
" 'IFEvalMetric_strict_follow_instruction_list', "
" 'IFEvalMetric_loose_follow_instruction_list']) "
),
},
),
output_dir=os.path.join(self.log_dir, "metric_post_processing_output"),
)
# Configure the reporting component for instruction level aggregation
self.instruction_level_evalreporting_comp = EvalReportingConfig(
component_type=EvalReporting,
data_reader_config=DataSetConfig(
DataReader,
{
"path": os.path.join(self.eval_post_processing_comp.output_dir, "transformed_data.jsonl"),
"format": ".jsonl",
},
),
aggregator_configs=[
AggregatorConfig(
AverageAggregator,
{
"column_names": [
"IFEvalMetric_strict_follow_instruction_list",
"IFEvalMetric_loose_follow_instruction_list",
],
"group_by": "instruction_id_list",
"filename_base": "IFEvalAccuracyMetrics_GroupByInstructionID",
},
),
AggregatorConfig(
AverageAggregator,
{
"column_names": [
"IFEvalMetric_strict_follow_instruction_list",
"IFEvalMetric_loose_follow_instruction_list",
],
"group_by": "IFEvalMetric_tier0_instructions",
"filename_base": "IFEvalAccuracyMetrics_GroupByTier0Instructions",
},
),
],
output_dir=os.path.join(self.log_dir, "instruction_level_eval_report"),
)
# Configure the pipeline
return PipelineConfig(
[
self.data_processing_comp,
self.inference_comp,
self.evalreporting_comp,
self.eval_post_processing_comp,
self.instruction_level_evalreporting_comp,
],
self.log_dir,
)