code: def _nonzero_counter_hook(module, inputs, output):
    
    if not hasattr(module, "__counter_nonzero__"):
      raise ValueError("register_counter_nonzero was not called for this network")
  
    if module.training:
      return
  
    size = module.__counter_nonzero__.get("input", 0)
    size += sum([torch.nonzero(i).size(0) for i in inputs])
    module.__counter_nonzero__["input"] = size
  
    size = module.__counter_nonzero__.get("output", 0)
    size += torch.nonzero(output).size(0)
    module.__counter_nonzero__["output"] = size
  
    for name, param in module._parameters.items():
      if param is None:
        continue
  
      size = module.__counter_nonzero__.get(name, 0)
      size += torch.nonzero(param.data).size(0)
      module.__counter_nonzero__[name] = size
  
    for name, buffer in module._buffers.items():
      if buffer is None:
        continue
  
      size = module.__counter_nonzero__.get(name, 0)
      size += torch.nonzero(buffer).size(0)
      module.__counter_nonzero__[name] = size
docs: Module hook used to count the number of nonzero floating point values from
    all the tensors used by the given network during inference. This hook will be
    called every time before :func:`forward` is invoked.
  
    See :func:`torch.nn.Module.register_forward_hook`