Skip to content

Commit c091f3c

Browse files
authored
fix: Handle model not found error for multimodal example (#1545) (#1558)
1 parent 0508825 commit c091f3c

File tree

8 files changed

+42
-2
lines changed

8 files changed

+42
-2
lines changed

examples/multimodal/components/frontend.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,9 @@
1818

1919
from components.processor import Processor
2020
from fastapi import FastAPI
21-
from fastapi.responses import StreamingResponse
21+
from fastapi.responses import JSONResponse, StreamingResponse
2222
from utils.protocol import MultiModalRequest
23+
from utils.vllm import parse_vllm_args
2324

2425
from dynamo.sdk import DYNAMO_IMAGE, api, depends, service
2526

@@ -38,8 +39,18 @@
3839
class Frontend:
3940
processor = depends(Processor)
4041

42+
def __init__(self):
43+
class_name = self.__class__.__name__
44+
self.engine_args = parse_vllm_args(class_name, "")
45+
4146
@api(name="v1/chat/completions")
4247
async def generate(self, request: MultiModalRequest):
48+
if self.engine_args.model != request.model:
49+
return JSONResponse(
50+
{"error": f"Model '{request.model}' not found"},
51+
status_code=404,
52+
)
53+
4354
async def content_generator():
4455
async for response in self.processor.generate(request.model_dump_json()):
4556
try:

examples/multimodal/components/video_frontend.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,9 @@
1818

1919
from components.video_processor import Processor
2020
from fastapi import FastAPI
21-
from fastapi.responses import StreamingResponse
21+
from fastapi.responses import JSONResponse, StreamingResponse
2222
from utils.protocol import MultiModalRequest
23+
from utils.vllm import parse_vllm_args
2324

2425
from dynamo.sdk import DYNAMO_IMAGE, api, depends, service
2526

@@ -38,8 +39,18 @@
3839
class Frontend:
3940
processor = depends(Processor)
4041

42+
def __init__(self):
43+
class_name = self.__class__.__name__
44+
self.engine_args = parse_vllm_args(class_name, "")
45+
4146
@api(name="v1/chat/completions")
4247
async def generate(self, request: MultiModalRequest):
48+
if self.engine_args.model != request.model:
49+
return JSONResponse(
50+
{"error": f"Model '{request.model}' not found"},
51+
status_code=404,
52+
)
53+
4354
async def content_generator():
4455
async for response in self.processor.generate(request.model_dump_json()):
4556
try:

examples/multimodal/configs/agg-llava.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ Common:
1717
block-size: 64
1818
max-model-len: 4096
1919

20+
Frontend:
21+
common-configs: [model]
22+
2023
Processor:
2124
router: round-robin
2225
prompt-template: "USER: <image>\n<prompt> ASSISTANT:"

examples/multimodal/configs/agg-phi3v.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ Common:
1818
max-model-len: 4096
1919
trust-remote-code: true
2020

21+
Frontend:
22+
common-configs: [model]
23+
2124
Processor:
2225
router: round-robin
2326
prompt-template: "<|user|>\n<|image_1|>\n<prompt><|end|>\n<|assistant|>\n"

examples/multimodal/configs/agg-qwen.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ Common:
1717
block-size: 64
1818
max-model-len: 4096
1919

20+
Frontend:
21+
common-configs: [model]
22+
2023
Processor:
2124
router: round-robin
2225
prompt-template: "<|im_start|>system\nYou are a helpful assistant.<|im_end|>\n<|im_start|>user\n<|vision_start|><|image_pad|><|vision_end|><prompt><|im_end|>\n<|im_start|>assistant\n"

examples/multimodal/configs/agg_video.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@ Common:
2424
video-token-id: 32000
2525
dummy-tokens-per-frame: 144
2626

27+
Frontend:
28+
common-configs: [model]
29+
2730
Processor:
2831
router: round-robin
2932
common-configs: [model, block-size, max-model-len]

examples/multimodal/configs/disagg.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ Common:
2020
num-patches: 576
2121
kv-transfer-config: '{"kv_connector":"DynamoNixlConnector"}'
2222

23+
Frontend:
24+
common-configs: [model]
25+
2326
Processor:
2427
router: round-robin
2528
prompt-template: "USER: <image>\n<prompt> ASSISTANT:"

examples/multimodal/configs/disagg_video.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ Common:
2525
video-token-id: 32000
2626
dummy-tokens-per-frame: 144
2727

28+
Frontend:
29+
common-configs: [model]
30+
2831
Processor:
2932
router: round-robin
3033
common-configs: [model, block-size]

0 commit comments

Comments
 (0)