code: def run_encoder(
      encoder: IEncoder,
      batch_idx: int,
      batch: tensor_dict_type,
      state: Optional[TrainerState] = None,
      **kwargs: Any,
  ) -> tensor_dict_type:
      return _forward(
          encoder,
          batch_idx,
          batch,
          INPUT_KEY,
          state,
          general_output_key=LATENT_KEY,
          **kwargs,
      )
  
imports: import torch
  import torch.nn
  from torch import Tensor
  from typing import Any
  from typing import Dict
  from typing import Type
  from typing import Optional
  from cftool.misc import safe_execute
  from cftool.misc import check_requires
  from cftool.misc import WithRegister
  from cftool.types import tensor_dict_type
  from ....schema import _forward
  from ....schema import TrainerState
  from ....constants import INPUT_KEY
  from ....constants import LATENT_KEY
  from ....misc.toolkit import eval_context
  from ....misc.toolkit import get_device
  from ....modules.blocks import ImgToPatches
label_desc: Use image node_id 2 for calling a global function with example usage: run_encoder(encoder, batch_idx, batch, state) and returns: _forward