Skip to content

vllm.utils.serial_utils

Functions:

  • numpy2base64 –

    Encode a NumPy array using its .npy representation.

  • numpy2tensor –

    Convert NumPy values to a tensor, accepting either byte order.

numpy2base64(array)

Encode a NumPy array using its .npy representation.

Source code in vllm/utils/serial_utils.py
def numpy2base64(array: np.ndarray) -> str:
    """Encode a NumPy array using its `.npy` representation."""
    with io.BytesIO() as buffer:
        np.save(buffer, array, allow_pickle=False)
        return pybase64.b64encode(buffer.getbuffer()).decode("ascii")

numpy2tensor(array)

Convert NumPy values to a tensor, accepting either byte order.

Source code in vllm/utils/serial_utils.py
def numpy2tensor(array: np.ndarray) -> torch.Tensor:
    """Convert NumPy values to a tensor, accepting either byte order."""
    if not array.dtype.isnative:
        array = array.astype(array.dtype.newbyteorder("="))
    return torch.from_numpy(array)