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",")"]
docstr: Create callback function object which can be used as a function_post_hook argument of backward().
docstr_tok: ["Create","callback","function","object","which","can","be","used","as","a","function_post_hook","argument","of","backward","(",")","."]
code: def backward_post_hook(self):
      """
      Create callback function object which can be used as a function_post_hook argument of backward().
      """
      if not (self.trace_nan or self.trace_inf):
          return None
  
      # Perform F.isnan and then F.sum to check the output of incoming function contains the nan value.
      def callback(f):
          # For the first time to check this function.
          self._add_key(f, self.key_to_stat_bwd)
  
          # apply callback to check the outputs of this function has nan values or not.
          nan = []
          if self.trace_nan:
              nan = [F.sum(F.isnan(i.grad)) for i in f.inputs]
  
          inf = []
          if self.trace_inf:
              inf = [F.sum(F.isinf(i.grad)) for i in f.inputs]
  
          self.key_to_stat_bwd[f].update(
              {
                  "inf": inf,
                  "nan": nan,
                  # rank might be changed between each iteration.
                  "rank": f.rank,
              }
          )
  
      return callback
  
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 6 for calling the NanInfTracer obj's underlying member method code with example usage: obj.backward_post_hook() and returns: callback, None