[Bugfix][Security] Bound embedding densification before to_dense() (#54632)

Signed-off-by: lzhan011 <35493221+lzhan011@users.noreply.github.com>
Co-authored-by: Cyrus Leung <tlleungac@connect.ust.hk>
This commit is contained in:
lzhan011
2026-09-01 08:45:14 +00:00
committed by GitHub
co-authored by Cyrus Leung
parent 8905633687
commit ce7391712b
8 changed files with 226 additions and 18 deletions
+5 -7
View File
@@ -8,7 +8,10 @@ import torch
from vllm.exceptions import VLLMValidationError
from vllm.utils.async_utils import make_async
from vllm.utils.sparse_utils import check_sparse_tensor_invariants_threadsafe
from vllm.utils.sparse_utils import (
check_sparse_tensor_invariants_threadsafe,
safe_to_dense,
)
if TYPE_CHECKING:
from vllm.config import ModelConfig
@@ -30,12 +33,7 @@ def safe_load_prompt_embeds(
weights_only=True,
map_location=torch.device("cpu"),
)
if not isinstance(tensor, torch.Tensor):
raise VLLMValidationError(
"`prompt_embeds` payload did not deserialize to a torch.Tensor.",
parameter="prompt_embeds",
)
tensor = tensor.to_dense()
tensor = safe_to_dense(tensor, parameter="prompt_embeds")
if tensor.dim() > 2:
tensor = tensor.squeeze(0)