class_docstr: Saves and loads training checkpoints on a file system.
class_docstr_tok: ["Saves","and","loads","training","checkpoints","on","a","file","system","."]
code: def load_consolidated_model(
      self, step_nr: int, out: Module, device: Optional[Device] = None
  ) -> None:
      if self.gang.rank == 0:
          model_file = self.checkpoint_dir.joinpath(
              f"step_{step_nr}/model.pt"
          )
  
          try:
              checkpoint = load_checkpoint(
                  model_file, map_location=CPU, restrict=True
              )
          except FileNotFoundError:
              raise CheckpointNotFoundError(
                  f"Training step {step_nr} has no consolidated model."
              )
          except (RuntimeError, OSError, PickleError) as ex:
              raise RuntimeError(
                  f"The consolidated model checkpoint of training step {step_nr} cannot be loaded. See nested exception for details."
              ) from ex
  
          model_device = infer_device(out)
  
          if model_device == META:
              # Move the model to the actual device without initializing. Its
              # state will be overwritten by the checkpoint anyways.
              to_empty(out, device=device or CPU)
  
          # Load the model.
          try:
              state_dict = checkpoint["model"]
          except KeyError:
              raise RuntimeError(
                  f"The consolidated model checkpoint of training step {step_nr} does not contain a 'model' entry."
              )
  
          try:
              out.load_state_dict(state_dict)
          except (KeyError, ValueError) as ex:
              raise RuntimeError(
                  f"The consolidated model of training step {step_nr} cannot be loaded. See nested exception for details."
              ) from ex
  
          if model_device == META:
              # Non-persistent buffers are not included in the checkpoint, so
              # we have to explicitly initialize them.
              reset_non_persistent_buffers(out)
  
      self.gang.barrier()
  
imports: from abc import ABC, abstractmethod
  from os import scandir
  from pathlib import Path
  from pickle import PickleError
  from shutil import rmtree
  from typing import Any, Dict, Iterator, List, Optional, Tuple, final
  import torch
  from torch.distributed.fsdp import FullyShardedDataParallel
  from torch.distributed.fsdp.api import FullStateDictConfig, StateDictType
  from torch.nn import Module
  from fairseq2.gang import Gang
  from fairseq2.models.utils.checkpoint import load_checkpoint
  from fairseq2.nn.utils.module import infer_device, reset_non_persistent_buffers, to_empty
  from fairseq2.typing import CPU, META, Device, finaloverride
label_desc: Use image node_id 8 for calling the FileCheckpointManager obj's underlying member method code with example usage: obj.load_consolidated_model(step_nr, out, device) without return types