code: def save_checkpoint_atomic(trainer, final_filename, extra_state):
      """Wrapper around trainer.save_checkpoint to make save atomic."""
      temp_filename = os.path.join(final_filename + ".tmp")
      trainer.save_checkpoint(temp_filename, extra_state)
      # TODO(T56266125): Use mv() instead of copy() + rm() after it's added to
      # PathManager.
      assert PathManager.copy(
          temp_filename, final_filename, overwrite=True
      ), f"Failed to copy {temp_filename} to {final_filename}"
      PathManager.rm(temp_filename)
  
imports: import os
  from collections import deque, OrderedDict
  from typing import Any, Deque, Dict, List, Optional, Tuple
  import torch
  from fairseq import checkpoint_utils, utils
  from pytorch_translate import constants
  from pytorch_translate.file_io import PathManager
label_desc: Use image node_id 1 for calling a global function with example usage: save_checkpoint_atomic(trainer, final_filename, extra_state) without return types