Skip to content

Commit

Permalink
bug fix for logging
Browse files Browse the repository at this point in the history
value
Out[35]: tensor(3211., device='cuda:0')
value.mean() * batch_size  / batch_size
Out[36]: tensor(3210.9998, device='cuda:0')
value.type(torch.float64).mean() * batch_size / batch_size
Out[37]: tensor(3211., device='cuda:0', dtype=torch.float64)
  • Loading branch information
qqueing authored Oct 22, 2021
1 parent 8482c28 commit f018121
Showing 1 changed file with 3 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -185,13 +185,13 @@ def __init__(self, metadata: _Metadata, is_tensor: bool) -> None:
self.meta = metadata
self.has_reset = False
if is_tensor:
self.add_state("value", torch.tensor(0, dtype=torch.float), dist_reduce_fx=torch.sum)
self.add_state("value", torch.tensor(0, dtype=torch.float64), dist_reduce_fx=torch.sum)
if self.meta.is_mean_reduction:
self.add_state("cumulated_batch_size", torch.tensor(0, dtype=torch.float), dist_reduce_fx=torch.sum)
self.add_state("cumulated_batch_size", torch.tensor(0, dtype=torch.float64), dist_reduce_fx=torch.sum)

def update(self, value: _IN_METRIC, batch_size: torch.Tensor) -> None:
if self.is_tensor:
value = value.float()
value = value.type(torch.float64)
# performance: no need to accumulate on values only logged on_step
if self.meta.on_step and not self.meta.on_epoch:
self._forward_cache = self.value = self.meta.sync(value)
Expand Down

0 comments on commit f018121

Please sign in to comment.