class_docstr: TensorBoard callback which writes metrics to the given log directory. Requires the TensorboardX library for python.
  
  Args:
      log_dir (str): The tensorboard log path for output
      comment (str): Descriptive comment to append to path
      visdom (bool): If true, log to visdom instead of tensorboard
      visdom_params (VisdomParams): Visdom parameter settings object, uses default if None
  
  State Requirements:
      - :attr:`torchbearer.state.MODEL`: PyTorch model
class_docstr_tok: ["TensorBoard","callback","which","writes","metrics","to","the","given","log","directory",".","Requires","the","TensorboardX","library","for","python",".","Args",":","log_dir","(","str",")",":","The","tensorboard","log","path","for","output","comment","(","str",")",":","Descriptive","comment","to","append","to","path","visdom","(","bool",")",":","If","true",",","log","to","visdom","instead","of","tensorboard","visdom_params","(","VisdomParams",")",":","Visdom","parameter","settings","object",",","uses","default","if","None","State","Requirements",":","-",":","attr",":","`","torchbearer.state.MODEL","`",":","PyTorch","model"]
docstr: Static method that recurses through `metric` until the `add_fn` can be applied. Useful when metric is an
  iterable of tensors so that the tensors can  all be passed to an `add_fn` such as writer.add_scalar.
  For example, if passed `metric` as [[A, B], [C, ], D, {'E': E}] then `add_fn` would be called on A, B, C, D and
  E and the respective tags (with base tag 'met') would be: met_0_0, met_0_1, met_1_0, met_2, met_E. Throws a
  warning if `add_fn` fails to parse a metric.
  
  Args:
      add_fn: Function to be called to log a metric, e.g. SummaryWriter.add_scalar
      tag: Tag under which to log the metric
      metric: Iterable of metrics.
      *args: Args for `add_fn`
      **kwargs: Keyword args for `add_fn`
  
  Returns:
docstr_tok: ["Static","method","that","recurses","through","`","metric","`","until","the","`","add_fn","`","can","be","applied",".","Useful","when","metric","is","an","iterable","of","tensors","so","that","the","tensors","can","all","be","passed","to","an","`","add_fn","`","such","as","writer.add_scalar",".","For","example",",","if","passed","`","metric","`","as","[","[","A",",","B","]",",","[","C",",","]",",","D",",","{","'","E","'",":","E","}","]","then","`","add_fn","`","would","be","called","on","A",",","B",",","C",",","D","and","E","and","the","respective","tags","(","with","base","tag","'met","'",")","would","be",":","met_0_0",",","met_0_1",",","met_1_0",",","met_2",",","met_E",".","Throws","a","warning","if","`","add_fn","`","fails","to","parse","a","metric",".","Args",":","add_fn",":","Function","to","be","called","to","log","a","metric",",","e.g",".","SummaryWriter.add_scalar","tag",":","Tag","under","which","to","log","the","metric","metric",":","Iterable","of","metrics",".","*","args",":","Args","for","`","add_fn","`","*","*","kwargs",":","Keyword","args","for","`","add_fn","`","Returns",":"]
code: def add_metric(add_fn, tag, metric, *args, **kwargs):
      """Static method that recurses through `metric` until the `add_fn` can be applied. Useful when metric is an
      iterable of tensors so that the tensors can  all be passed to an `add_fn` such as writer.add_scalar.
      For example, if passed `metric` as [[A, B], [C, ], D, {'E': E}] then `add_fn` would be called on A, B, C, D and
      E and the respective tags (with base tag 'met') would be: met_0_0, met_0_1, met_1_0, met_2, met_E. Throws a
      warning if `add_fn` fails to parse a metric.
  
      Args:
          add_fn: Function to be called to log a metric, e.g. SummaryWriter.add_scalar
          tag: Tag under which to log the metric
          metric: Iterable of metrics.
          *args: Args for `add_fn`
          **kwargs: Keyword args for `add_fn`
  
      Returns:
  
      """
      try:
          add_fn(tag, metric, *args, **kwargs)
      except NotImplementedError:
          try:
              for key, met in enumerate(metric):
                  if isinstance(metric, dict):
                      key, met = met, metric[met]
  
                  AbstractTensorBoard.add_metric(
                      add_fn,
                      tag + "_{}".format(key),
                      met,
                      *args,
                      **kwargs,
                  )
          except TypeError as e:
              warnings.warn(
                  "Failed to log metric to tensorboard with error: {}".format(
                      e
                  )
              )
      except Exception as e:
          warnings.warn(
              "Failed to log metric to tensorboard with error: {}".format(
                  e
              )
          )
  
imports: import copy
  import os
  import warnings
  import torch
  import torch.nn.functional
  import torchbearer
  from torchbearer.callbacks import Callback
label_desc: Use image node_id 5 for calling the AbstractTensorBoard obj's underlying member method code with example usage: obj.add_metric(add_fn, tag, metric) without return types