# Buggy code
def save_hparams_to_yaml(config_yaml, hparams: Union[dict, Namespace]) -> None:
    """
    Args:
        config_yaml: path to new YAML file
        hparams: parameters to be saved
    """
    if not gfile.isdir(os.path.dirname(config_yaml)):
        raise RuntimeError(f"Missing folder: {os.path.dirname(config_yaml)}.")

    if OMEGACONF_AVAILABLE and isinstance(hparams, Container):
        from omegaconf import OmegaConf

        OmegaConf.save(hparams, config_yaml, resolve=True)
        return

    # saving the standard way
    if isinstance(hparams, Namespace):
        hparams = vars(hparams)
    elif isinstance(hparams, AttributeDict):
        hparams = dict(hparams)
    assert isinstance(hparams, dict)

    with cloud_open(config_yaml, "w", newline="") as fp:
        yaml.dump(hparams, fp)


# Traceback (AttributeError)
-- Process 0 terminated with the following error:
Traceback (most recent call last):
  File "/mnt/xarfuse/uid-30415/c18376c8-seed-f10abbe6-4964-43d9-a723-5ecbc73379c7-ns-4026534030/torch/multiprocessing/spawn.py", line 20, in _wrap
    fn(i, *args)
  File "/mnt/xarfuse/uid-30415/c18376c8-seed-f10abbe6-4964-43d9-a723-5ecbc73379c7-ns-4026534030/torchelastic/agent/server/local_elastic_agent.py", line
 101, in _wrap
    ret = fn(*args)
  File "/mnt/xarfuse/uid-30415/c18376c8-seed-f10abbe6-4964-43d9-a723-5ecbc73379c7-ns-4026534030/f6/stdlib/sample_projects/classy_hydra_project/main.py"
