def test_milproto_load_to_pymil_sub_byte(self, immediate_value: bool, dtype: types):
        """Test if value in milproto (especially sub-byte) could be corrected loaded into pymil."""
        dtype_range = types.type_mapping.builtin_to_range(dtype)
        data_val = [dtype_range.low, dtype_range.high]
        if immediate_value:
            # Tensors with less than 10 elements will be stored as immediate values.
            data = np.array(data_val).reshape((1, 2, 1))
        else:
            data = np.array(data_val * 20).reshape((1, 40, 1))

        offset_val = dtype_range.high if dtype.is_unsigned() else -1
        offset = np.array([offset_val]).reshape((1, 1, 1))

        np_dtype = types.nptype_from_builtin(dtype)

        @mb.program(input_specs=[], opset_version=ct.target.iOS18)
        def prog():
            return mb.constexpr_blockwise_shift_scale(
                data=data.astype(np_dtype),
                scale=np.array([4]).reshape((1, 1, 1)).astype(np.float16),
                offset=offset.astype(np_dtype),
            )

        mlmodel = ct.convert(
            prog,
            convert_to="mlprogram",
            compute_units=ct.ComputeUnit.CPU_ONLY,
            minimum_deployment_target=ct.target.iOS18,
        )
        pymil_prog: Program = milproto_to_pymil(
            model_spec=mlmodel.get_spec(),
            specification_version=ct.target.iOS18,
            file_weights_dir=mlmodel.weights_dir,
        )
        assert get_op_types_in_program(pymil_prog) == get_op_types_in_program(prog)

        original_ops = mlmodel._mil_program.functions["main"].find_ops(
            op_type="constexpr_blockwise_shift_scale"
        )
        load_back_ops = pymil_prog.functions["main"].find_ops(
            op_type="constexpr_blockwise_shift_scale"
        )
        for (original_op, load_back_op) in zip(original_ops, load_back_ops):
            assert original_op.data.dtype == load_back_op.data.dtype
            assert original_op.offset.dtype == load_back_op.offset.dtype
            np.testing.assert_array_equal(original_op.data.val, load_back_op.data.val)
            np.testing.assert_array_equal(original_op.offset.val, load_back_op.offset.val)
Test if value in milproto (especially sub-byte) could be corrected loaded into pymil.
coremltools/converters/mil/frontend/milproto/test_load.py