class_docstr: Callback that streams epoch results to a [Weights & Biases](https://self.wandb.ai/) run.
  
  ```python
  self.wandb.login()
  wandb_logger = WandbCallback(project="sample-self.wandb-project", job_type="train")
  model.fit(X_train, Y_train, callbacks=[wandb_logger])
  ```
class_docstr_tok: ["Callback","that","streams","epoch","results","to","a","[","Weights","&","Biases","]","(","https",":","\/\/self.wandb.ai\/",")","run",".","``","`","python","self.wandb.login","(",")","wandb_logger","=","WandbCallback","(","project=","''","sample-self.wandb-project","''",",","job_type=","''","train","''",")","model.fit","(","X_train",",","Y_train",",","callbacks=","[","wandb_logger","]",")","``","`"]
docstr: Arguments:
      project: (str, optional) The name of the project where you're sending the new run.
          If the project is not specified, the run is put in an "Uncategorized" project.
      name: (str, optional) A short display name for this run, which is how you'll
          identify this run in the UI. By default we generate a random two-word name that
          lets you easily cross-reference runs from the table to charts. Keeping these run
          names short makes the chart legends and tables easier to read. If you're looking
          for a place to save your hyperparameters, we recommend saving those in config.
      entity: (str, optional) An entity is a username or team name where you're sending runs.
          This entity must exist before you can send runs there, so make sure to create your
          account or team in the UI before starting to log runs. If you don't specify an entity,
          the run will be sent to your default entity, which is usually your username.
      job_type: (str, optional) Specify the type of run, which is useful when you're grouping
          runs together into larger experiments using group. For example, you might have multiple
          jobs in a group, with job types like train and eval. Setting this makes it easy to
          filter and group similar runs together in the UI so you can compare apples to apples.
      config: (dict, argparse, absl.flags, str, optional) This sets `self.wandb.config`, a dictionary-like
          object for saving inputs to your job, like hyperparameters for a model or settings for a
          data preprocessing job. The config will show up in a table in the UI that you can use to
          group, filter, and sort runs. Keys should not contain . in their names, and values should
          be under 10 MB. If dict, argparse or `absl.flags`: will load the key value pairs into the
          self.wandb.config object. If str: will look for a yaml file by that name, and load config from
          that file into the `self.wandb.config` object.
      update_freq: (str, int)`'batch'` or `'epoch'` or integer. When using `'batch'`, writes the
          losses and metrics to TensorBoard after each batch. The same applies for `'epoch'`. If
          using an integer, let's say `1000`, the callback will write the metrics and losses to
          TensorBoard every 1000 batches. Note that writing too frequently to TensorBoard can slow
          down your training.
      save_model: (bool) Save a model when monitor beats all previous epochs if set to `True` otherwise
          don't save models.
      monitor: (str) name of metric to monitor. Defaults to `'val_loss'`.
      mode: (str) one of {`'min'`, `'max'`, `'every'`}. `'min'` - save model when monitor is minimized.
          `'max'` - save model when monitor is maximized. `'every'` - save model after every epoch.
docstr_tok: ["Arguments",":","project",":","(","str",",","optional",")","The","name","of","the","project","where","you","'re","sending","the","new","run",".","If","the","project","is","not","specified",",","the","run","is","put","in","an","``","Uncategorized","''","project",".","name",":","(","str",",","optional",")","A","short","display","name","for","this","run",",","which","is","how","you'll","identify","this","run","in","the","UI",".","By","default","we","generate","a","random","two-word","name","that","lets","you","easily","cross-reference","runs","from","the","table","to","charts",".","Keeping","these","run","names","short","makes","the","chart","legends","and","tables","easier","to","read",".","If","you","'re","looking","for","a","place","to","save","your","hyperparameters",",","we","recommend","saving","those","in","config",".","entity",":","(","str",",","optional",")","An","entity","is","a","username","or","team","name","where","you","'re","sending","runs",".","This","entity","must","exist","before","you","can","send","runs","there",",","so","make","sure","to","create","your","account","or","team","in","the","UI","before","starting","to","log","runs",".","If","you","do","n't","specify","an","entity",",","the","run","will","be","sent","to","your","default","entity",",","which","is","usually","your","username",".","job_type",":","(","str",",","optional",")","Specify","the","type","of","run",",","which","is","useful","when","you","'re","grouping","runs","together","into","larger","experiments","using","group",".","For","example",",","you","might","have","multiple","jobs","in","a","group",",","with","job","types","like","train","and","eval",".","Setting","this","makes","it","easy","to","filter","and","group","similar","runs","together","in","the","UI","so","you","can","compare","apples","to","apples",".","config",":","(","dict",",","argparse",",","absl.flags",",","str",",","optional",")","This","sets","`","self.wandb.config","`",",","a","dictionary-like","object","for","saving","inputs","to","your","job",",","like","hyperparameters","for","a","model","or","settings","for","a","data","preprocessing","job",".","The","config","will","show","up","in","a","table","in","the","UI","that","you","can","use","to","group",",","filter",",","and","sort","runs",".","Keys","should","not","contain",".","in","their","names",",","and","values","should","be","under","10","MB",".","If","dict",",","argparse","or","`","absl.flags","`",":","will","load","the","key","value","pairs","into","the","self.wandb.config","object",".","If","str",":","will","look","for","a","yaml","file","by","that","name",",","and","load","config","from","that","file","into","the","`","self.wandb.config","`","object",".","update_freq",":","(","str",",","int",")","`","'batch","'","`","or","`","'epoch","'","`","or","integer",".","When","using","`","'batch","'","`",",","writes","the","losses","and","metrics","to","TensorBoard","after","each","batch",".","The","same","applies","for","`","'epoch","'","`",".","If","using","an","integer",",","let","'s","say","`","1000","`",",","the","callback","will","write","the","metrics","and","losses","to","TensorBoard","every","1000","batches",".","Note","that","writing","too","frequently","to","TensorBoard","can","slow","down","your","training",".","save_model",":","(","bool",")","Save","a","model","when","monitor","beats","all","previous","epochs","if","set","to","`","True","`","otherwise","do","n't","save","models",".","monitor",":","(","str",")","name","of","metric","to","monitor",".","Defaults","to","`","'val_loss","'","`",".","mode",":","(","str",")","one","of","{","`","'min","'","`",",","`","'max","'","`",",","`","'every","'","`","}",".","`","'min","'","`","-","save","model","when","monitor","is","minimized",".","`","'max","'","`","-","save","model","when","monitor","is","maximized",".","`","'every","'","`","-","save","model","after","every","epoch","."]
code: def __init__(
      self,
      project: Optional[str] = None,
      name: Optional[str] = None,
      entity: Optional[str] = None,
      job_type: Optional[str] = None,
      config: Union[Dict, str, None] = None,
      update_freq: Union[str, int] = "epoch",
      save_model: bool = False,
      monitor: str = "val_loss",
      mode: str = "min",
      **kwargs,
  ):
      """
      Arguments:
          project: (str, optional) The name of the project where you're sending the new run.
              If the project is not specified, the run is put in an "Uncategorized" project.
          name: (str, optional) A short display name for this run, which is how you'll
              identify this run in the UI. By default we generate a random two-word name that
              lets you easily cross-reference runs from the table to charts. Keeping these run
              names short makes the chart legends and tables easier to read. If you're looking
              for a place to save your hyperparameters, we recommend saving those in config.
          entity: (str, optional) An entity is a username or team name where you're sending runs.
              This entity must exist before you can send runs there, so make sure to create your
              account or team in the UI before starting to log runs. If you don't specify an entity,
              the run will be sent to your default entity, which is usually your username.
          job_type: (str, optional) Specify the type of run, which is useful when you're grouping
              runs together into larger experiments using group. For example, you might have multiple
              jobs in a group, with job types like train and eval. Setting this makes it easy to
              filter and group similar runs together in the UI so you can compare apples to apples.
          config: (dict, argparse, absl.flags, str, optional) This sets `self.wandb.config`, a dictionary-like
              object for saving inputs to your job, like hyperparameters for a model or settings for a
              data preprocessing job. The config will show up in a table in the UI that you can use to
              group, filter, and sort runs. Keys should not contain . in their names, and values should
              be under 10 MB. If dict, argparse or `absl.flags`: will load the key value pairs into the
              self.wandb.config object. If str: will look for a yaml file by that name, and load config from
              that file into the `self.wandb.config` object.
          update_freq: (str, int)`'batch'` or `'epoch'` or integer. When using `'batch'`, writes the
              losses and metrics to TensorBoard after each batch. The same applies for `'epoch'`. If
              using an integer, let's say `1000`, the callback will write the metrics and losses to
              TensorBoard every 1000 batches. Note that writing too frequently to TensorBoard can slow
              down your training.
          save_model: (bool) Save a model when monitor beats all previous epochs if set to `True` otherwise
              don't save models.
          monitor: (str) name of metric to monitor. Defaults to `'val_loss'`.
          mode: (str) one of {`'min'`, `'max'`, `'every'`}. `'min'` - save model when monitor is minimized.
              `'max'` - save model when monitor is maximized. `'every'` - save model after every epoch.
      """
      import wandb
  
      self.wandb = wandb
      super().__init__()
      self.run = (
          self.wandb.init(
              project=project,
              name=name,
              entity=entity,
              job_type=job_type,
              config=config,
              **kwargs,
          )
          if self.wandb.run is None
          else self.wandb.run
      )
      self.keys = None
      self.write_per_batch = True
      self._constant_fields = ["size"]
      self._constants = {}
      self._save_model = save_model
      self._monitor = monitor
      self._mode = mode
      self._monitor_metric_val = (
          math.inf if mode == "min" else -math.inf
      )
      self._best_epoch = 0
      self._model_path = f"model-best-0"
      self._model_checkpoint = self.model
      try:
          self.update_freq = int(update_freq)
      except ValueError as e:
          self.update_freq = 1
          if update_freq == "batch":
              self.write_per_batch = True
          elif update_freq == "epoch":
              self.write_per_batch = False
          else:
              raise e
  
file_path: elegy/elegy/callbacks/wandb_callback.py
imports: import math
  from typing import Dict, Optional, Union
  from .callback import Callback
label_desc: Use image node_id 1 to create a new WandbCallback object from inherited base classes: Callback with example: obj = WandbCallback(project, name, entity, job_type, config, update_freq, save_model, monitor, mode)