def _average_gradients_and_load_into_optimizer(self, maybe_step_control: Optional[StepControl]):
    'Run gradient averaging; on success, feed averaged gradients into optimizer; else, use local gradients'
    assert ((self.use_gradient_averaging and (maybe_step_control is None)) or maybe_step_control.triggered)
    averaged_gradients = False
    try:
        if (maybe_step_control is not None):
            group_info = maybe_step_control.result(self.averaging_timeout)
            logger.log(self.status_loglevel, f'Averaged gradients with {len(group_info)} peers')
            self._load_averaged_gradients_into_optimizer_()
            averaged_gradients = True
        else:
            logger.log(self.status_loglevel, f'Skipped averaging: there are no other peers')
    except BaseException as e:
        logger.log(self.status_loglevel, f'Averaging gradients failed with {repr(e)}')
    if (not averaged_gradients):
        self._load_local_gradients_into_optimizer()
Run gradient averaging; on success, feed averaged gradients into optimizer; else, use local gradients
def _average_gradients_and_load_into_optimizer(self, maybe_step_control: Optional[StepControl]):
    
    assert ((self.use_gradient_averaging and (maybe_step_control is None)) or maybe_step_control.triggered)
    averaged_gradients = False
    try:
        if (maybe_step_control is not None):
            group_info = maybe_step_control.result(self.averaging_timeout)
            logger.log(self.status_loglevel, f'Averaged gradients with {len(group_info)} peers')
            self._load_averaged_gradients_into_optimizer_()
            averaged_gradients = True
        else:
            logger.log(self.status_loglevel, f'Skipped averaging: there are no other peers')
    except BaseException as e:
        logger.log(self.status_loglevel, f'Averaging gradients failed with {repr(e)}')
    if (not averaged_gradients):
        self._load_local_gradients_into_optimizer()