code: def _cleanup(self, lr_decay_opt_states_reset: str, process_manager: Optional['DecoderProcessManager'] = None,
                   keep_training_state = False):
          
          utils.cleanup_params_files(self.model.output_dir, self.max_params_files_to_keep,
                                     self.state.checkpoint, self.state.best_checkpoint, self.keep_initializations)
          if process_manager is not None:
              result = process_manager.collect_results()
              if result is not None:
                  decoded_checkpoint, decoder_metrics = result
                  self.state.metrics[decoded_checkpoint - 1].update(decoder_metrics)
                  self.tflogger.log_metrics(decoder_metrics, decoded_checkpoint)
                  utils.write_metrics_file(self.state.metrics, self.metrics_fname)
                  self.state.save(os.path.join(self.training_state_dirname, C.TRAINING_STATE_NAME))
  
          if not keep_training_state:
              final_training_state_dirname = os.path.join(self.model.output_dir, C.TRAINING_STATE_DIRNAME)
              if os.path.exists(final_training_state_dirname):
                  shutil.rmtree(final_training_state_dirname)
              if lr_decay_opt_states_reset == C.LR_DECAY_OPT_STATES_RESET_BEST:
                  best_opt_states_fname = os.path.join(self.model.output_dir, C.OPT_STATES_BEST)
                  if os.path.exists(best_opt_states_fname):
                      os.remove(best_opt_states_fname)
              if lr_decay_opt_states_reset == C.LR_DECAY_OPT_STATES_RESET_INITIAL:
                  initial_opt_states_fname = os.path.join(self.model.output_dir, C.OPT_STATES_INITIAL)
                  if os.path.exists(initial_opt_states_fname):
                      os.remove(initial_opt_states_fname)
docs: Cleans parameter files, training state directory and waits for remaining decoding processes.