code: def palettize_weights(
      mlmodel, nbits=None, mode="kmeans", lut_function=None
  ):
      op_config = cto.coreml.OpPalettizerConfig(
          mode=mode, nbits=nbits, lut_function=lut_function
      )
      config = cto.coreml.OptimizationConfig(global_config=op_config)
      return cto.coreml.palettize_weights(mlmodel, config)
  
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 2 for calling a global function with example usage: palettize_weights(mlmodel, nbits, mode, lut_function) and returns: cto