class_docstr: Loads models of type ``ModelT``.
docstr: :param model_name_or_card:
      The name or asset card of the model to load.
  :param device:
      The device on which to load the model.
  :param dtype:
      The data type of the model parameters and buffers.
  :param out:
      The output model to load.
  :param force:
      If ``True``, downloads the model checkpoint even if it is already in
      cache.
  :param cache_only:
      If ``True``, skips the download and uses the cached model checkpoint.
  :param progress:
      If ``True``, displays a progress bar to stderr.
  
  :returns:
      A model loaded from the checkpoint of ``model_name_or_card``.
docstr_tok: [":","param","model_name_or_card",":","The","name","or","asset","card","of","the","model","to","load",".",":","param","device",":","The","device","on","which","to","load","the","model",".",":","param","dtype",":","The","data","type","of","the","model","parameters","and","buffers",".",":","param","out",":","The","output","model","to","load",".",":","param","force",":","If","``","True","``",",","downloads","the","model","checkpoint","even","if","it","is","already","in","cache",".",":","param","cache_only",":","If","``","True","``",",","skips","the","download","and","uses","the","cached","model","checkpoint",".",":","param","progress",":","If","``","True","``",",","displays","a","progress","bar","to","stderr",".",":","returns",":","A","model","loaded","from","the","checkpoint","of","``","model_name_or_card","``","."]
code: def __call__(
      self,
      model_name_or_card: Union[str, AssetCard],
      *,
      device: Optional[Device] = None,
      dtype: Optional[DataType] = None,
      out: Optional[ModelT] = None,
      force: bool = False,
      cache_only: bool = False,
      progress: bool = True,
  ) -> ModelT:
      """
      :param model_name_or_card:
          The name or asset card of the model to load.
      :param device:
          The device on which to load the model.
      :param dtype:
          The data type of the model parameters and buffers.
      :param out:
          The output model to load.
      :param force:
          If ``True``, downloads the model checkpoint even if it is already in
          cache.
      :param cache_only:
          If ``True``, skips the download and uses the cached model checkpoint.
      :param progress:
          If ``True``, displays a progress bar to stderr.
  
      :returns:
          A model loaded from the checkpoint of ``model_name_or_card``.
      """
      if isinstance(model_name_or_card, AssetCard):
          card = model_name_or_card
      else:
          card = self.asset_store.retrieve_card(model_name_or_card)
  
      config = self.config_loader(card)
  
      # Load the checkpoint.
      uri = card.field("checkpoint").as_uri()
  
      try:
          path = self.download_manager.download_checkpoint(
              uri,
              card.name,
              force=force,
              cache_only=cache_only,
              progress=progress,
          )
      except ValueError as ex:
          raise AssetCardError(
              f"The value of the field 'checkpoint' of the asset card '{card.name}' is not valid. See nested exception for details."
          ) from ex
  
      if self.checkpoint_converter is None:
          checkpoint_converter = None
      else:
          checkpoint_converter = partial(
              self.checkpoint_converter, config=config
          )
  
      try:
          checkpoint = load_checkpoint(
              path,
              map_location=CPU,
              restrict=self.restrict_checkpoints,
              converter=checkpoint_converter,
          )
      except (
          RuntimeError,
          OSError,
          KeyError,
          ValueError,
          PickleError,
      ) as ex:
          raise AssetError(
              f"The checkpoint of {card.name} cannot be loaded. See nested exception for details."
          ) from ex
  
      if out is not None:
          model = out
      else:
          try:
              # Try to construct the model on the meta device.
              model = self.model_factory(
                  config, device=META, dtype=dtype
              )
          except NotImplementedError:
              logger.warning("One or more operators in %s constructor do not support the meta device. Skipping lazy initialization.", card.name)  # fmt: skip
  
              # If we are here, it means the model has at least one operator that
              # does not support meta device. Do regular model initialization.
              model = self.model_factory(
                  config, device=device, dtype=dtype
              )
  
      model_device = infer_device(model)
  
      if model_device == META:
          # Move the model to the actual device without initializing. Its
          # state will be overwritten by the checkpoint anyways.
          to_empty(model, device=device or CPU)
  
      # Load the model.
      try:
          state_dict = checkpoint["model"]
      except KeyError:
          raise AssetError(
              f"The checkpoint of {card.name} does not contain a 'model' entry."
          )
  
      try:
          model.load_state_dict(state_dict)
      except (KeyError, ValueError) as ex:
          raise AssetError(
              f"{card.name} 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(model)
  
      return model
  
imports: import logging
  from abc import ABC, abstractmethod
  from copy import deepcopy
  from functools import partial
  from pathlib import Path
  from pickle import PickleError
  from typing import Any, Dict, Generic, Optional, Protocol, TypeVar, Union, final
  from torch.nn import Module
  from fairseq2.assets import AssetCard, AssetCardError, AssetCardFieldNotFoundError, AssetDownloadManager, AssetError, AssetStore
  from fairseq2.data import PathLike
  from fairseq2.data.text import TextTokenizer
  from fairseq2.models.utils.arch_registry import ArchitectureRegistry
  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, DataType, Device, finaloverride
  from fairseq2.utils.dataclass import update_dataclass
label_desc: Use image node_id 2 for calling the ModelLoader obj's underlying member method code with example usage: obj.__call__(model_name_or_card) and returns: model