code: def upgrade_config(cfg: CN, to_version: Optional[int] = None) -> CN:
      """
      Upgrade a config from its current version to a newer version.
  
      Args:
          cfg (CfgNode):
          to_version (int): defaults to the latest version.
      """
      cfg = cfg.clone()
      if to_version is None:
          to_version = _C.VERSION
  
      assert (
          cfg.VERSION <= to_version
      ), "Cannot upgrade from v{} to v{}!".format(
          cfg.VERSION, to_version
      )
      for k in range(cfg.VERSION, to_version):
          converter = globals()["ConverterV" + str(k + 1)]
          converter.upgrade(cfg)
          cfg.VERSION = k + 1
      return cfg
  
file_path: detectron2/detectron2/config/compat.py
imports: import logging
  from typing import List, Optional, Tuple
  from .config import CfgNode
  from .defaults import _C
label_desc: Use image node_id 1 for calling a global function with example usage: upgrade_config(cfg, to_version) and returns: cfg