code: def patch(
      save: bool = True,
      tensorboard_x: Optional[bool] = None,
      pytorch: Optional[bool] = None,
      root_logdir: str = "",
  ) -> None:
      if len(wandb.patched["tensorboard"]) > 0:
          raise ValueError(
              "Tensorboard already patched, remove `sync_tensorboard=True` "
              "from `wandb.init` or only call `wandb.tensorboard.patch` once."
          )
  
      # TODO: Some older versions of tensorflow don't require tensorboard to be present.
      # we may want to lift this requirement, but it's safer to have it for now
      wandb.util.get_module(
          "tensorboard",
          required="Please install tensorboard package",
          lazy=False,
      )
      c_writer = wandb.util.get_module(TENSORBOARD_C_MODULE, lazy=False)
      py_writer = wandb.util.get_module(
          TENSORFLOW_PY_MODULE, lazy=False
      )
      tb_writer = wandb.util.get_module(
          TENSORBOARD_WRITER_MODULE, lazy=False
      )
      pt_writer = wandb.util.get_module(
          TENSORBOARD_PYTORCH_MODULE, lazy=False
      )
      tbx_writer = wandb.util.get_module(
          TENSORBOARD_X_MODULE, lazy=False
      )
  
      if not pytorch and not tensorboard_x and c_writer:
          _patch_tensorflow2(
              writer=c_writer,
              module=TENSORBOARD_C_MODULE,
              save=save,
              root_logdir=root_logdir,
          )
      # This is for tensorflow <= 1.15 (tf.compat.v1.summary.FileWriter)
      if py_writer:
          _patch_file_writer(
              writer=py_writer,
              module=TENSORFLOW_PY_MODULE,
              save=save,
              root_logdir=root_logdir,
          )
      if tb_writer:
          _patch_file_writer(
              writer=tb_writer,
              module=TENSORBOARD_WRITER_MODULE,
              save=save,
              root_logdir=root_logdir,
          )
      if pt_writer:
          _patch_file_writer(
              writer=pt_writer,
              module=TENSORBOARD_PYTORCH_MODULE,
              save=save,
              root_logdir=root_logdir,
          )
      if tbx_writer:
          _patch_file_writer(
              writer=tbx_writer,
              module=TENSORBOARD_X_MODULE,
              save=save,
              root_logdir=root_logdir,
          )
      if not c_writer and not tb_writer and not tb_writer:
          wandb.termerror("Unsupported tensorboard configuration")
  
file_path: wandb/wandb/integration/tensorboard/monkeypatch.py
imports: import os
  import re
  import socket
  from typing import Any, Optional
  import wandb
  import wandb.util
label_desc: Use image node_id 2 for calling a global function with example usage: patch(save, tensorboard_x, pytorch, root_logdir) without return types