self.log with Metric in ddp
def validation_epoch_end(self, outputs):
    self.log('metric', self.metric.compute()) # rank = 0

def validation_epoch_end(self, outputs):
    out = self.metric.compute()
    self.log('metric', out) # rank =0

def validation_epoch_end(self, outputs):
    if self.global_rank == 0:
        out = self.metric.compute()
        self.log('metric', out) # rank =0
    dist.barrier()

global_rank
The global_rank of this LightningModule. Lightning saves logs, weights etc only from global_rank = 0. You normally do not need to use this property
Global rank refers to the index of that GPU across ALL GPUs. For example, if using 10 machines, each with 4 GPUs, the 4th GPU on the 10th machine has global_rank = 39

As the doc says, self.log will be call when global_rank = 0, but metric.compute will auto call self.reset().
So which example will work correctly?