code: def load_models(
      device: pt.device,
      model_folders: List[str],
      checkpoints: Optional[List[int]] = None,
      dtype: Optional[Union[pt.dtype, str]] = None,
      clamp_to_dtype: bool = False,
      inference_only: bool = False,
      train_decoder_only: bool = False,
      allow_missing: bool = False,
      forward_pass_cache_size: int = 0,
      knn_index: Optional[str] = None,
  ) -> Tuple[List[SockeyeModel], List[vocab.Vocab], List[vocab.Vocab]]:
      """
      Loads a list of models for inference.
  
      :param device: PyTorch device.
      :param model_folders: List of model folders to load models from.
      :param checkpoints: List of checkpoints to use for each model in model_folders. Use None to load best checkpoint.
      :param dtype: Optional data type (torch.dtype or str) to use. If None, will be inferred from stored model.
      :param clamp_to_dtype: Avoid -inf/inf by clamping outputs to min/max finite values for their dtype.
      :param inference_only: Use the model only for inference, enabling optimizations.
      :param train_decoder_only: Training will only update the decoder. Disable
             autograd for encoder and embeddings to save memory.
      :param allow_missing: Allow missing parameters in the loaded models.
      :param forward_pass_cache_size: If > 0, cache encoder and embedding calculations of forward pass.
      :param knn_index: Optional path to a folder containing a KNN model index.
      :return: List of models, source vocabulary, target vocabulary, source factor vocabularies.
      """
      logger.info(
          "Loading %d model(s) from %s ...",
          len(model_folders),
          model_folders,
      )
      load_time_start = time.time()
      models = []  # type: List[SockeyeModel]
      source_vocabs = []  # type: List[List[vocab.Vocab]]
      target_vocabs = []  # type: List[List[vocab.Vocab]]
  
      if checkpoints is None:
          checkpoints = [None] * len(model_folders)
      else:
          utils.check_condition(
              len(checkpoints) == len(model_folders),
              "Must provide checkpoints for each model",
          )
  
      for model_folder, checkpoint in zip(model_folders, checkpoints):
          model, src_vcbs, trg_vcbs = load_model(
              model_folder,
              device=device,
              dtype=dtype,
              clamp_to_dtype=clamp_to_dtype,
              checkpoint=checkpoint,
              inference_only=inference_only,
              train_decoder_only=train_decoder_only,
              allow_missing=allow_missing,
              forward_pass_cache_size=forward_pass_cache_size,
              knn_index=knn_index,
          )
          models.append(model)
          source_vocabs.append(src_vcbs)
          target_vocabs.append(trg_vcbs)
  
      first_model_vocabs = source_vocabs[0]
      for fi in range(len(first_model_vocabs)):
          utils.check_condition(
              vocab.are_identical(
                  *[
                      source_vocabs[i][fi]
                      for i in range(len(source_vocabs))
                  ]
              ),
              "Source vocabulary ids do not match. Factor %d" % fi,
          )
      first_model_vocabs = target_vocabs[0]
      for fi in range(len(first_model_vocabs)):
          utils.check_condition(
              vocab.are_identical(
                  *[
                      target_vocabs[i][fi]
                      for i in range(len(target_vocabs))
                  ]
              ),
              "Target vocabulary ids do not match. Factor %d" % fi,
          )
  
      load_time = time.time() - load_time_start
      logger.info("%d model(s) loaded in %.4fs", len(models), load_time)
      return models, source_vocabs[0], target_vocabs[0]
  
imports: import copy
  import logging
  import os
  import time
  from dataclasses import dataclass
  from functools import lru_cache
  from typing import cast, Dict, List, Optional, Tuple, Union
  import numpy
  import torch
  from sockeye import __version__
  from .None import constants
  from .None import data_io
  from .None import decoder
  from .None import encoder
  from .None import layers
  from .None import transformer
  from .None import utils
  from .None import vocab
  from .config import Config
  from .encoder import FactorConfig
  from .layers import LengthRatioConfig
  from .None import nvs
  from sockeye.knn import KNNConfig
label_desc: Use image node_id 3 for calling a global function with example usage: load_models(device, model_folders, checkpoints, dtype, clamp_to_dtype, inference_only, train_decoder_only, allow_missing, forward_pass_cache_size, knn_index) and returns: models,  source_vocabs,  target_vocabs