[Misc] Various cleanups for MM input processing (#29970)
Signed-off-by: DarkLight1337 <tlleungac@connect.ust.hk>
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
# SPDX-FileCopyrightText: Copyright contributors to the vLLM project
|
||||
import base64
|
||||
import io
|
||||
import sys
|
||||
from dataclasses import dataclass
|
||||
from typing import Literal
|
||||
@@ -52,6 +53,15 @@ Endianness = Literal["native", "big", "little"]
|
||||
EncodingFormat = Literal["float", "base64", "bytes"]
|
||||
|
||||
|
||||
def tensor2base64(x: torch.Tensor) -> str:
|
||||
with io.BytesIO() as buf:
|
||||
torch.save(x, buf)
|
||||
buf.seek(0)
|
||||
binary_data = buf.read()
|
||||
|
||||
return base64.b64encode(binary_data).decode("utf-8")
|
||||
|
||||
|
||||
def tensor2binary(
|
||||
tensor: torch.Tensor, embed_dtype: EmbedDType, endianness: Endianness
|
||||
) -> bytes:
|
||||
|
||||
Reference in New Issue
Block a user