docstr: Log activations to tensorboard
docstr_tok: ["Log","activations","to","tensorboard"]
code: def _enable_activation_logging(self):
      """
      Log activations to tensorboard
      """
      if self._histogram_interval is not None:
          # To log activation histograms to the forward pass, we register
          # a hook on forward to capture the output tensors.
          # This uses a closure on self._log_histograms_this_batch to
          # determine whether to send the activations to tensorboard,
          # since we don't want them on every call.
          for _, module in self._model.named_modules():
              if not getattr(module, "should_log_activations", False):
                  # skip it
                  continue
  
              def hook(module_, inputs, outputs):
                  # pylint: disable=unused-argument,cell-var-from-loop
                  log_prefix = "activation_histogram/{0}".format(
                      module_.__class__
                  )
                  if self._log_histograms_this_batch:
                      if isinstance(outputs, torch.Tensor):
                          log_name = log_prefix
                          self._tensorboard.add_train_histogram(
                              log_name, outputs, self._batch_num_total
                          )
                      elif isinstance(outputs, (list, tuple)):
                          for i, output in enumerate(outputs):
                              log_name = "{0}_{1}".format(log_prefix, i)
                              self._tensorboard.add_train_histogram(
                                  log_name,
                                  output,
                                  self._batch_num_total,
                              )
                      elif isinstance(outputs, dict):
                          for k, tensor in list(outputs.items()):
                              log_name = "{0}_{1}".format(log_prefix, k)
                              self._tensorboard.add_train_histogram(
                                  log_name,
                                  tensor,
                                  self._batch_num_total,
                              )
                      else:
                          # skip it
                          pass
  
              module.register_forward_hook(hook)
  
imports: from __future__ import with_statement
  from __future__ import division
  from __future__ import absolute_import
  import logging
  import os
  import shutil
  import time
  import re
  import datetime
  import traceback
  import torch
  import torch.optim.lr_scheduler
  from torch.nn.parallel import replicate, parallel_apply
  from torch.nn.parallel.scatter_gather import scatter_kwargs, gather
  from allennlp.common import Params
  from allennlp.common.checks import ConfigurationError
  from allennlp.common.util import peak_memory_mb, gpu_memory_mb
  from allennlp.common.tqdm import Tqdm
  from allennlp.data.instance import Instance
  from allennlp.data.iterators.data_iterator import DataIterator
  from allennlp.models.model import Model
  from allennlp.nn import util
  from allennlp.training.learning_rate_schedulers import LearningRateScheduler
  from allennlp.training.optimizers import Optimizer
label_desc: Use image node_id 3 for calling the Trainer obj's underlying member method code with example usage: obj._enable_activation_logging() without return types