Skip to content

[Feature]: Better base64 to torch tenser #26781

@noooop

Description

@noooop

🚀 The feature, motivation and pitch

Support float32, float16, bfloat16, fp8_e4m3, fp8_e5m2 embed dtype in #26414

The following line of code will raise annoying UserWarning

torch.frombuffer(
    base64.b64decode(data["embedding"]), dtype=torch_dtype
).to(torch.float32)

UserWarning:

examples/online_serving/pooling/embedding_embed_dtype_client.py:49: UserWarning: The given buffer is not writable, and PyTorch does not support non-writable tensors. This means you can write to the underlying (supposedly non-writable) buffer using the tensor. You may want to copy the buffer to protect its data or make it writable before converting it to a tensor. This type of warning will be suppressed for the rest of this program. (Triggered internally at /pytorch/torch/csrc/utils/tensor_new.cpp:1578.)
  torch.frombuffer(

Cannot use numpy to load data['embedding'] because numpy does not support bfloat16, fp8_e4m3, fp8_e5m2

Welcome to contribute. If you know an efficient method that does not trigger this UserWarning (It's best to use a zero-copy method here.)

This issue involves the following files

  • examples/online_serving/pooling/embedding_embed_dtype_client.py
  • tests/entrypoints/pooling/openai/test_pooling.py
  • tests/entrypoints/pooling/openai/test_embedding.py

Alternatives

No response

Additional context

No response

Before submitting a new issue...

  • Make sure you already searched for relevant issues, and asked the chatbot living at the bottom right corner of the documentation page, which can answer lots of frequently asked questions.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions