class_docstr: This class is testing the api reference code in
  https://coremltools.readme.io/v7.0/docs/optimizetorch-api-overview
code: def test_programmatic_example_1(self):
      import torch
  
      import coremltools as ct
      from coremltools.optimize.torch.palettization import (
          DKMPalettizer,
          DKMPalettizerConfig,
          ModuleDKMPalettizerConfig,
      )
  
      # Toy example
      x, label = torch.rand(1, 3, 224, 224), torch.rand(1, 26, 206, 12)
      data = [(x, label)]
  
      # code that defines the pytorch model, and optimizer
      model, loss_fn, optimizer = create_model_and_optimizer()
  
      # Initialize the palettizer
      config = DKMPalettizerConfig(
          global_config=ModuleDKMPalettizerConfig(
              n_bits=4, cluster_dim=4
          )
      )
  
      palettizer = DKMPalettizer(model, config)
  
      # Prepare the model to insert FakePalettize layers for palettization
      model = palettizer.prepare(inplace=True)
  
      # Use palettizer in the PyTorch training loop
      for inputs, labels in data:
          output = model(inputs)
          loss = loss_fn(output, labels)
          loss.backward()
          optimizer.step()
          palettizer.step()
  
      # Fold LUT and indices into weights
      model = palettizer.finalize(inplace=True)
  
      # Export
      example_input = torch.rand(1, 3, 224, 224)
      traced_model = torch.jit.trace(model, example_input)
  
      coreml_model = ct.convert(
          traced_model,
          inputs=[ct.TensorType(shape=example_input.shape)],
          pass_pipeline=ct.PassPipeline.DEFAULT_PALETTIZATION,
          minimum_deployment_target=ct.target.iOS16,
      )
      assert coreml_model is not None
      output_file = tempfile.NamedTemporaryFile(
          suffix=".mlpackage"
      ).name
      coreml_model.save(output_file)
  
imports: import tempfile
  from coremltools.converters.mil.testing_utils import get_op_types_in_program
  from coremltools.test.optimize.coreml.test_passes import TestCompressionPasses
  from coremltools.test.optimize.coreml.test_passes import TestConfigurationFromDictFromYaml
label_desc: Use image node_id 4 for calling the TestOptimizeTorchAPIOverview obj's underlying member method code with example usage: obj.test_programmatic_example_1() without return types