class_docstr: Provide methods to save, load, and overrides an omegaconf config object
  which may contain definition of lazily-constructed objects.
class_docstr_tok: ["Provide","methods","to","save",",","load",",","and","overrides","an","omegaconf","config","object","which","may","contain","definition","of","lazily-constructed","objects","."]
docstr: Save a config object to a yaml file.
  Note that when the config dictionary contains complex objects (e.g. lambda),
  it can't be saved to yaml. In that case we will print an error and
  attempt to save to a pkl file instead.
  
  Args:
      cfg: an omegaconf config object
      filename: yaml file name to save the config file
docstr_tok: ["Save","a","config","object","to","a","yaml","file",".","Note","that","when","the","config","dictionary","contains","complex","objects","(","e.g",".","lambda",")",",","it","ca","n't","be","saved","to","yaml",".","In","that","case","we","will","print","an","error","and","attempt","to","save","to","a","pkl","file","instead",".","Args",":","cfg",":","an","omegaconf","config","object","filename",":","yaml","file","name","to","save","the","config","file"]
code: def save(cfg, filename: str):
      """
      Save a config object to a yaml file.
      Note that when the config dictionary contains complex objects (e.g. lambda),
      it can't be saved to yaml. In that case we will print an error and
      attempt to save to a pkl file instead.
  
      Args:
          cfg: an omegaconf config object
          filename: yaml file name to save the config file
      """
      logger = logging.getLogger(__name__)
      try:
          cfg = deepcopy(cfg)
      except Exception:
          pass
      else:
          # if it's deep-copyable, then...
          def _replace_type_by_name(x):
              if "_target_" in x and callable(x._target_):
                  try:
                      x._target_ = _convert_target_to_string(x._target_)
                  except AttributeError:
                      pass
  
          # not necessary, but makes yaml looks nicer
          _visit_dict_config(cfg, _replace_type_by_name)
  
      save_pkl = False
      try:
          dict = OmegaConf.to_container(
              cfg,
              # Do not resolve interpolation when saving, i.e. do not turn ${a} into
              # actual values when saving.
              resolve=False,
              # Save structures (dataclasses) in a format that can be instantiated later.
              # Without this option, the type information of the dataclass will be erased.
              structured_config_mode=SCMode.INSTANTIATE,
          )
          dumped = yaml.dump(
              dict,
              default_flow_style=None,
              allow_unicode=True,
              width=9999,
          )
          with PathManager.open(filename, "w") as f:
              f.write(dumped)
  
          try:
              _ = yaml.unsafe_load(dumped)  # test that it is loadable
          except Exception:
              logger.warning(
                  "The config contains objects that cannot serialize to a valid yaml. "
                  f"{filename} is human-readable but cannot be loaded."
              )
              save_pkl = True
      except Exception:
          logger.exception(
              "Unable to serialize the config to yaml. Error:"
          )
          save_pkl = True
  
      if save_pkl:
          new_filename = filename + ".pkl"
          try:
              # retry by pickle
              with PathManager.open(new_filename, "wb") as f:
                  cloudpickle.dump(cfg, f)
              logger.warning(
                  f"Config is saved using cloudpickle at {new_filename}."
              )
          except Exception:
              pass
  
imports: import ast
  import builtins
  import collections.abc
  import importlib
  import inspect
  import logging
  import os
  import uuid
  from contextlib import contextmanager
  from copy import deepcopy
  from dataclasses import is_dataclass
  from typing import List, Tuple, Union
  import cloudpickle
  import yaml
  from omegaconf import DictConfig, ListConfig, OmegaConf, SCMode
  from detectron2.utils.file_io import PathManager
  from detectron2.utils.registry import _convert_target_to_string
label_desc: Use image node_id 3 for calling the LazyConfig obj's underlying member method code with example usage: obj.save(cfg, filename) without return types