class_docstr: An utility API to create function_hook callbacks to check whether the outputs of all layers have NaN or inf as their values.
  During forward and backward execution, passed as function_hook,
  this API reports ValueError if at least one of all layer outputs has Nan or inf as its values.
  Otherwise, all tensors passed to next layer or function as is.
  
  Example:
  
  .. code-block:: python
  
      pred = model(...)
  
      from nnabla.utils.inspection import NanInfTracer
      nit = NanInfTracer(trace_inf=True, trace_nan=True, need_details=True)
  
      with nit.trace():
          pred.forward(function_post_hook=nit.forward_post_hook)
          pred.backward(function_post_hook=nit.backward_post_hook)
class_docstr_tok: ["An","utility","API","to","create","function_hook","callbacks","to","check","whether","the","outputs","of","all","layers","have","NaN","or","inf","as","their","values",".","During","forward","and","backward","execution",",","passed","as","function_hook",",","this","API","reports","ValueError","if","at","least","one","of","all","layer","outputs","has","Nan","or","inf","as","its","values",".","Otherwise",",","all","tensors","passed","to","next","layer","or","function","as","is",".","Example",":","..","code-block",":",":","python","pred","=","model","(","...",")","from","nnabla.utils.inspection","import","NanInfTracer","nit","=","NanInfTracer","(","trace_inf=True",",","trace_nan=True",",","need_details=True",")","with","nit.trace","(",")",":","pred.forward","(","function_post_hook=nit.forward_post_hook",")","pred.backward","(","function_post_hook=nit.backward_post_hook",")"]
code: def __init__(self, trace_nan=True, trace_inf=True, need_details=True):
      super(NanInfTracer, self).__init__()
  
      self.trace_nan = trace_nan
      self.trace_inf = trace_inf
      self.need_details = need_details
      self.key_to_stat_fwd = OrderedDict()
      self.key_to_stat_bwd = OrderedDict()
  
      _msg_general = "The {} output of the function '{}' (rank: {}) has nan or inf as its values."
      _msg_detail = (
          """
          Function details: 
              function type: {}
              shapes of inputs: {} 
              shapes of outputs: {}
              function args: {}
          """
          if self.need_details
          else ""
      )
  
      self._msg = _msg_general + _msg_detail
      self._msg_keys = [
          "name",
          "rank",
          "function_type",
          "input_shapes",
          "output_shapes",
          "function_args",
      ]
  
file_path: nnabla/python/src/nnabla/utils/inspection/value_trace.py
imports: from __future__ import absolute_import
  from collections import OrderedDict
  from contextlib import contextmanager
  import nnabla.functions
  from .base import FunctionHookCallbackBase
label_desc: Use image node_id 1 to create a new NanInfTracer object from inherited base classes: FunctionHookCallbackBase with example: obj = NanInfTracer(trace_nan, trace_inf, need_details)