# 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
    """
    fs = get_filesystem(config_yaml)
    if not fs.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_AVAILABLE:
        if OmegaConf.is_config(hparams):
            with fs.open(config_yaml, "w", encoding="utf-8") as fp:
                OmegaConf.save(hparams, fp, resolve=True)
            return
        for v in hparams.values():
            if OmegaConf.is_config(v):
                with fs.open(config_yaml, "w", encoding="utf-8") as fp:
                    OmegaConf.save(OmegaConf.create(hparams), fp, resolve=True)
                return

    assert isinstance(hparams, dict)
    hparams_allowed = {}
    # drop paramaters which contain some strange datatypes as fsspec
    for k, v in hparams.items():
        try:
            yaml.dump(v)
        except TypeError as err:
            warn(
                f"Skipping '{k}' parameter because it is not possible to safely dump to YAML."
            )
            hparams[k] = type(v).__name__
        else:
            hparams_allowed[k] = v

    # saving the standard way
    with fs.open(config_yaml, "w", newline="") as fp:
        yaml.dump(hparams_allowed, fp)


# Traceback (omegaconf.errors.ConfigKeyError)
Traceback (most recent call last):
File "xCoFormer.py", line 153, in perform_tasks
fit(hparams)
File "xCoFormer.py", line 88, in fit
trainer.fit(model, datamodule=dm)
File "/home/celso/projects/venvs/xCoFormer/lib/python3.7/site-packages/pytorch_lightning/trainer/trainer.py", line 470, in fit
results = self.accelerator_backend.train()
File "/home/celso/projects/venvs/xCoFormer/lib/python3.7/site-packages/pytorch_lightning/accelerators/gpu_accelerator.py", line 65, in train
self.trainer.train_loop.setup_training(model)
File "/home/celso/projects/venvs/xCoFormer/lib/python3.7/site-packages/pytorch_lightning/trainer/training_loop.py", line 147, in setup_training
self.trainer.logger.save()
File "/home/celso/projects/venvs/xCoFormer/lib/python3.7/site-packages/pytorch_lightning/utilities/distributed.py", line 39, in wrapped_fn
return fn(*args, **kwargs)
File "/home/celso/projects/venvs/xCoFormer/lib/python3.7/site-packages/pytorch_lightning/loggers/tensorboard.py", line 221, in save
save_hparams_to_yaml(hparams_file, self.hparams)
File "/home/celso/projects/venvs/xCoFormer/lib/python3.7/site-packages/pytorch_lightning/core/saving.py", line 366, in save_hparams_to_yaml
OmegaConf.save(hparams, fp, resolve=True)
omegaconf.errors.ConfigKeyError: str interpolation key 'data.name' not found

# 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
    """
    fs = get_filesystem(config_yaml)
    if not fs.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_AVAILABLE:
        # deepcopy: hparams from user shouldn't be resolved
        hparams = deepcopy(hparams)
        to_container = partial(OmegaConf.to_container, resolve=True)
        hparams = apply_to_collection(hparams, DictConfig, to_container)
        with fs.open(config_yaml, "w", encoding="utf-8") as fp:
            try:
                OmegaConf.save(hparams, fp)
                return
            except (UnsupportedValueType, ValidationError):
                pass

    assert isinstance(hparams, dict)
    hparams_allowed = {}
    # drop paramaters which contain some strange datatypes as fsspec
    for k, v in hparams.items():
        try:
            yaml.dump(v)
        except TypeError as err:
            warn(
                f"Skipping '{k}' parameter because it is not possible to safely dump to YAML."
            )
            hparams[k] = type(v).__name__
        else:
            hparams_allowed[k] = v

    # saving the standard way
    with fs.open(config_yaml, "w", newline="") as fp:
        yaml.dump(hparams_allowed, fp)