class_docstr: `Weights & Biases <https://wandb.ai/site>`_ handler to log metrics, model/optimizer parameters, gradients
  during training and validation. It can also be used to log model checkpoints to the Weights & Biases cloud.
  
  .. code-block:: bash
  
      pip install wandb
  
  This class is also a wrapper for the wandb module. This means that you can call any wandb function using
  this wrapper. See examples on how to save model parameters and gradients.
  
  Args:
      args: Positional arguments accepted by `wandb.init`.
      kwargs: Keyword arguments accepted by `wandb.init`.
          Please see `wandb.init <https://docs.wandb.ai/library/init>`_ for documentation of possible parameters.
  
  Examples:
      .. code-block:: python
  
          from ignite.contrib.handlers.wandb_logger import *
  
          # Create a logger. All parameters are optional. See documentation
          # on wandb.init for details.
  
          wandb_logger = WandBLogger(
              entity="shared",
              project="pytorch-ignite-integration",
              name="cnn-mnist",
              config={"max_epochs": 10},
              tags=["pytorch-ignite", "minst"]
          )
  
          # Attach the logger to the trainer to log training loss at each iteration
          wandb_logger.attach_output_handler(
              trainer,
              event_name=Events.ITERATION_COMPLETED,
              tag="training",
              output_transform=lambda loss: {"loss": loss}
          )
  
          # Attach the logger to the evaluator on the training dataset and log NLL, Accuracy metrics after each epoch
          # We setup `global_step_transform=lambda *_: trainer.state.iteration` to take iteration value
          # of the `trainer`:
          wandb_logger.attach_output_handler(
              train_evaluator,
              event_name=Events.EPOCH_COMPLETED,
              tag="training",
              metric_names=["nll", "accuracy"],
              global_step_transform=lambda *_: trainer.state.iteration,
          )
  
          # Attach the logger to the evaluator on the validation dataset and log NLL, Accuracy metrics after
          # each epoch. We setup `global_step_transform=lambda *_: trainer.state.iteration` to take iteration value
          # of the `trainer` instead of `evaluator`.
          wandb_logger.attach_output_handler(
              evaluator,
              event_name=Events.EPOCH_COMPLETED,
              tag="validation",
              metric_names=["nll", "accuracy"],
              global_step_transform=lambda *_: trainer.state.iteration,
          )
  
          # Attach the logger to the trainer to log optimizer's parameters, e.g. learning rate at each iteration
          wandb_logger.attach_opt_params_handler(
              trainer,
              event_name=Events.ITERATION_STARTED,
              optimizer=optimizer,
              param_name='lr'  # optional
          )
  
          # We need to close the logger when we are done
          wandb_logger.close()
  
      If you want to log model gradients, the model call graph, etc., use the logger as wrapper of wandb. Refer
      to the documentation of wandb.watch for details:
  
      .. code-block:: python
  
          wandb_logger = WandBLogger(
              entity="shared",
              project="pytorch-ignite-integration",
              name="cnn-mnist",
              config={"max_epochs": 10},
              tags=["pytorch-ignite", "minst"]
          )
  
          model = torch.nn.Sequential(...)
          wandb_logger.watch(model)
  
      For model checkpointing, Weights & Biases creates a local run dir, and automatically synchronizes all
      files saved there at the end of the run. You can just use the `wandb_logger.run.dir` as path for the
      `ModelCheckpoint`:
  
      .. code-block:: python
  
          from ignite.handlers import ModelCheckpoint
  
          def score_function(engine):
              return engine.state.metrics['accuracy']
  
          model_checkpoint = ModelCheckpoint(
              wandb_logger.run.dir, n_saved=2, filename_prefix='best',
              require_empty=False, score_function=score_function,
              score_name="validation_accuracy",
              global_step_transform=global_step_from_engine(trainer)
          )
          evaluator.add_event_handler(Events.COMPLETED, model_checkpoint, {'model': model})