, line 32, in train
    trainer.fit(task)
  File "/mnt/xarfuse/uid-30415/c18376c8-seed-f10abbe6-4964-43d9-a723-5ecbc73379c7-ns-4026534030/pytorch_lightning/trainer/trainer.py", line 1039, in
 fit
    self.ddp_train(process_idx=task, q=None, model=model)
  File "/mnt/xarfuse/uid-30415/c18376c8-seed-f10abbe6-4964-43d9-a723-5ecbc73379c7-ns-4026534030/pytorch_lightning/trainer/distrib_data_parallel.py",
 line 563, in ddp_train
    results = self.run_pretrain_routine(model)
  File "/mnt/xarfuse/uid-30415/c18376c8-seed-f10abbe6-4964-43d9-a723-5ecbc73379c7-ns-4026534030/pytorch_lightning/trainer/trainer.py", line 1199, in
 run_pretrain_routine
    self.logger.save()
  File "/mnt/xarfuse/uid-30415/c18376c8-seed-f10abbe6-4964-43d9-a723-5ecbc73379c7-ns-4026534030/pytorch_lightning/utilities/distributed.py", line 12,
 in wrapped_fn
    return fn(*args, **kwargs)
  File "/mnt/xarfuse/uid-30415/c18376c8-seed-f10abbe6-4964-43d9-a723-5ecbc73379c7-ns-4026534030/f6/stdlib/loggers/manifold_tensorboard_logger.py", line
 125, in save
    self.save_hparams_to_yaml(hparams_file, self.hparams)
  File "/mnt/xarfuse/uid-30415/c18376c8-seed-f10abbe6-4964-43d9-a723-5ecbc73379c7-ns-4026534030/f6/stdlib/loggers/manifold_tensorboard_logger.py", line
 151, in save_hparams_to_yaml
    yaml.dump(hparams, fp)
  File "/mnt/xarfuse/uid-30415/c18376c8-seed-f10abbe6-4964-43d9-a723-5ecbc73379c7-ns-4026534030/yaml/__init__.py", line 290, in dump
    return dump_all([data], stream, Dumper=Dumper, **kwds)
  File "/mnt/xarfuse/uid-30415/c18376c8-seed-f10abbe6-4964-43d9-a723-5ecbc73379c7-ns-4026534030/yaml/__init__.py", line 278, in dump_all
    dumper.represent(data)
  File "/mnt/xarfuse/uid-30415/c18376c8-seed-f10abbe6-4964-43d9-a723-5ecbc73379c7-ns-4026534030/yaml/representer.py", line 27, in represent
    node = self.represent_data(data)
  File "/mnt/xarfuse/uid-30415/c18376c8-seed-f10abbe6-4964-43d9-a723-5ecbc73379c7-ns-4026534030/yaml/representer.py", line 48, in represent_data
    node = self.yaml_representers[data_types[0]](self, data)
  File "/mnt/xarfuse/uid-30415/c18376c8-seed-f10abbe6-4964-43d9-a723-5ecbc73379c7-ns-4026534030/yaml/representer.py", line 207, in represent_dict
    return self.represent_mapping('tag:yaml.org,2002:map', data)
  File "/mnt/xarfuse/uid-30415/c18376c8-seed-f10abbe6-4964-43d9-a723-5ecbc73379c7-ns-4026534030/yaml/representer.py", line 118, in represent_mapping
    node_value = self.represent_data(item_value)
  File "/mnt/xarfuse/uid-30415/c18376c8-seed-f10abbe6-4964-43d9-a723-5ecbc73379c7-ns-4026534030/yaml/representer.py", line 52, in represent_data
    node = self.yaml_multi_representers[data_type](self, data)
  File "/mnt/xarfuse/uid-30415/c18376c8-seed-f10abbe6-4964-43d9-a723-5ecbc73379c7-ns-4026534030/yaml/representer.py", line 343, in represent_object
    'tag:yaml.org,2002:python/object:'+function_name, state)
  File "/mnt/xarfuse/uid-30415/c18376c8-seed-f10abbe6-4964-43d9-a723-5ecbc73379c7-ns-4026534030/yaml/representer.py", line 118, in represent_mapping
    node_value = self.represent_data(item_value)
  File "/mnt/xarfuse/uid-30415/c18376c8-seed-f10abbe6-4964-43d9-a723-5ecbc73379c7-ns-4026534030/yaml/representer.py", line 52, in represent_data
    node = self.yaml_multi_representers[data_type](self, data)
  File "/mnt/xarfuse/uid-30415/c18376c8-seed-f10abbe6-4964-43d9-a723-5ecbc73379c7-ns-4026534030/yaml/representer.py", line 343, in represent_object
    'tag:yaml.org,2002:python/object:'+function_name, state)
  File "/mnt/xarfuse/uid-30415/c18376c8-seed-f10abbe6-4964-43d9-a723-5ecbc73379c7-ns-4026534030/yaml/representer.py", line 118, in represent_mapping
    node_value = self.represent_data(item_value)
  File "/mnt/xarfuse/uid-30415/c18376c8-seed-f10abbe6-4964-43d9-a723-5ecbc73379c7-ns-4026534030/yaml/representer.py", line 48, in represent_data
    node = self.yaml_representers[data_types[0]](self, data)
  File "/mnt/xarfuse/uid-30415/c18376c8-seed-f10abbe6-4964-43d9-a723-5ecbc73379c7-ns-4026534030/yaml/representer.py", line 207, in represent_dict
    return self.represent_mapping('tag:yaml.org,2002:map', data)
  File "/mnt/xarfuse/uid-30415/c18376c8-seed-f10abbe6-4964-43d9-a723-5ecbc73379c7-ns-4026534030/yaml/representer.py", line 118, in represent_mapping
    node_value = self.represent_data(item_value)
  File "/mnt/xarfuse/uid-30415/c18376c8-seed-f10abbe6-4964-43d9-a723-5ecbc73379c7-ns-4026534030/yaml/representer.py", line 52, in represent_data
    node = self.yaml_multi_representers[data_type](self, data)
  File "/mnt/xarfuse/uid-30415/c18376c8-seed-f10abbe6-4964-43d9-a723-5ecbc73379c7-ns-4026534030/yaml/representer.py", line 343, in represent_object
    'tag:yaml.org,2002:python/object:'+function_name, state)
  File "/mnt/xarfuse/uid-30415/c18376c8-seed-f10abbe6-4964-43d9-a723-5ecbc73379c7-ns-4026534030/yaml/representer.py", line 118, in represent_mapping
    node_value = self.represent_data(item_value)
  File "/mnt/xarfuse/uid-30415/c18376c8-seed-f10abbe6-4964-43d9-a723-5ecbc73379c7-ns-4026534030/yaml/representer.py", line 48, in represent_data
    node = self.yaml_representers[data_types[0]](self, data)
  File "/mnt/xarfuse/uid-30415/c18376c8-seed-f10abbe6-4964-43d9-a723-5ecbc73379c7-ns-4026534030/yaml/representer.py", line 207, in represent_dict
    return self.represent_mapping('tag:yaml.org,2002:map', data)
  File "/mnt/xarfuse/uid-30415/c18376c8-seed-f10abbe6-4964-43d9-a723-5ecbc73379c7-ns-4026534030/yaml/representer.py", line 118, in represent_mapping
    node_value = self.represent_data(item_value)
  File "/mnt/xarfuse/uid-30415/c18376c8-seed-f10abbe6-4964-43d9-a723-5ecbc73379c7-ns-4026534030/yaml/representer.py", line 52, in represent_data
    node = self.yaml_multi_representers[data_type](self, data)
  File "/mnt/xarfuse/uid-30415/c18376c8-seed-f10abbe6-4964-43d9-a723-5ecbc73379c7-ns-4026534030/yaml/representer.py", line 343, in represent_object
    'tag:yaml.org,2002:python/object:'+function_name, state)
  File "/mnt/xarfuse/uid-30415/c18376c8-seed-f10abbe6-4964-43d9-a723-5ecbc73379c7-ns-4026534030/yaml/representer.py", line 118, in represent_mapping
    node_value = self.represent_data(item_value)
  File "/mnt/xarfuse/uid-30415/c18376c8-seed-f10abbe6-4964-43d9-a723-5ecbc73379c7-ns-4026534030/yaml/representer.py", line 52, in represent_data
    node = self.yaml_multi_representers[data_type](self, data)
  File "/mnt/xarfuse/uid-30415/c18376c8-seed-f10abbe6-4964-43d9-a723-5ecbc73379c7-ns-4026534030/yaml/representer.py", line 343, in represent_object
    'tag:yaml.org,2002:python/object:'+function_name, state)
  File "/mnt/xarfuse/uid-30415/c18376c8-seed-f10abbe6-4964-43d9-a723-5ecbc73379c7-ns-4026534030/yaml/representer.py", line 118, in represent_mapping
    node_value = self.represent_data(item_value)
  File "/mnt/xarfuse/uid-30415/c18376c8-seed-f10abbe6-4964-43d9-a723-5ecbc73379c7-ns-4026534030/yaml/representer.py", line 52, in represent_data
    node = self.yaml_multi_representers[data_type](self, data)
  File "/mnt/xarfuse/uid-30415/c18376c8-seed-f10abbe6-4964-43d9-a723-5ecbc73379c7-ns-4026534030/yaml/representer.py", line 331, in represent_object
    if function.__name__ == '__newobj__':
AttributeError: 'str' object has no attribute '__name__'

# Fixed code
def save_hparams_to_yaml(config_yaml, hparams: Union[dict, Namespace]) -> None:
    """
    Args:
        config_yaml: path to new YAML file
        hparams: parameters to be saved
    """
    if not gfile.isdir(os.path.dirname(config_yaml)):
        raise RuntimeError(f"Missing folder: {os.path.dirname(config_yaml)}.")

    # convert Namespace or AD to dict
    if isinstance(hparams, Namespace):
        hparams = vars(hparams)
    elif isinstance(hparams, AttributeDict):
        hparams = dict(hparams)

    # saving with OmegaConf objects
    if OmegaConf is not None:
        if OmegaConf.is_config(hparams):
            OmegaConf.save(hparams, config_yaml, resolve=True)
            return
        for v in hparams.values():
            if OmegaConf.is_config(v):
                OmegaConf.save(OmegaConf.create(hparams), config_yaml, resolve=True)
                return

    # saving the standard way
    assert isinstance(hparams, dict)
    with open(config_yaml, "w", newline="") as fp:
        yaml.dump(hparams, fp)