def test_grouped_channelwise_better_than_tensorwise(
        self, nbits, channel_axis, channel_group_size
    ):
        """The noise introduced by per-tensor lut should be more than grouped-channel-wise lut."""
        original_data = np.random.randint(low=-512, high=512, size=(32, 32, 2, 2)).astype(
            np.float32
        )
        block_sizes_channelwise = [0] * len(original_data.shape)
        block_sizes_channelwise[channel_axis] = channel_group_size
        params_grouped_channelwise = quantization.palettize_weights.blockwise_compress(
            original_data,
            "UNIFORM",
            nbits,
            block_sizes_channelwise,
        )

        block_sizes_per_tensor = [0] * len(original_data.shape)
        params_per_tensor = quantization.palettize_weights.blockwise_compress(
            original_data,
            "UNIFORM",
            nbits,
            block_sizes_per_tensor,
        )
        decompressed_grouped_channelwise = quantization.palettize_weights.decompress(
            params_grouped_channelwise
        )
        decompressed_per_tensor = quantization.palettize_weights.decompress(params_per_tensor)
        snr_grouped_channelwise = compute_snr_and_psnr(
            original_data, decompressed_grouped_channelwise
        )[0]
        snr_per_tensor = compute_snr_and_psnr(original_data, decompressed_per_tensor)[0]
        assert snr_grouped_channelwise > snr_per_tensor
The noise introduced by per-tensor lut should be more than grouped-channel-wise lut.
coremltools/test/optimize/coreml/test_passes.py