code: def encoder_test(
      encoder,
      input_data,
      output_dtype,
      output_shape,
      output_data=None,
  ):
      """Helper method to test different kinds of encoders.
  
      :param encoder: encoder object
      :param input_data: data to encode
      :param output_dtype: expected data type of the output (optional)
      :param output_shape: expected shape of the encoder output (optional)
      :param output_data: expected output data (optional)
      :return: returns the encoder object for the caller to run extra checks
      """
      encoder = encoder.to(DEVICE)
  
      # Run the encoder
      input_data = torch.from_numpy(input_data).to(DEVICE)
  
      hidden = encoder(input_data)[ENCODER_OUTPUT]
  
      # Check output shape and type
      assert hidden.dtype == output_dtype
      assert list(hidden.shape) == output_shape
  
      if output_data is not None:
          # todo the hidden output is actually a tensor. May need modification
          assert np.allclose(hidden, output_data)
  
imports: import random
  import numpy
  import pytest
  import torch
  from ludwig.constants import ENCODER_OUTPUT
  from ludwig.data.dataset_synthesizer import build_vocab
  from ludwig.encoders.base import Encoder
  from ludwig.encoders.image.base import MLPMixerEncoder, Stacked2DCNN
  from ludwig.encoders.sequence_encoders import ParallelCNN, SequenceEmbedEncoder, StackedCNN, StackedCNNRNN, StackedParallelCNN, StackedRNN
  from ludwig.utils.torch_utils import get_torch_device
  from tests.integration_tests.parameter_update_utils import check_module_parameters_updated
label_desc: Use image node_id 6 for calling a global function with example usage: encoder_test(encoder, input_data, output_dtype, output_shape, output_data) without return types