@@ -63,6 +63,9 @@ def _eval_by_dataset(
6363) -> Tuple [float , Dict [str , Dict [str , float ]]]:
6464 """Evaluate with computing metric on total samples(default process).
6565
66+ NOTE: This is the default evaluation method as general for most cases, but may not
67+ memory-efficiency for large dataset or large output.
68+
6669 Args:
6770 solver (solver.Solver): Main Solver.
6871 epoch_id (int): Epoch id.
@@ -159,6 +162,7 @@ def _eval_by_dataset(
159162
160163 metric_dict_group : Dict [str , Dict [str , float ]] = misc .PrettyOrderedDict ()
161164 for metric_name , metric_func in _validator .metric .items ():
165+ # NOTE: compute metric with entire output and label
162166 metric_dict = metric_func (all_output , all_label )
163167 metric_dict_group [metric_name ] = {
164168 k : float (v ) for k , v in metric_dict .items ()
@@ -189,6 +193,10 @@ def _eval_by_batch(
189193) -> Tuple [float , Dict [str , Dict [str , float ]]]:
190194 """Evaluate with computing metric by batch, which is memory-efficient.
191195
196+ NOTE: This is a evaluation function for large dataset or large output, as is more
197+ memory-efficiency than evaluating by dataset, but less general because some metric
198+ is not independent among samples, e.g. L2 relative error.
199+
192200 Args:
193201 solver (solver.Solver): Main Solver.
194202 epoch_id (int): Epoch id.
@@ -270,7 +278,10 @@ def _eval_by_batch(
270278 # concatenate all metric and discard metric of padded sample(s)
271279 for metric_name , metric_dict in metric_dict_group .items ():
272280 for var_name , metric_value in metric_dict .items ():
281+ # NOTE: concat all metric(scalars) into metric vector
273282 metric_value = paddle .concat (metric_value )[:num_samples ]
283+ # NOTE: compute metric via averaging metric vector,
284+ # this might be not general for certain evaluation case
274285 metric_value = float (metric_value .mean ())
275286 metric_dict_group [metric_name ][var_name ] = metric_value
276287 metric_str = f"{ _validator .name } /{ metric_name } .{ var_name } "
0 commit comments