code: def distrib_ctx(
      self: Learner,
      sync_bn=True,  # Whether to replace all batch norm with `nn.SyncBatchNorm`
      in_notebook=False,  # Whether we are launching from a notebook or not
      **kwargs,
  ):
      "A context manager to adapt a learner to train in distributed data parallel mode."
      try:
          import accelerate
      except ImportError as e:
          e.args = [
              "Accelerate is required. Install with `pip install accelerate`"
          ]
          raise
      # Adapt self to DistributedDataParallel, yield, and cleanup afterwards.
      cleanup_dpg = False
      try:
          if in_notebook:
              cuda_id = rank_distrib()
              if not torch.distributed.is_initialized():
                  setup_distrib(cuda_id)
                  cleanup_dpg = torch.distributed.is_initialized()
              if not rank_distrib():
                  print("Training Learner...")
          if num_distrib():
              self.to_distributed(sync_bn, **kwargs)
          yield self
      finally:
          self.detach_distributed()
          if cleanup_dpg:
              teardown_distrib()
  
imports: from __future__ import annotations
  from .basics import *
  from .callback.progress import ProgressCallback
  from torch.nn.parallel import DistributedDataParallel, DataParallel
  from .data.load import _FakeLoader, _loaders
  from .optimizer import OptimWrapper
label_desc: Use image node_id 11 for calling a global function with example usage: distrib_ctx(sync_bn, in_notebook) without return types