code: def test_palettization():
      (
          model,
          inputs,
          torch_input_values,
          coreml_input_values,
      ) = get_test_model_and_data_complex()
      torchmodel = torch.jit.trace(model, torch_input_values)
      mlmodel = ct.convert(
          torchmodel,
          inputs=inputs,
          convert_to="mlprogram",
          compute_precision=ct.precision.FLOAT32,
      )
  
      config = cto.coreml.OptimizationConfig()
      global_config = cto.coreml.OpPalettizerConfig(
          nbits=8, mode="kmeans", weight_threshold=500
      )
      conv_config = cto.coreml.OpPalettizerConfig(
          nbits=6, mode="kmeans", weight_threshold=500
      )
      conv_2_config = cto.coreml.OpPalettizerConfig(
          nbits=4, mode="kmeans", weight_threshold=500
      )
      linear_1_config = cto.coreml.OpPalettizerConfig(
          nbits=2, mode="kmeans", weight_threshold=500
      )
  
      config.set_global(global_config)
      config.set_op_type("conv", conv_config)
      config.set_op_name("conv_2_1", conv_2_config)
      config.set_op_name("linear_0", linear_1_config)
  
      mlmodel = cto.coreml.palettize_weights(mlmodel, config)
      expected_ops = [
          "constexpr_lut_to_dense",
          "constexpr_lut_to_dense",
          "constexpr_lut_to_dense",
          "constexpr_lut_to_dense",
          "conv",
          "conv",
          "reshape",
          "linear",
          "linear",
          "constexpr_lut_to_dense",
          "constexpr_lut_to_dense",
          "constexpr_lut_to_dense",
          "lstm",
          "expand_dims",
          "expand_dims",
      ]
      prog = mlmodel._mil_program
      assert get_op_types_in_program(prog) == expected_ops
  
      expected_nbits = [6, 4, 2, 8, 8, 8, 8, 8]
      lut_ops = prog.find_ops(op_type="constexpr_lut_to_dense")
  
      for nbits, op in zip(expected_nbits, lut_ops):
          assert op.lut.val.shape == (2**nbits,)
  
imports: import itertools
  import numpy
  import pytest
  import torch
  import coremltools
  import coremltools.optimize
  from coremltools._deps import _HAS_SKLEARN
  from coremltools.converters.mil.mil import Builder
  from coremltools.converters.mil.mil import types
  from coremltools.converters.mil.testing_utils import get_op_types_in_program
  from coremltools.optimize.coreml._post_training_quantization import CoreMLWeightMetaData
  from coremltools.test.ml_program.test_compression import get_test_model_and_data
label_desc: Use image node_id 1 for calling the TestPalettizeWeights obj's underlying member method code with example usage: obj.test_palettization() without return types