def _check_and_accumulate_gradients(self, batch_size: int, grad_scaler: Optional[GradScaler]) -> bool:
    'Check if gradients are valid, accumulate and return True; otherwise, reset and return False'
    assert ((not self.use_local_updates) and (not self.auxiliary))
    if ((grad_scaler is not None) and (not grad_scaler.are_grads_finite(self))):
        logger.log(self.status_loglevel, 'Encountered incorrect value in fp16 grads, resetting local gradients')
        self.tracker.report_local_progress(self.local_epoch, samples_accumulated=0)
        self.grad_averager.reset_accumulated_grads_()
        return False
    self.grad_averager.accumulate_grads_(batch_size)
    self.tracker.report_local_progress(self.local_epoch, self.grad_averager.local_samples_accumulated)
    return True
Check if gradients are valid, accumulate and return True; otherwise, reset and return False
def _check_and_accumulate_gradients(self, batch_size: int, grad_scaler: Optional[GradScaler]) -> bool:
    
    assert ((not self.use_local_updates) and (not self.auxiliary))
    if ((grad_scaler is not None) and (not grad_scaler.are_grads_finite(self))):
        logger.log(self.status_loglevel, 'Encountered incorrect value in fp16 grads, resetting local gradients')
        self.tracker.report_local_progress(self.local_epoch, samples_accumulated=0)
        self.grad_averager.reset_accumulated_grads_()
        return False
    self.grad_averager.accumulate_grads_(batch_size)
    self.tracker.report_local_progress(self.local_epoch, self.grad_averager.local_samples_accumulated)
    return True