Repository navigation
Description
🚀 The feature, motivation and pitch
Please expose per-request image and video prompt-token counts in the OpenAI-compatible /v1/chat/completions response from trtllm-serve.
Clients need to distinguish text and visual contributions to the prompt for usage accounting, benchmarking, and diagnosing missing multimodal input. Aggregate prompt_tokens cannot provide that breakdown. These counts would describe input processing, not establish that the model correctly understood the media.
In v1.3.0rc27, PromptTokensDetails contains only cached_tokens. The Qwen processor already computes video-token counts from processed video_grid_thw in get_num_tokens_per_video, but that information is not exposed in response usage.
One possible response shape is below. The values are illustrative, not measured output:
{
"usage": {
"prompt_tokens": 1242,
"completion_tokens": 45,
"total_tokens": 1287,
"prompt_tokens_details": {
"cached_tokens": 0,
"image_tokens": 0,
"video_tokens": 1024
}
}
}Suggested initial scope:
- Support Qwen image/video inputs first, with optional fields that can accommodate other supported processors later. Field names are open to maintainer guidance.
- Derive counts from the actual processed media used by the request, after sampling/resizing, without another media decode or preprocessing pass. Define visual tokens as the embedding positions contributed to the language-model prompt; exclude framing tokens.
- Keep prompt totals unchanged: visual counts are a breakdown, not additional tokens. Preserve counts when cached media/context is reused; these describe prompt contents rather than newly performed computation.
- Omit unavailable counts; reserve zero for a known zero. Do not estimate counts from video duration or a successful URL fetch.
- Return consistent details in non-streaming responses and streaming usage chunks when usage is requested, including the postprocessing-worker path.
Alternatives
Aggregate prompt counts do not distinguish text from visual tokens. Client-side estimates can disagree with server sampling and resizing. Server logs or aggregate metrics are useful for debugging but do not provide accounting attached to an individual API response.
Additional context
This is a proposal based on upstream source inspection, not a claim of a reproduced GPU failure. The existing cached-token reporting contribution provides a related response-metadata precedent.
I would be happy to contribute an implementation and tests after maintainers agree on the response shape and counting semantics. Suggested coverage includes text-only, image, video, unavailable accounting, cache reuse, and streaming/non-streaming parity. Any disaggregated-serving scope should be explicit so counts are not silently lost at a handoff.
Would this be an acceptable initial scope, and is there an existing preferred format for per-modality usage?
Before submitting a new issue...
- Searched existing issues and pull requests, and checked the public multimodal documentation and examples.
Activity
[NVIDIA#19460][fix] Address review findings for multimodal prompt tok…
[NVIDIA#19460][fix] Address review findings for multimodal prompt tok…