def _convert_weight_to_int4pack(context, node):
    """Pack weight to int4pack format which will be fed into `_weight_int4pack_mm` op."""
    inputs = _get_inputs(context, node, expected=2)
    x = inputs[0].val
    inner_k_tiles = inputs[1].val

    if x is None or inner_k_tiles is None:
        raise NotImplementedError(
            "For `_convert_weight_to_int4pack` op, we only support static case, where x, "
            "and inner_k_tiles are all known during compilation time."
        )

    with _torch.no_grad():
        x_int4packed = _torch._convert_weight_to_int4pack(
            _torch.from_numpy(x), inner_k_tiles
        ).numpy()

    res = mb.const(val=x_int4packed, name=node.name)
    context.add(res)
Pack weight to int4pack format which will be fed into `_weight_int4pack_mm` op.
coremltools/converters/mil/frontend/torch/quantization_ops.py