[Bugfix] Unreadable prompt_embeds payload should be a 400, not a 500 (#55451)
Signed-off-by: lzhan011 <35493221+lzhan011@users.noreply.github.com> Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com> Co-authored-by: Cyrus Leung <tlleungac@connect.ust.hk>
This commit is contained in:
co-authored by
Claude Opus 5
Cyrus Leung
parent
4fe9e6f6e5
commit
323a29d8f2
@@ -11,6 +11,7 @@ import pytest
|
||||
import torch
|
||||
|
||||
from vllm.config import ModelConfig
|
||||
from vllm.exceptions import VLLMValidationError
|
||||
from vllm.multimodal.media import AudioEmbeddingMediaIO, ImageEmbeddingMediaIO
|
||||
from vllm.renderers.embed_utils import safe_load_prompt_embeds
|
||||
from vllm.utils.sparse_utils import check_sparse_tensor_invariants_threadsafe
|
||||
@@ -54,7 +55,7 @@ class TestNegativeControlWithoutRace:
|
||||
|
||||
def test_malicious_sparse_rejected_by_prompt_loader(self, model_config):
|
||||
encoded = _encode_tensor(_create_malicious_sparse_tensor())
|
||||
with pytest.raises((RuntimeError, ValueError)):
|
||||
with pytest.raises((RuntimeError, ValueError, VLLMValidationError)):
|
||||
safe_load_prompt_embeds(model_config, encoded)
|
||||
|
||||
def test_malicious_sparse_rejected_by_image_loader(self):
|
||||
@@ -147,7 +148,7 @@ class TestConcurrentRaceProtection:
|
||||
try:
|
||||
safe_load_prompt_embeds(model_config, malicious_encoded)
|
||||
bypassed.append(True)
|
||||
except (RuntimeError, ValueError):
|
||||
except (RuntimeError, ValueError, VLLMValidationError):
|
||||
rejected.append(True)
|
||||
|
||||
with ThreadPoolExecutor(max_workers=num_workers) as pool:
|
||||
@@ -192,7 +193,7 @@ class TestGlobalFlagRestoration:
|
||||
initial = torch.sparse.check_sparse_tensor_invariants.is_enabled()
|
||||
malicious_encoded = _encode_tensor(_create_malicious_sparse_tensor())
|
||||
|
||||
with pytest.raises((RuntimeError, ValueError)):
|
||||
with pytest.raises((RuntimeError, ValueError, VLLMValidationError)):
|
||||
safe_load_prompt_embeds(model_config, malicious_encoded)
|
||||
|
||||
assert torch.sparse.check_sparse_tensor_invariants.is_enabled() == initial
|
||||
@@ -203,7 +204,7 @@ class TestGlobalFlagRestoration:
|
||||
malicious_encoded = _encode_tensor(_create_malicious_sparse_tensor())
|
||||
|
||||
def attempt_load(_):
|
||||
with contextlib.suppress(RuntimeError, ValueError):
|
||||
with contextlib.suppress(RuntimeError, ValueError, VLLMValidationError):
|
||||
safe_load_prompt_embeds(model_config, malicious_encoded)
|
||||
|
||||
with ThreadPoolExecutor(max_workers=4) as pool:
|
||||
@@ -244,7 +245,7 @@ class TestCrossLoaderLockSharing:
|
||||
# serialization — one finishes before the other starts), AND invalid
|
||||
# tensors are still rejected.
|
||||
malicious = _encode_tensor(_create_malicious_sparse_tensor())
|
||||
with pytest.raises((RuntimeError, ValueError)):
|
||||
with pytest.raises((RuntimeError, ValueError, VLLMValidationError)):
|
||||
safe_load_prompt_embeds(model_config, malicious)
|
||||
with pytest.raises((RuntimeError, ValueError)):
|
||||
io_handler.load_base64("", malicious.decode("utf-8"))
|
||||
|
||||
Reference in New Issue
Block a user