code: def has_overflow(self, params):
          
          is_not_finite = 0
          for param in params:
              if param.grad_req != 'null':
                  grad = param.list_grad()[0]
                  is_not_finite += mx.nd.contrib.isnan(grad).sum()
                  is_not_finite += mx.nd.contrib.isinf(grad).sum()
          # NDArray is implicitly converted to bool
          if is_not_finite == 0:
              return False
          else:
              return True
docs: detect inf and nan