class_docstr_tok: ["`","Weights","&","Biases","<","https",":","\/\/wandb.ai\/site",">","`","_","handler","to","log","metrics",",","model\/optimizer","parameters",",","gradients","during","training","and","validation",".","It","can","also","be","used","to","log","model","checkpoints","to","the","Weights","&","Biases","cloud",".","..","code-block",":",":","bash","pip","install","wandb","This","class","is","also","a","wrapper","for","the","wandb","module",".","This","means","that","you","can","call","any","wandb","function","using","this","wrapper",".","See","examples","on","how","to","save","model","parameters","and","gradients",".","Args",":","args",":","Positional","arguments","accepted","by","`","wandb.init","`",".","kwargs",":","Keyword","arguments","accepted","by","`","wandb.init","`",".","Please","see","`","wandb.init","<","https",":","\/\/docs.wandb.ai\/library\/init",">","`","_","for","documentation","of","possible","parameters",".","Examples",":","..","code-block",":",":","python","from","ignite.contrib.handlers.wandb_logger","import","*","#","Create","a","logger",".","All","parameters","are","optional",".","See","documentation","#","on","wandb.init","for","details",".","wandb_logger","=","WandBLogger","(","entity=","''","shared","''",",","project=","''","pytorch-ignite-integration","''",",","name=","''","cnn-mnist","''",",","config=","{","``","max_epochs","''",":","10","}",",","tags=","[","``","pytorch-ignite","''",",","``","minst","''","]",")","#","Attach","the","logger","to","the","trainer","to","log","training","loss","at","each","iteration","wandb_logger.attach_output_handler","(","trainer",",","event_name=Events.ITERATION_COMPLETED",",","tag=","''","training","''",",","output_transform=lambda","loss",":","{","``","loss","''",":","loss","}",")","#","Attach","the","logger","to","the","evaluator","on","the","training","dataset","and","log","NLL",",","Accuracy","metrics","after","each","epoch","#","We","setup","`","global_step_transform=lambda","*","_",":","trainer.state.iteration","`","to","take","iteration","value","#","of","the","`","trainer","`",":","wandb_logger.attach_output_handler","(","train_evaluator",",","event_name=Events.EPOCH_COMPLETED",",","tag=","''","training","''",",","metric_names=","[","``","nll","''",",","``","accuracy","''","]",",","global_step_transform=lambda","*","_",":","trainer.state.iteration",",",")","#","Attach","the","logger","to","the","evaluator","on","the","validation","dataset","and","log","NLL",",","Accuracy","metrics","after","#","each","epoch",".","We","setup","`","global_step_transform=lambda","*","_",":","trainer.state.iteration","`","to","take","iteration","value","#","of","the","`","trainer","`","instead","of","`","evaluator","`",".","wandb_logger.attach_output_handler","(","evaluator",",","event_name=Events.EPOCH_COMPLETED",",","tag=","''","validation","''",",","metric_names=","[","``","nll","''",",","``","accuracy","''","]",",","global_step_transform=lambda","*","_",":","trainer.state.iteration",",",")","#","Attach","the","logger","to","the","trainer","to","log","optimizer","'s","parameters",",","e.g",".","learning","rate","at","each","iteration","wandb_logger.attach_opt_params_handler","(","trainer",",","event_name=Events.ITERATION_STARTED",",","optimizer=optimizer",",","param_name='lr","'","#","optional",")","#","We","need","to","close","the","logger","when","we","are","done","wandb_logger.close","(",")","If","you","want","to","log","model","gradients",",","the","model","call","graph",",","etc.",",","use","the","logger","as","wrapper","of","wandb",".","Refer","to","the","documentation","of","wandb.watch","for","details",":","..","code-block",":",":","python","wandb_logger","=","WandBLogger","(","entity=","''","shared","''",",","project=","''","pytorch-ignite-integration","''",",","name=","''","cnn-mnist","''",",","config=","{","``","max_epochs","''",":","10","}",",","tags=","[","``","pytorch-ignite","''",",","``","minst","''","]",")","model","=","torch.nn.Sequential","(","...",")","wandb_logger.watch","(","model",")","For","model","checkpointing",",","Weights","&","Biases","creates","a","local","run","dir",",","and","automatically","synchronizes","all","files","saved","there","at","the","end","of","the","run",".","You","can","just","use","the","`","wandb_logger.run.dir","`","as","path","for","the","`","ModelCheckpoint","`",":","..","code-block",":",":","python","from","ignite.handlers","import","ModelCheckpoint","def","score_function","(","engine",")",":","return","engine.state.metrics","[","'accuracy","'","]","model_checkpoint","=","ModelCheckpoint","(","wandb_logger.run.dir",",","n_saved=2",",","filename_prefix='best","'",",","require_empty=False",",","score_function=score_function",",","score_name=","''","validation_accuracy","''",",","global_step_transform=global_step_from_engine","(","trainer",")",")","evaluator.add_event_handler","(","Events.COMPLETED",",","model_checkpoint",",","{","'model","'",":","model","}",")"]
code: def __init__(self, *args: Any, **kwargs: Any):
      try:
          import wandb
  
          self._wandb = wandb
      except ImportError:
          raise ModuleNotFoundError(
              "This contrib module requires wandb to be installed. "
              "You man install wandb with the command:\n pip install wandb\n"
          )
      if kwargs.get("init", True):
          wandb.init(*args, **kwargs)
  
file_path: ignite/ignite/contrib/handlers/wandb_logger.py
imports: from typing import Any, Callable, List, Optional, Union
  from torch.optim import Optimizer
  from ignite.contrib.handlers.base_logger import BaseLogger, BaseOptimizerParamsHandler, BaseOutputHandler
  from ignite.engine import Engine, Events
  from ignite.handlers import global_step_from_engine
label_desc: Use image node_id 1 to create a new WandBLogger object from inherited base classes: BaseLogger with example: obj = WandBLogger()