Skip to content

Commit

Permalink
indent and cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
MikhailKardash committed Oct 24, 2024
1 parent ab1ffb1 commit e137f79
Showing 1 changed file with 9 additions and 18 deletions.
27 changes: 9 additions & 18 deletions harness/determined/pytorch/deepspeed/_deepspeed_trial.py
Original file line number Diff line number Diff line change
Expand Up @@ -813,24 +813,15 @@ def _validate(self, searcher_op: Optional[core.SearcherOperation] = None) -> Dic
if isinstance(metric, torch.Tensor):
metric = metric.cpu().detach().numpy()
vld_metrics[name] = metric
# Verify validation metric names are the same across batches.
if keys is None:
keys = vld_metrics.keys()
else:
if keys != vld_metrics.keys():
raise ValueError(
"Validation metric names must match across all batches of data: "
f"{keys} != {vld_metrics.keys()}.",
)
if not isinstance(vld_metrics, dict):
raise TypeError(
"validation_metrics() must return a "
"dictionary of string names to Tensor "
"metrics; "
f"got {vld_metrics}.",
)
# TODO: For performance perform -> cpu() only at the end of validation.
batch_metrics.append(pytorch._convert_metrics_to_numpy(vld_metrics))
# Verify validation metric names are the same across batches.
if keys is None:
keys = vld_metrics.keys()
else:
if keys != vld_metrics.keys():
raise ValueError(
"Validation metric names must match across all batches of data: "
f"{keys} != {vld_metrics.keys()}.",
)
if self.test_mode:
break

Expand Down

0 comments on commit e137f79

Please sign in to comment.