class_docstr: Core trainable object in OpenNMT. Implements a trainable interface
  for a simple, generic encoder / decoder or decoder only model.
  
  Args:
    encoder (onmt.encoders.EncoderBase): an encoder object
    decoder (onmt.decoders.DecoderBase): a decoder object
class_docstr_tok: ["Core","trainable","object","in","OpenNMT",".","Implements","a","trainable","interface","for","a","simple",",","generic","encoder","\/","decoder","or","decoder","only","model",".","Args",":","encoder","(","onmt.encoders.EncoderBase",")",":","an","encoder","object","decoder","(","onmt.decoders.DecoderBase",")",":","a","decoder","object"]
docstr: Custom state_dict loading to enable moving module on device as they are loaded
  
  Args:
      checkpoint: Pytorch serialized checkpoint
      precision: precision to move each module to
      device: device to move each module to
      strict: if True checks model keys wrt state_dict (both ways)
docstr_tok: ["Custom","state_dict","loading","to","enable","moving","module","on","device","as","they","are","loaded","Args",":","checkpoint",":","Pytorch","serialized","checkpoint","precision",":","precision","to","move","each","module","to","device",":","device","to","move","each","module","to","strict",":","if","True","checks","model","keys","wrt","state_dict","(","both","ways",")"]
code: def load_state_dict(
      self,
      checkpoint,
      precision=torch.float32,
      device=torch.device("cpu"),
      strict=True,
      offset=0,
  ):
      """Custom state_dict loading to enable moving module on device as they are loaded
  
      Args:
          checkpoint: Pytorch serialized checkpoint
          precision: precision to move each module to
          device: device to move each module to
          strict: if True checks model keys wrt state_dict (both ways)
      """
  
      # bitsandbytes quantize weights when .cuda() is called
      # for huge models we need to save Ram
      # so we load the weights  module by module and transfer them to GPU for quantization
      if device == torch.device("cpu"):
          offset = 0
      buf_list = []
      for buf_name, buf in self.named_buffers():
          buf_list.append(buf_name)
      for name, module in self.named_modules():
          named_buf_and_param = list(module.named_buffers()) + list(
              module.named_parameters()
          )
          for param_name, param in named_buf_and_param:
              if len(param_name.split(".")) == 1:  # only last key
                  if (
                      name + "." + param_name
                      in checkpoint["model"].keys()
                  ):
                      ckpt_t = checkpoint["model"][
                          name + "." + param_name
                      ]
                      self._load_param(
                          name,
                          module,
                          param_name,
                          param,
                          buf_list,
                          ckpt_t,
                          offset,
                      )
                      del checkpoint["model"][name + "." + param_name]
                  elif (
                      "generator" in checkpoint.keys()
                      and "generator" in name
                      and checkpoint["generator"] is not None
                      and param_name in checkpoint["generator"].keys()
                  ):
                      keyname = (
                          name + "." + param_name
                          if "linear" in name
                          else param_name
                      )
                      param.data = checkpoint["generator"][keyname]
                      del checkpoint["generator"][keyname]
                  elif strict and "lora" not in param_name:
                      raise ValueError(
                          "Missing key in checkpoint: %s" % name
                          + "."
                          + param_name
                      )
                  if precision != torch.int8:
                      module.to(precision)
                  module.to(device)
  
      for key in checkpoint[
          "model"
      ].keys():  # if some keys are left in checkpoint after deletion
          if key not in buf_list:
              raise ValueError(
                  "Extra keys in model state_dict do not match the model config %s"
                  % checkpoint["model"].keys()
              )
      if checkpoint["generator"]:
          for key in checkpoint["generator"].keys():
              if key not in buf_list:
                  raise ValueError(
                      "Extra keys in generator state_dict do not match the model config %s"
                      % checkpoint["generator"].keys()
                  )
  
imports: import torch
  import torch.nn
  from glob import glob
label_desc: Use image node_id 6 for calling the BaseModel obj's underlying member method code with example usage: obj.load_state_dict(checkpoint, precision, device, strict, offset) without return types