class_docstr: Base handler for logging weights or their gradients.
class_docstr_tok: ["Base","handler","for","logging","weights","or","their","gradients","."]
code: def __init__(
      self,
      model: nn.Module,
      tag: Optional[str] = None,
      whitelist: Optional[
          Union[List[str], Callable[[str, nn.Parameter], bool]]
      ] = None,
  ):
      if not isinstance(model, torch.nn.Module):
          raise TypeError(
              f"Argument model should be of type torch.nn.Module, but given {type(model)}"
          )
  
      self.model = model
      self.tag = tag
  
      weights = {}
      if whitelist is None:
          weights = dict(model.named_parameters())
      elif callable(whitelist):
          for n, p in model.named_parameters():
              if whitelist(n, p):
                  weights[n] = p
      else:
          for n, p in model.named_parameters():
              for item in whitelist:
                  if n.startswith(item):
                      weights[n] = p
  
      self.weights = weights.items()
  
imports: import numbers
  import warnings
  from abc import ABCMeta, abstractmethod
  from collections import OrderedDict
  from typing import Any, Callable, Dict, List, Optional, Sequence, Tuple, Union
  import torch
  import torch.nn
  from torch.optim import Optimizer
  from ignite.engine import Engine, Events, EventsList, State
  from ignite.engine.events import CallableEventWithFilter, RemovableEventHandle
label_desc: Use image node_id 1 to create a new BaseWeightsHandler object from inherited base classes: BaseHandler with example: obj = BaseWeightsHandler(model, tag, whitelist)