From 5d389ab4599996b1f2a8651b06f54b2f15537b53 Mon Sep 17 00:00:00 2001 From: Sharma Vikash Kaulesh <94862026+Vikash-Sharma-17@users.noreply.github.com> Date: Mon, 26 Oct 2026 23:46:29 +0530 Subject: [PATCH] Fix(llm): Normalize multi_modal_data dictionary and validate lengths in LLM.generate --- deepinfer/entrypoints/llm.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/deepinfer/entrypoints/llm.py b/deepinfer/entrypoints/llm.py index aa8d5e8..4e3b4c0 100644 --- a/deepinfer/entrypoints/llm.py +++ b/deepinfer/entrypoints/llm.py @@ -119,15 +119,20 @@ class LLM: if isinstance(prompts, str): # Convert a single prompt to a list. prompts = [prompts] + if isinstance(multi_modal_data, dict): multi_modal_data = [multi_modal_data] if prompts is not None and prompt_token_ids is not None and len(prompts) != len(prompt_token_ids): raise ValueError("The lengths of prompts and prompt_token_ids must be the same.") + num_requests = len(prompts) if prompts is not None else len(prompt_token_ids) + if multi_modal_data is not None and len(multi_modal_data) != num_requests: + raise ValueError("The lengths of prompts and multi_modal_data must be the same.") + if isinstance(sampling_params, list) and len(sampling_params) != num_requests: + raise ValueError("The lengths of prompts and sampling_params must be the same.") if sampling_params is None: # Use default sampling params. sampling_params = SamplingParams() # Add requests to the engine. - num_requests = len(prompts) if prompts is not None else len(prompt_token_ids) for i in range(num_requests): prompt = prompts[i] if prompts is not None else None token_ids = None if prompt_token_ids is None else prompt_token_ids[i]