# Buggy code
def dump_checkpoint(self, weights_only: bool = False) -> dict:
    """Creating model checkpoint.

    Args:
        weights_only: saving model weights only

    Return:
         structured dictionary
    """
    checkpoint = {
        "epoch": self.current_epoch + 1,
        "global_step": self.global_step + 1,
        "pytorch-lightning_version": pytorch_lightning.__version__,
    }

    if not weights_only:
        # TODO support more generic way for callbacks to persist a state_dict in a checkpoint
        checkpoint_callbacks = [
            c for c in self.callbacks if isinstance(c, ModelCheckpoint)
        ]
        early_stopping_callbacks = [
            c for c in self.callbacks if isinstance(c, EarlyStopping)
        ]

        if checkpoint_callbacks:
            # we add the official checkpoint callback to the end of the list
            # extra user provided callbacks will not be persisted yet
            checkpoint["checkpoint_callback_best_model_score"] = (
                self.checkpoint_callback.best_model_score
            )
            checkpoint["checkpoint_callback_best_model_path"] = (
                self.checkpoint_callback.best_model_path
            )

        if early_stopping_callbacks and checkpoint_callbacks:
            # we add the official early stopping callback to the end of the list
            # extra user provided callbacks will not be persisted yet
            checkpoint["early_stop_callback_state_dict"] = early_stopping_callbacks[
                -1
            ].state_dict()

        # save optimizers
        optimizer_states = []
        for i, optimizer in enumerate(self.optimizers):
            optimizer_states.append(optimizer.state_dict())
        checkpoint["optimizer_states"] = optimizer_states

        # save lr schedulers
        lr_schedulers = []
        for scheduler in self.lr_schedulers:
            lr_schedulers.append(scheduler["scheduler"].state_dict())
        checkpoint["lr_schedulers"] = lr_schedulers

        # save native amp scaling
        if self.use_amp and NATIVE_AMP_AVALAIBLE and not self.use_tpu:
            checkpoint["native_amp_scaling_state"] = self.scaler.state_dict()
        elif self.use_amp and not NATIVE_AMP_AVALAIBLE:
            checkpoint["amp_scaling_state"] = amp.state_dict()

    # add the module_arguments and state_dict from the model
    model = self.get_model()

    checkpoint["state_dict"] = model.state_dict()

    if model.hparams:
        if hasattr(model, "_hparams_name"):
            checkpoint[LightningModule.CHECKPOINT_HYPER_PARAMS_NAME] = (
                model._hparams_name
            )
        # add arguments to the checkpoint
        checkpoint[LightningModule.CHECKPOINT_HYPER_PARAMS_KEY] = model.hparams
        if Container is not None:
            if isinstance(model.hparams, Container):
                checkpoint[LightningModule.CHECKPOINT_HYPER_PARAMS_TYPE] = type(
                    model.hparams
                )

    # give the model a chance to add a few things
    model.on_save_checkpoint(checkpoint)

    return checkpoint


# 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 dump_checkpoint(self, weights_only: bool = False) -> dict:
    """Creating model checkpoint.

    Args:
        weights_only: saving model weights only

    Return:
         structured dictionary
    """
    checkpoint = {
        "epoch": self.current_epoch + 1,
        "global_step": self.global_step + 1,
        "pytorch-lightning_version": pytorch_lightning.__version__,
    }

    if not weights_only:
        # TODO support more generic way for callbacks to persist a state_dict in a checkpoint
        checkpoint_callbacks = [
            c for c in self.callbacks if isinstance(c, ModelCheckpoint)
        ]
        early_stopping_callbacks = [
            c for c in self.callbacks if isinstance(c, EarlyStopping)
        ]

        if checkpoint_callbacks:
            # we add the official checkpoint callback to the end of the list
            # extra user provided callbacks will not be persisted yet
            checkpoint["checkpoint_callback_best_model_score"] = (
                self.checkpoint_callback.best_model_score
            )
            checkpoint["checkpoint_callback_best_model_path"] = (
                self.checkpoint_callback.best_model_path
            )

        if early_stopping_callbacks and checkpoint_callbacks:
            # we add the official early stopping callback to the end of the list
            # extra user provided callbacks will not be persisted yet
            checkpoint["early_stop_callback_state_dict"] = early_stopping_callbacks[
                -1
            ].state_dict()

        # save optimizers
        optimizer_states = []
        for i, optimizer in enumerate(self.optimizers):
            optimizer_states.append(optimizer.state_dict())
        checkpoint["optimizer_states"] = optimizer_states

        # save lr schedulers
        lr_schedulers = []
        for scheduler in self.lr_schedulers:
            lr_schedulers.append(scheduler["scheduler"].state_dict())
        checkpoint["lr_schedulers"] = lr_schedulers

        # save native amp scaling
        if self.use_amp and NATIVE_AMP_AVALAIBLE and not self.use_tpu:
            checkpoint["native_amp_scaling_state"] = self.scaler.state_dict()
        elif self.use_amp and not NATIVE_AMP_AVALAIBLE:
            checkpoint["amp_scaling_state"] = amp.state_dict()

    # add the module_arguments and state_dict from the model
    model = self.get_model()

    checkpoint["state_dict"] = model.state_dict()

    if model.hparams:
        if hasattr(model, "_hparams_name"):
            checkpoint[LightningModule.CHECKPOINT_HYPER_PARAMS_NAME] = (
                model._hparams_name
            )
        # add arguments to the checkpoint
        checkpoint[LightningModule.CHECKPOINT_HYPER_PARAMS_KEY] = model.hparams
        if OMEGACONF_AVAILABLE:
            if isinstance(model.hparams, Container):
                checkpoint[LightningModule.CHECKPOINT_HYPER_PARAMS_TYPE] = type(
                    model.hparams
                )

    # give the model a chance to add a few things
    model.on_save_checkpoint(checkpoint)

    return checkpoint