class_docstr: This test includes unit tests for:
  1. CoreMLWeightMetaData
  2. coremltools.optimize.coreml.get_weights_metadata
class_docstr_tok: ["This","test","includes","unit","tests","for",":","1",".","CoreMLWeightMetaData","2.","coremltools.optimize.coreml.get_weights_metadata"]
docstr: Test the get_weights_metadata functionality for models with weight-sharing layers.
docstr_tok: ["Test","the","get_weights_metadata","functionality","for","models","with","weight-sharing","layers","."]
code: def test_get_weights_metadata_shared_weight():
      """
      Test the get_weights_metadata functionality for models with weight-sharing layers.
      """
  
      def _test_child_ops(child_ops):
          assert len(child_ops) == 2
  
          assert child_ops[0].name == "add_1"
          assert child_ops[0].op_type == "add"
          assert child_ops[0].params_name_mapping["y"] == "w_1"
  
          assert child_ops[1].name == "add_2"
          assert child_ops[1].op_type == "add"
          assert child_ops[1].params_name_mapping["y"] == "w_1"
  
      @mb.program(
          input_specs=[
              mb.TensorSpec(shape=(1, 30, 10, 10)),
              mb.TensorSpec(shape=(1, 30, 10, 10)),
          ],
      )
      def prog(x, y):
          shared_weight = mb.const(
              val=np.random.rand(1, 30, 10, 10).astype(np.float32),
              name="w_1",
          )
          x = mb.add(x=x, y=shared_weight, name="add_1")
          y = mb.add(x=y, y=shared_weight, name="add_2")
          return x, y
  
      mlmodel = ct.convert(
          prog,
          convert_to="mlprogram",
          compute_precision=ct.precision.FLOAT32,
      )
  
      ops_metadata_dict = ct.optimize.coreml.get_weights_metadata(
          mlmodel,
          weight_threshold=100,
      )
      assert len(ops_metadata_dict) == 1
      child_ops = ops_metadata_dict["w_1"].child_ops
      _test_child_ops(child_ops)
  
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 3 for calling the TestCoreMLWeightMetaData obj's underlying member method code with example usage: obj.test_get_weights_metadata_shared_weight() and returns: x,  y