def test_palettization_pcs(self, compute_unit, backend):
        """Test the palettization with per-channel-scale."""
        if platform.machine() == "x86_64":
            pytest.xfail("rdar://137153993 ([CI] Quantization Tests Failing only on *native* x86_64 (not with Rosetta))")

        model, inputs, torch_input_values, coreml_input_values = get_test_model_and_data()

        torchmodel = torch.jit.trace(model, torch_input_values)
        mlmodel = ct.convert(
            torchmodel,
            inputs=inputs,
            convert_to="mlprogram",
            minimum_deployment_target=backend.opset_version,
            compute_precision=ct.precision.FLOAT16
            if backend.precision == "fp16"
            else ct.precision.FLOAT32,
            compute_units=compute_unit,
        )

        vector_lut_config = cto.coreml.OptimizationConfig(
            global_config=cto.coreml.OpPalettizerConfig(
                mode="kmeans",
                nbits=4,
                granularity="per_grouped_channel",
                group_size=0,
                enable_per_channel_scale=True,
                weight_threshold=500,
            )
        )

        if backend.opset_version < ct.target.iOS18:
            with pytest.raises(ValueError, match=self._ERR_MSG.format("per_grouped_channel")):
                cto.coreml.palettize_weights(mlmodel, vector_lut_config)
            return

        mlmodel_palettized = cto.coreml.palettize_weights(mlmodel, vector_lut_config)

        # Verify ops.
        palettize_op = mlmodel_palettized._mil_program.functions["main"].find_ops(
            op_type="constexpr_lut_to_dense"
        )[0]
        assert types.builtin_to_string(palettize_op.indices.dtype) == "uint4"
        # The per-channel-scale is represented by a quant op to do scaling.
        quantize_ops = mlmodel_palettized._mil_program.functions["main"].find_ops(
            op_type="constexpr_blockwise_shift_scale"
        )
        assert len(quantize_ops) > 0
        # Order of quant and lut op is determined by canonicalize_quantized_lut_pattern graph pass.
        assert quantize_ops[0].outputs[0].child_ops[0].op_type == "constexpr_lut_to_dense"

        if _macos_version() >= (15, 0):
            verify_model_outputs(mlmodel, mlmodel_palettized, coreml_input_values)
Test the palettization with per-channel-scale.
coremltools/test/optimize/coreml/test_post_training_quantization.py