class_docstr: Helper handler to log model's gradients as scalars.
  Handler, upon construction, iterates over named parameters of the model and keep
  reference to ones permitted by the `whitelist`. Then at every call, applies
  reduction function to each parameter's gradient, produces a scalar and logs it.
  
  Args:
      model: model to log weights
      reduction: function to reduce parameters into scalar
      tag: common title for all produced plots. For example, "generator"
      whitelist: specific gradients to log. Should be list of model's submodules
          or parameters names, or a callable which gets weight along with its name
          and determines if its gradient should be logged. Names should be
          fully-qualified. For more information please refer to `PyTorch docs
          <https://pytorch.org/docs/stable/generated/torch.nn.Module.html#torch.nn.Module.get_submodule>`_.
          If not given, all of model's gradients are logged.
  
  Examples:
      .. code-block:: python
  
          from ignite.contrib.handlers.neptune_logger import *
  
          # Create a logger
          # We are using the api_token for the anonymous user neptuner but you can use your own.
  
          npt_logger = NeptuneLogger(
              api_token="ANONYMOUS",
              project_name="shared/pytorch-ignite-integration",
              experiment_name="cnn-mnist", # Optional,
              params={"max_epochs": 10}, # Optional,
              tags=["pytorch-ignite","minst"] # Optional
          )
  
          # Attach the logger to the trainer to log model's weights norm after each iteration
          npt_logger.attach(
              trainer,
              event_name=Events.ITERATION_COMPLETED,
              log_handler=GradsScalarHandler(model, reduction=torch.norm)
          )
  
      .. code-block:: python
  
          from ignite.contrib.handlers.neptune_logger import *
  
          npt_logger = NeptuneLogger(
              api_token="ANONYMOUS",
              project_name="shared/pytorch-ignite-integration",
              experiment_name="cnn-mnist", # Optional,
              params={"max_epochs": 10}, # Optional,
              tags=["pytorch-ignite","minst"] # Optional
          )
  
          # Log gradient of `base`
          npt_logger.attach(
              trainer,
              event_name=Events.ITERATION_COMPLETED,
              log_handler=GradsScalarHandler(
                  model,
                  reduction=torch.norm,
                  whitelist=['base']
              )
          )
  
      .. code-block:: python
  
          from ignite.contrib.handlers.neptune_logger import *
  
          npt_logger = NeptuneLogger(
              api_token="ANONYMOUS",
              project_name="shared/pytorch-ignite-integration",
              experiment_name="cnn-mnist", # Optional,
              params={"max_epochs": 10}, # Optional,
              tags=["pytorch-ignite","minst"] # Optional
          )
  
          # Log gradient of weights which belong to a `fc` layer
          def is_in_fc_layer(n, p):
              return 'fc' in n
  
          npt_logger.attach(
              trainer,
              event_name=Events.ITERATION_COMPLETED,
              log_handler=GradsScalarHandler(model, whitelist=is_in_fc_layer)
          )
  
  ..  versionchanged:: 0.4.9
      optional argument `whitelist` added.
code: def __call__(
      self,
      engine: Engine,
      logger: NeptuneLogger,
      event_name: Union[str, Events],
  ) -> None:
      if not isinstance(logger, NeptuneLogger):
          raise TypeError(
              "Handler GradsScalarHandler works only with NeptuneLogger"
          )
  
      global_step = engine.state.get_event_attrib_value(event_name)
      tag_prefix = f"{self.tag}/" if self.tag else ""
      for name, p in self.weights:
          if p.grad is None:
              continue
  
          name = name.replace(".", "/")
          key = f"{tag_prefix}grads_{self.reduction.__name__}/{name}"
          logger[key].append(self.reduction(p.grad), step=global_step)
  
imports: import tempfile
  import warnings
  from typing import Any, Callable, List, Mapping, Optional, Union
  import torch
  from torch.optim import Optimizer
  import ignite.distributed
  from ignite import __version__
  from ignite.contrib.handlers.base_logger import BaseLogger, BaseOptimizerParamsHandler, BaseOutputHandler, BaseWeightsScalarHandler
  from ignite.engine import Engine, Events
  from ignite.handlers import global_step_from_engine
  from ignite.handlers.checkpoint import BaseSaveHandler
label_desc: Use image node_id 1 for calling the GradsScalarHandler obj's underlying member method code with example usage: obj.__call__(engine, logger, event_name) without return types