def test_const_mask_deduplication(self):
        """The same mask used by constexpr_sparse_blockwise_shift_scale and constexpr_sparse_to_dense is deduped."""
        mask_val = np.random.randint(low=0, high=2, size=(32, 32)).astype(types.np_uint1_dtype)
        nonzero_data_val = np.random.randint(low=1, high=100, size=(np.sum(mask_val),)).astype(
            np.int8
        )

        @mb.program(input_specs=[], opset_version=ct.target.iOS18)
        def prog():
            mask, nonzero_data = mb.constexpr_sparse_blockwise_shift_scale(
                data_mask=mb.const(val=mask_val),
                nonzero_data=nonzero_data_val,
                scale=np.array([[0.1]]),
                offset=np.array([[1]]).astype(np.int8),
            )
            return mb.constexpr_sparse_to_dense(
                nonzero_data=nonzero_data,
                mask=mb.const(val=mask_val),
            )

        prev_prog, _, _ = apply_pass_and_basic_check(prog, "common::const_deduplication")
        assert_op_count_match(prev_prog, expect=5, op="const")
        # The `data_mask` and `mask` which have the same val (mask_val) are deduplicated.
        assert_op_count_match(prog, expect=4, op="const")
        quantize_op = prog.functions["main"].find_ops(
            op_type="constexpr_sparse_blockwise_shift_scale"
        )[0]
        sparse_to_dense_op = prog.functions["main"].find_ops(op_type="constexpr_sparse_to_dense")[0]
        assert quantize_op.data_mask == sparse_to_dense_op.mask
The same mask used by constexpr_sparse_blockwise_shift_scale and constexpr_sparse_to_dense is deduped.
coremltools/converters/mil/mil/passes/tests/test_cleanup_passes.py