allennlp/training/tensorboard_writer.py
def log_parameter_and_gradient_statistics(self, model: Model, batch_grad_norm: float) -> None:
        """
        Send the mean and std of all parameters and gradients to tensorboard, as well
        as logging the average gradient norm.
        """
        if self._should_log_parameter_statistics:
            # Log parameter values to Tensorboard
            for name, param in model.named_parameters():
                if param.data.numel() > 0:
                    self.add_train_scalar("parameter_mean/" + name, param.data.mean())
                if param.data.numel() > 1:
                    self.add_train_scalar("parameter_std/" + name, param.data.std())
                if param.grad is not None:
                    if param.grad.is_sparse:

                        grad_data = param.grad.data._values()
                    else:
                        grad_data = param.grad.data

                    # skip empty gradients
                    if torch.prod(torch.tensor(grad_data.shape)).item() > 0:
                        self.add_train_scalar("gradient_mean/" + name, grad_data.mean())
                        if grad_data.numel() > 1:
                            self.add_train_scalar("gradient_std/" + name, grad_data.std())
                    else:
                        # no gradient for a parameter with sparse gradients
                        logger.info("No gradient for %s, skipping tensorboard logging.", name)
            # norm of gradients
            if batch_grad_norm is not None:
                self.add_train_scalar("gradient_norm", batch_grad_norm)

        Send the mean and std of all parameters and gradients to tensorboard, as well
        as logging the average gradient norm.
        
Send the mean and std of all parameters and gradients to tensorboard, as well
as logging the average gradient norm.
Send the mean and std of all parameters and gradients to tensorboard as well as logging the average gradient norm .
def log_parameter_and_gradient_statistics(self, model: Model, batch_grad_norm: float) -> None:
        if self._should_log_parameter_statistics:
            for name, param in model.named_parameters():
                if param.data.numel() > 0:
                    self.add_train_scalar("parameter_mean/" + name, param.data.mean())
                if param.data.numel() > 1:
                    self.add_train_scalar("parameter_std/" + name, param.data.std())
                if param.grad is not None:
                    if param.grad.is_sparse:
                        grad_data = param.grad.data._values()
                    else:
                        grad_data = param.grad.data
                    if torch.prod(torch.tensor(grad_data.shape)).item() > 0:
                        self.add_train_scalar("gradient_mean/" + name, grad_data.mean())
                        if grad_data.numel() > 1:
                            self.add_train_scalar("gradient_std/" + name, grad_data.std())
                    else:
                        logger.info("No gradient for %s, skipping tensorboard logging.", name)
            if batch_grad_norm is not None:
                self.add_train_scalar("gradient_norm", batch_grad_norm)
def log_parameter_and_gradient_statistics ( self , model : Model , batch_grad_norm : float ) -> None : if self . _should_log_parameter_statistics : for name , param in model . named_parameters ( ) : if param . data . numel ( ) > 0 : self . add_train_scalar ( "parameter_mean/" + name , param . data . mean ( ) ) if param . data . numel ( ) > 1 : self . add_train_scalar ( "parameter_std/" + name , param . data . std ( ) ) if param . grad is not None : if param . grad . is_sparse : grad_data = param . grad . data . _values ( ) else : grad_data = param . grad . data if torch . prod ( torch . tensor ( grad_data . shape ) ) . item ( ) > 0 : self . add_train_scalar ( "gradient_mean/" + name , grad_data . mean ( ) ) if grad_data . numel ( ) > 1 : self . add_train_scalar ( "gradient_std/" + name , grad_data . std ( ) ) else : logger . info ( "No gradient for %s, skipping tensorboard logging." , name ) if batch_grad_norm is not None : self . add_train_scalar ( "gradient_norm" , batch_grad_norm )
Send the mean and std of all parameters and gradients to tensorboard, as well
as logging the average gradient norm.
Send the mean and std of all parameters and gradients to tensorboard as well as logging the average gradient norm .
"""
        Send the mean and std of all parameters and gradients to tensorboard, as well
        as logging the average gradient norm.
        """ # Log parameter values to Tensorboard # skip empty gradients # no gradient for a parameter with sparse gradients # norm of gradients
self
model
Model
batch_grad_norm
float