prepare_multimodal_messages_vllm fails on content-less tool-call messages
Problem
prepare_multimodal_messages accepts an assistant message that has tool_calls but no content. Its vLLM companion, prepare_multimodal_messages_vllm, unconditionally indexes message["content"], so it raises KeyError for that valid message representation.
Minimal reproduction
from trl.data_utils import prepare_multimodal_messages, prepare_multimodal_messages_vllm
messages = prepare_multimodal_messages(
[
{"role": "user", "content": "What is the weather in New York?"},
{
"role": "assistant",
"tool_calls": [
{
"type": "tool",
"function": {
"name": "get_current_weather",
"arguments": {"location": "New York"},
},
}
],
},
]
)
prepare_multimodal_messages_vllm(messages)
On current main (0261c7c8c78ada470856709b6fc7760cf2a13f31), this raises KeyError: 'content'.
Expected behavior
The vLLM conversion should preserve a content-less tool-call message, just as the base multimodal-message helper does, while continuing to convert image blocks when content is present.
I have added a focused regression test. AI assistance was used to investigate and draft this report; the human reporter reviewed it and reproduced the failure.
Thanks for the report. The function isn't reachable from anything: the vLLM path moved to to_openai_messages in #4700, so prepare_multimodal_messages_vllm has been dead code since January and only the tests call it.
https://github.com/huggingface/trl/blob/67dfbe211a07a8dd6ebc1a5af5b75152e10add8e/trl/data_utils.py#L127-L157
So instead of fixing it I'd rather remove it. If you're calling it directly from your own code and want it kept, say so and I'will see what to do
Closing: no trainer calls prepare_multimodal_messages_vllm on main, so this can't be hit through TRL. The helper itself goes away in #6946.