def test_joint_palettize_quantize_weights_invalid(self, compute_unit, backend):
        """Only support per-tensor quantization for this case."""
        model, inputs, torch_input_values, coreml_input_values = get_test_model_and_data_complex()
        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,
        )

        palettize_config = cto.coreml.OptimizationConfig(
            global_config=cto.coreml.OpPalettizerConfig(
                mode="uniform",
                nbits=4,
                granularity="per_grouped_channel",
                group_size=1,
                weight_threshold=500,
            )
        )
        quant_config = cto.coreml.OptimizationConfig(
            global_config=cto.coreml.OpLinearQuantizerConfig(
                mode="linear",
                block_size=1,
                weight_threshold=500,
            )
        )

        pytest_context_manager = nullcontext()
        if backend.opset_version < ct.target.iOS18:
            pytest_context_manager = pytest.raises(ValueError, match=self._ERR_MSG)

        with pytest_context_manager:
            mlmodel_palettized = cto.coreml.palettize_weights(mlmodel, palettize_config)

        if backend.opset_version < ct.target.iOS18:
            return

        with pytest.raises(
            NotImplementedError,
            match="When use joint compression for palettization-quantization, "
            "please make sure to use per-tensor quantization",
        ):
            cto.coreml.linear_quantize_weights(
                mlmodel_palettized, quant_config, joint_compression=True
            )
Only support per-tensor quantization for this case.
coremltools/test/optimize/coreml/test_post_training_quantization.py