Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Properly handle empty metric_names passed to Trainer._filter_metrics #2700

Merged
merged 6 commits into from
Nov 9, 2023
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions composer/core/evaluator.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,11 +86,10 @@ def __init__(
self.label = label
self.dataloader = ensure_data_spec(dataloader)

self.metric_names = []
if metric_names is not None:
if not isinstance(metric_names, list):
raise ValueError(f'``metric_names`` should be a list of strings, not a {type(metric_names)}')
self.metric_names = metric_names
self.metric_names = metric_names
irenedea marked this conversation as resolved.
Show resolved Hide resolved

self.subset_num_batches = subset_num_batches
self._eval_interval = None
Expand Down
13 changes: 6 additions & 7 deletions composer/trainer/trainer.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,14 +106,13 @@ def _get_default_scheduler_frequency(schedulers: Optional[Union[Scheduler, Seque
def _filter_metrics(metrics: Dict[str, Metric], metric_names: Optional[List[str]]) -> Dict[str, Metric]:
"""Filter the metrics based on the given metric_names as regex strings (e.g. 'Accuracy', 'f1' for 'BinaryF1Score', 'Top-.' for 'Top-1 Accuracy' and 'Top-2 Accuracy', etc). If no metric_names are provided, all metrics will be returned."""
metrics = deepcopy(metrics)
if not metric_names:
if metric_names is None:
return metrics
else:
filtered_metrics = {}
for name, metric in metrics.items():
if any(re.match(f'.*{metric_name}.*', name, re.IGNORECASE) for metric_name in metric_names):
filtered_metrics[name] = metric
return filtered_metrics
filtered_metrics = {}
for name, metric in metrics.items():
if any(re.match(f'.*{metric_name}.*', name, re.IGNORECASE) for metric_name in metric_names):
filtered_metrics[name] = metric
return filtered_metrics


def _validate_precision(precision: Precision, device: Device):
Expand Down
Loading