code: def add_log_hooks_to_pytorch_module(self, module, name=None, prefix='', log_parameters=True, log_gradients=True, log_freq=0):
          
          if name is not None:
              prefix = prefix + name
  
          if log_parameters:
              def parameter_log_hook(module, input_, output, log_track):
                  if not log_track_update(log_track):
                      return
                  for name, parameter in module.named_parameters():
                      # for pytorch 0.3 Variables
                      if isinstance(parameter, torch.autograd.Variable):
                          data = parameter.data
                      else:
                          data = parameter
                      self.log_tensor_stats(
                          data.cpu(), 'parameters/' + prefix + name)
              log_track_params = log_track_init(log_freq)
              module.register_forward_hook(
                  lambda mod, inp, outp: parameter_log_hook(mod, inp, outp, log_track_params))
  
          if log_gradients:
              for name, parameter in module.named_parameters():
                  if parameter.requires_grad:
                      log_track_grad = log_track_init(log_freq)
                      self._hook_variable_gradient_stats(
                          parameter, 'gradients/' + prefix + name, log_track_grad)
docs: This instuments hooks into the pytorch module
          log_parameters - log parameters after a forward pass
          log_gradients - log gradients after a backward pass
          log_freq - log gradients/parameters every N batches