class_docstr: SockeyeModel shares components needed for both training and inference.
  The main components of a Sockeye model are
  1) Source embedding
  2) Target embedding
  3) Encoder
  4) Decoder
  5) Output Layer
  
  ModelConfig contains parameters and their values that are fixed at training time and must be re-used at inference
  time.
  
  :param config: Model configuration.
  :param inference_only: Use the model only for inference, enabling optimizations.
  :param clamp_to_dtype: Avoid -inf/inf by clamping outputs to min/max finite values for their dtype.
class_docstr_tok: ["SockeyeModel","shares","components","needed","for","both","training","and","inference",".","The","main","components","of","a","Sockeye","model","are","1",")","Source","embedding","2",")","Target","embedding","3",")","Encoder","4",")","Decoder","5",")","Output","Layer","ModelConfig","contains","parameters","and","their","values","that","are","fixed","at","training","time","and","must","be","re-used","at","inference","time",".",":","param","config",":","Model","configuration",".",":","param","inference_only",":","Use","the","model","only","for","inference",",","enabling","optimizations",".",":","param","clamp_to_dtype",":","Avoid","-inf\/inf","by","clamping","outputs","to","min\/max","finite","values","for","their","dtype","."]
docstr: Load kNN index from a directory.
  
  :param knn_index_folder: same as `output_dir` from the `sockeye-knn` command,
                           containing the index and a config file.
docstr_tok: ["Load","kNN","index","from","a","directory",".",":","param","knn_index_folder",":","same","as","`","output_dir","`","from","the","`","sockeye-knn","`","command",",","containing","the","index","and","a","config","file","."]
code: def load_knn_index(self, knn_index_folder: str) -> None:
      """
      Load kNN index from a directory.
  
      :param knn_index_folder: same as `output_dir` from the `sockeye-knn` command,
                               containing the index and a config file.
      """
      utils.check_import_faiss()
      knn_config = KNNConfig.load(
          os.path.join(knn_index_folder, C.KNN_CONFIG_NAME)
      )
      knn_config = cast(
          KNNConfig, knn_config
      )  # load returns a Config class, need to cast to subclass KNNConfig
      keys_index = faiss.read_index(
          os.path.join(knn_index_folder, C.KNN_INDEX_NAME)
      )
      vals = np.memmap(
          os.path.join(knn_index_folder, C.KNN_WORD_DATA_STORE_NAME),
          dtype=utils.get_numpy_dtype(knn_config.word_data_type),
          mode="r",
          shape=(knn_config.index_size, 1),
      )  # type: np.memmap
      state_store = None  # type: Optional[np.memmap]
      if os.path.isfile(
          os.path.join(knn_index_folder, C.KNN_STATE_DATA_STORE_NAME)
      ):
          state_store = np.memmap(
              os.path.join(
                  knn_index_folder, C.KNN_STATE_DATA_STORE_NAME
              ),
              dtype=utils.get_numpy_dtype(knn_config.state_data_type),
              mode="r",
              shape=(knn_config.index_size, knn_config.dimension),
          )
      self.knn = layers.KNN(
          keys_index,
          vals,
          vocab_size=self.config.vocab_target_size,
          state_store=state_store,
      )
  
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 17 for calling the SockeyeModel obj's underlying member method code with example usage: obj.load_knn_index(knn_index_folder) without return types