Closed
Labels
Description
System Info
- CPU: x86_64
- GPU: B300
- TensorRT-LLM Version: main branch (hash:
0d5c9ffd8f3f)
Who can help?
No response
Information
- The official example scripts
- My own modified scripts
Tasks
- An officially supported task in the
examplesfolder (such as GLUE/SQuAD, ...) - My own task or dataset (give details below)
Reproduction
When running the examples/llm-api/quickstart_multimodal.py example with the Efficient-Large-Model/NVILA-8B model as suggested in examples/llm-api/README.md, a ValueError occurs during the forward pass due to a mismatch between image tokens in input_ids and the received image embeddings.
Steps to Reproduce
Run the following command in the examples/llm-api/ directory:
(.venv-3.12) user@server:~/TensorRT-LLM$ cd examples/llm-api/
(.venv-3.12) user@server:~/TensorRT-LLM/examples/llm-api$ python quickstart_multimodal.py --model_dir Efficient-Large-Model/NVILA-8B --modality image
Skipping import of cpp extensions due to incompatible torch version 2.11.0a0+eb65b36914.nv26.02 for torchao version 0.15.0 Please see https://github.com/pytorch/ao/issues/2919 for more info
Warning: The cache directory for DeepSpeed Triton autotune, ~/.triton/autotune, appears to be on an NFS system. While this is generally acceptable, if you experience slowdowns or hanging when DeepSpeed exits, it is recommended to set the TRITON_CACHE_DIR environment variable to a non-NFS path.
/usr/local/lib/python3.12/dist-packages/modelopt/torch/__init__.py:36: UserWarning: transformers version 4.57.3 is incompatible with nvidia-modelopt and may cause issues. Please install recommended version with `pip install nvidia-modelopt[hf]` if working with HF models.
_warnings.warn(
🚨 Config not found for parakeet. You can manually add it to HARDCODED_CONFIG_FOR_MODELS in utils/auto_docstring.py
🚨 Config not found for parakeet. You can manually add it to HARDCODED_CONFIG_FOR_MODELS in utils/auto_docstring.py
🚨 Config not found for parakeet. You can manually add it to HARDCODED_CONFIG_FOR_MODELS in utils/auto_docstring.py
[TensorRT-LLM] TensorRT LLM version: 1.3.0rc11
[04/15/2026-05:12:53] [TRT-LLM] [I] Using LLM with PyTorch backend
[04/15/2026-05:12:53] [TRT-LLM] [W] Using default gpus_per_node: 8
[04/15/2026-05:12:53] [TRT-LLM] [I] neither checkpoint_format nor checkpoint_loader were provided, checkpoint_format will be set to HF.
The argument `trust_remote_code` is to be used with Auto classes. It has no effect here and is ignored. 92.8MB/s]
You are using a model of type llava_llama to instantiate a model of type . This is not supported for all configurations of models and can yield errors.
`torch_dtype` is deprecated! Use `dtype` instead!
rank 0 using MpiPoolSession to spawn MPI processes
Skipping import of cpp extensions due to incompatible torch version 2.11.0a0+eb65b36914.nv26.02 for torchao version 0.15.0 Please see https://github.com/pytorch/ao/issues/2919 for more info
Warning: The cache directory for DeepSpeed Triton autotune, ~/.triton/autotune, appears to be on an NFS system. While this is generally acceptable, if you experience slowdowns or hanging when DeepSpeed exits, it is recommended to set the TRITON_CACHE_DIR environment variable to a non-NFS path.
Multiple distributions found for package optimum. Picked distribution: optimum
Multiple distributions found for package modelopt. Picked distribution: nvidia-modelopt
/usr/local/lib/python3.12/dist-packages/modelopt/torch/__init__.py:36: UserWarning: transformers version 4.57.3 is incompatible with nvidia-modelopt and may cause issues. Please install recommended version with `pip install nvidia-modelopt[hf]` if working with HF models.
_warnings.warn(
🚨 Config not found for parakeet. You can manually add it to HARDCODED_CONFIG_FOR_MODELS in utils/auto_docstring.py
🚨 Config not found for parakeet. You can manually add it to HARDCODED_CONFIG_FOR_MODELS in utils/auto_docstring.py
🚨 Config not found for parakeet. You can manually add it to HARDCODED_CONFIG_FOR_MODELS in utils/auto_docstring.py
[TensorRT-LLM] TensorRT LLM version: 1.3.0rc11
[TensorRT-LLM][INFO] Refreshed the MPI local session
~/TensorRT-LLM/tensorrt_llm/serve/openai_protocol.py:108: UserWarning: Field name "schema" in "ResponseFormat" shadows an attribute in parent "OpenAIBaseModel"
class ResponseFormat(OpenAIBaseModel):
`torch_dtype` is deprecated! Use `dtype` instead!
~/TensorRT-LLM/tensorrt_llm/_torch/models/modeling_vila.py:645: UserWarning: LLM have a different vocab size than tokenizer. Consider update the LLM checkpoint with the tokenizer's vocab size with _resize_token_embeddings().
warnings.warn(
Loading safetensors weights in parallel: 100%|██████████| 4/4 [00:00<00:00, 120.66it/s]
Loading weights concurrently: 100%|██████████| 568/568 [00:03<00:00, 164.11it/s]
Model init total -- 167.35s
[TensorRT-LLM][INFO] Max KV cache blocks per sequence: 1024 [window size=32768], tokens per block=32, primary blocks=2048, secondary blocks=0, max sequence length=32768
[TensorRT-LLM][INFO] Number of tokens per block: 32.
[TensorRT-LLM][INFO] [MemUsageChange] Allocated 3.50 GiB for max tokens in paged KV cache (65536).
[TensorRT-LLM][WARNING] Attention workspace size is not enough, increase the size from 0 bytes to 34111744 bytes
[TensorRT-LLM][WARNING] Attention workspace size is not enough, increase the size from 34111744 bytes to 90832896 bytes
[TensorRT-LLM][WARNING] Attention workspace size is not enough, increase the size from 90832896 bytes to 92890112 bytes
[TensorRT-LLM][WARNING] Attention workspace size is not enough, increase the size from 92890112 bytes to 110186496 bytes
[TensorRT-LLM][WARNING] [kv cache manager] storeContextBlocks: Can not find sequence for request 2048
[TensorRT-LLM][INFO] Max KV cache blocks per sequence: 1024 [window size=32768], tokens per block=32, primary blocks=10685, secondary blocks=0, max sequence length=32768
[TensorRT-LLM][INFO] Number of tokens per block: 32.
[TensorRT-LLM][INFO] [MemUsageChange] Allocated 18.26 GiB for max tokens in paged KV cache (341920).
[TensorRT-LLM][WARNING] Attention workspace size is not enough, increase the size from 0 bytes to 34111744 bytes
[TensorRT-LLM][WARNING] Attention workspace size is not enough, increase the size from 34111744 bytes to 90832896 bytes
[TensorRT-LLM][WARNING] Attention workspace size is not enough, increase the size from 90832896 bytes to 92890112 bytes
[TensorRT-LLM][WARNING] Attention workspace size is not enough, increase the size from 92890112 bytes to 110186496 bytes
Processed requests: 0%| | 0/3 [00:00<?, ?it/s]Traceback (most recent call last):
File "~/TensorRT-LLM/tensorrt_llm/_torch/pyexecutor/py_executor.py", line 3317, in _forward_step
outputs = forward(scheduled_requests, self.resource_manager,
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "~/TensorRT-LLM/tensorrt_llm/_torch/pyexecutor/py_executor.py", line 3299, in forward
return self.model_engine.forward(
^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.12/dist-packages/torch/utils/_contextlib.py", line 124, in decorate_context
return func(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^
File "~/TensorRT-LLM/tensorrt_llm/_torch/utils.py", line 123, in wrapper
return func(self, *args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "~/TensorRT-LLM/tensorrt_llm/_torch/pyexecutor/model_engine.py", line 3829, in forward
outputs = self._forward_step(inputs, gather_ids,
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "~/TensorRT-LLM/tensorrt_llm/_torch/pyexecutor/model_engine.py", line 3906, in _forward_step
outputs = self.model_forward(
^^^^^^^^^^^^^^^^^^^
File "~/TensorRT-LLM/tensorrt_llm/_torch/pyexecutor/model_engine.py", line 3893, in model_forward
return self.model.forward(**kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.12/dist-packages/torch/utils/_contextlib.py", line 124, in decorate_context
return func(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^
File "~/TensorRT-LLM/tensorrt_llm/_torch/models/modeling_vila.py", line 1219, in forward
input_ids, inputs_embeds = fuse_input_embeds(
^^^^^^^^^^^^^^^^^^
File "~/TensorRT-LLM/tensorrt_llm/_torch/models/modeling_multimodal_utils.py", line 354, in fuse_input_embeds
raise ValueError(
ValueError: Multimodal token count mismatch: found 781 image tokens in input_ids but received 3072 image embeddings. This is likely due to KV cache reuse, chunk prefill, or other optimizations that cause token count mismatches within the inference batch.
[04/15/2026-05:20:36] [TRT-LLM] [E] Encountered an error in forward function: Multimodal token count mismatch: found 781 image tokens in input_ids but received 3072 image embeddings. This is likely due to KV cache reuse, chunk prefill, or other optimizations that cause token count mismatches within the inference batch.
[04/15/2026-05:20:36] [TRT-LLM] [E] Error in event loop: Sampling failed
[04/15/2026-05:20:36] [TRT-LLM] [E] Traceback (most recent call last):
File "~/TensorRT-LLM/tensorrt_llm/_torch/pyexecutor/py_executor.py", line 645, in _event_loop_wrapper
self.event_loop()
File "~/TensorRT-LLM/tensorrt_llm/_torch/pyexecutor/py_executor.py", line 2403, in _executor_loop_overlap
assert sample_state is not None, "Sampling failed"
^^^^^^^^^^^^^^^^^^^^^^^^
AssertionError: Sampling failed
Exception in thread Thread-3 (_event_loop_wrapper):
Traceback (most recent call last):
File "/usr/lib/python3.12/threading.py", line 1073, in _bootstrap_inner
self.run()
File "/usr/lib/python3.12/threading.py", line 1010, in run
Traceback (most recent call last):
File "~/TensorRT-LLM/tensorrt_llm/llmapi/utils.py", line 52, in wrapper
return func(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^
File "/usr/lib/python3.12/contextlib.py", line 81, in inner
return func(*args, **kwds)
^^^^^^^^^^^^^^^^^^^
File "~/TensorRT-LLM/tensorrt_llm/executor/result.py", line 552, in _handle_response
handler(response.error_msg)
File "~/TensorRT-LLM/tensorrt_llm/executor/executor.py", line 287, in _handle_background_error
raise error
tensorrt_llm.executor.utils.RequestError: Multimodal token count mismatch: found 781 image tokens in input_ids but received 3072 image embeddings. This is likely due to KV cache reuse, chunk prefill, or other optimizations that cause token count mismatches within the inference batch.
Processed requests: 0%| | 0/3 [00:09<?, ?it/s]
Traceback (most recent call last):
File "~/TensorRT-LLM/examples/llm-api/quickstart_multimodal.py", line 334, in <module>
main()
File "~/TensorRT-LLM/examples/llm-api/quickstart_multimodal.py", line 306, in main
self._target(*self._args, **self._kwargs)
File "~/TensorRT-LLM/tensorrt_llm/_torch/pyexecutor/py_executor.py", line 649, in _event_loop_wrapper
outputs = llm.generate(
^^^^^^^^^^^^^
File "~/TensorRT-LLM/tensorrt_llm/llmapi/llm.py", line 403, in generate
future.result()
File "~/TensorRT-LLM/tensorrt_llm/executor/result.py", line 865, in result
self._result_step(timeout)
File "~/TensorRT-LLM/tensorrt_llm/executor/result.py", line 847, in _result_step
self._handle_response(response)
File "~/TensorRT-LLM/tensorrt_llm/executor/result.py", line 719, in _handle_response
GenerationResultBase._handle_response(self, response)
File "~/TensorRT-LLM/tensorrt_llm/llmapi/utils.py", line 56, in wrapper
raise e
File "~/TensorRT-LLM/tensorrt_llm/llmapi/utils.py", line 52, in wrapper
return func(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^
File "/usr/lib/python3.12/contextlib.py", line 81, in inner
return func(*args, **kwds)
^^^^^^^^^^^^^^^^^^^
File "~/TensorRT-LLM/tensorrt_llm/executor/result.py", line 552, in _handle_response
handler(response.error_msg)
File "~/TensorRT-LLM/tensorrt_llm/executor/executor.py", line 287, in _handle_background_error
raise e
raise error
tensorrt_llm.executor.utils.RequestError: Multimodal token count mismatch: found 781 image tokens in input_ids but received 3072 image embeddings. This is likely due to KV cache reuse, chunk prefill, or other optimizations that cause token count mismatches within the inference batch.
File "~/TensorRT-LLM/tensorrt_llm/_torch/pyexecutor/py_executor.py", line 645, in _event_loop_wrapper
self.event_loop()
File "~/TensorRT-LLM/tensorrt_llm/_torch/pyexecutor/py_executor.py", line 2403, in _executor_loop_overlap
assert sample_state is not None, "Sampling failed"
^^^^^^^^^^^^^^^^^^^^^^^^
AssertionError: Sampling failed
[W415 05:20:39.971803201 CudaIPCTypes.cpp:16] Producer process has been terminated before all shared CUDA tensors released. See Note [Sharing CUDA tensors]Expected behavior
Success to run the README.md example for quickstart_multimodal.py without any error
actual behavior
The script throws an error
additional notes
I also tried google/gemma-3-4b-it, but it threw an error. This seems to be a different error related to the KV cache, but the model specified in README should probably take priority.
Before submitting a new issue...
- Make sure you already searched for relevant issues, and checked the documentation and examples for answers to frequently asked questions.
Activity
torotoki commentedon Apr 16, 2026
Reference to the example: https://github.com/NVIDIA/TensorRT-LLM/tree/main/examples/llm-api#run-the-multimodal-example-script
torotoki commentedon Apr 21, 2026
I discovered that this exmaple code works for
Efficient-Large-Model/NVILA-8Bwithout any errors in the recent commitab315dd4a2f12fac6fca519ed6822a894eb144f8, 6 days newer than the one I reported.I'm still digesting what situation could cause this error...
(cc: @aashirvad08)
torotoki commentedon Apr 21, 2026
It seems like the following code works:
But without
--disable_kv_cache_reuseit throws the error:torotoki commentedon May 15, 2026
Closed this issue because this seems like expected.
[#13082][fix] Fix-multimodal embedding mismatch (#13240)