def test_shared_weights():
        """
        If a const is shared with different downstream ops, we do a further conflict detection.
        """

        def _get_program():
            @mb.program(
                input_specs=[mb.TensorSpec(shape=(1, 10, 30))], opset_version=ct.target.iOS16
            )
            def prog(x):
                add_const = np.random.rand(10, 30).astype(np.float32)
                add_const = mb.const(val=add_const, name="add_const")
                x = mb.add(x=x, y=add_const, name="add_1")
                return mb.add(x=x, y=add_const, name="add_2")
            return prog

        # [Case 1] No conflict. Global and op_name level config are the same
        prog = _get_program()

        compressor = quantization.palettize_weights(
            config=cto.coreml.OptimizationConfig(
                global_config=cto.coreml.OpPalettizerConfig(nbits=2, mode="KMEANS", weight_threshold=50),
                op_name_configs={"add_2": cto.coreml.OpPalettizerConfig(nbits=2, mode="KMEANS", weight_threshold=50)}
            )
        )

        compressor.apply(prog)

        expected_ops = [
            "constexpr_lut_to_dense",
            "add",
            "add",
        ]
        assert get_op_types_in_program(prog) == expected_ops

        # [Case 2] No conflict. op_name level configs are the same
        prog = _get_program()

        compressor = quantization.palettize_weights(
            config=cto.coreml.OptimizationConfig(
                global_config=cto.coreml.OpPalettizerConfig(nbits=4, mode="KMEANS", weight_threshold=50),
                op_name_configs={
                    "add_1": cto.coreml.OpPalettizerConfig(nbits=2, mode="KMEANS", weight_threshold=50),
                    "add_2": cto.coreml.OpPalettizerConfig(nbits=2, mode="KMEANS", weight_threshold=50),
                }
            )
        )

        compressor.apply(prog)

        expected_ops = [
            "constexpr_lut_to_dense",
            "add",
            "add",
        ]
        assert get_op_types_in_program(prog) == expected_ops

        # [Case 3] Conflict. Global and op_name level config are different
        prog = _get_program()

        compressor = quantization.palettize_weights(
            config=cto.coreml.OptimizationConfig(
                global_config=cto.coreml.OpPalettizerConfig(nbits=2, mode="KMEANS", weight_threshold=50),
                op_name_configs={"add_2": cto.coreml.OpPalettizerConfig(nbits=4, mode="KMEANS", weight_threshold=50)}
            )
        )

        with pytest.raises(ValueError, match="compression config conflict detected between ops"):
            compressor.apply(prog)

        # [Case 4] Conflict. op_name level configs are different
        prog = _get_program()

        compressor = quantization.palettize_weights(
            config=cto.coreml.OptimizationConfig(
                global_config=cto.coreml.OpPalettizerConfig(nbits=2, mode="KMEANS", weight_threshold=50),
                op_name_configs={
                    "add_1": cto.coreml.OpPalettizerConfig(nbits=4, mode="KMEANS", weight_threshold=50),
                    "add_2": cto.coreml.OpPalettizerConfig(nbits=4, mode="KMEANS", weight_threshold=30),
                },
            )
        )

        with pytest.raises(ValueError, match="compression config conflict detected between ops"):
            compressor.apply(prog)

        If a const is shared with different downstream ops, we do a further conflict detection.
        
coremltools/test/optimize/coreml/test_passes.py