def test_tensor_wise(self):
        """Test granularity='per_block' with block_size=0 equivalent to granularity='per_tensor'."""
        global_config_1 = cto.coreml.OpPalettizerConfig(
            mode="kmeans",
            nbits=3,
            granularity="per_tensor",
            weight_threshold=2000,
        )
        global_config_2 = cto.coreml.OpPalettizerConfig(
            mode="kmeans",
            nbits=3,
            granularity="per_grouped_channel",
            group_size=0,
            weight_threshold=2000,
        )

        for global_config in (global_config_1, global_config_2):
            config = cto.coreml.OptimizationConfig(global_config=global_config)
            compressor = quantization.palettize_weights(config=config)

            prog = self._get_test_program_3()
            compressor.apply(prog)
            lut_ops = prog.find_ops(op_type="constexpr_lut_to_dense")
            # The conv weight dense shape is (90, 30, 2, 2).
            assert lut_ops[0].lut.shape == (1, 1, 1, 1, 8, 1)
            # The linear weight dense shape is (70, 81).
            assert lut_ops[1].lut.shape == (1, 1, 8, 1)
            # The matmul y dense shape is (2, 1, 70, 35).
            assert lut_ops[2].lut.shape == (1, 1, 1, 1, 8, 1)
            # The conv_transpose weight dense shape is (30, 4, 21, 10).
            assert lut_ops[3].lut.shape == (1, 1, 1, 1, 8, 1)
Test granularity='per_block' with block_size=0 equivalent to granularity='per_tensor'.
coremltools/test/optimize/coreml/test_passes.py