verl icon indicating copy to clipboard operation
verl copied to clipboard

Support for Qwen2.5-VL model in Multi-turn Sglang Rollout with Tool-Calling

Open Yuqi-Hu-2001 opened this issue 1 year ago • 16 comments

I am using the multi-turn sglang rollout with tool-call feature. In the document, https://github.com/volcengine/verl/blob/main/docs/sglang_multiturn/multiturn.rst, I see that this feature supports multi-modal inputs for Qwen 2.5-VL model. However, the chat template related to tool call in Qwen 2.5-3B (for example) (in geo3k example) is very different from that of Qwen 2.5-VL-3B. This results in many differences when I build my tools for Qwen 2.5-VL-3B. For example, chat template of Qwen 2.5-3B will add a <tool_call>functions and arguments</too_lcall> message to show the tool-calling process (also for gradient computation), and add a <tool_response>some resp</tool_response> message for the . Also at the begining of the conversation, it automately prints many discriptions of the tools available. Actually, these features are not available for all the Qwen2.5-vl-3B, due to the differences in chat template. I wonder if you could provide us a example of "Support for Qwen2.5-VL model in Multi-turn Sglang Rollout with Tool-Calling". It seems that this is supported from yourn tutorial of handling multi-modal inputs and outputs (also the source codes), but I after I implement my own tools under your instructions, training fails (kl loss high, and rewards drop severely). Wondering if this difference in chat template results in bugs of multi-modal tool calling. Expecting more communications/elaborations, also feel free to add my WeChat in my homepage.

By the way, @eric-haibin-lin I also noticed your streaming in Pytorch community in 2:00 a.m., 7th, August. Will this streaming have a record online? Wish to see your explanation of these new features online.

Yuqi-Hu-2001 avatar Aug 06 '25 11:08 Yuqi-Hu-2001

Also, thank the verl team for supporting these tool calling features!

Yuqi-Hu-2001 avatar Aug 06 '25 11:08 Yuqi-Hu-2001

Hi @jackhu-bme, please make sure AutoProcessor.from_pretrained(actor_rollout_ref.model.path) is Qwen2_5_VLProcessor.

verl will automatically handle the template. FYI:

https://github.com/volcengine/verl/blob/05eb0c7a6d30e2246548be2dff44c8340178f92a/verl/workers/rollout/schemas.py#L221-L235

Tavish9 avatar Aug 07 '25 01:08 Tavish9

ImageThe processing class is specialized for VL model, correct. What I mean is the difference within the red-boxed chat template. One difference between Qwen-3B-VL and Qwen-3B is the tool_call behavior within this template, except for the logics of image/video processing. If you compare vl-chat and plan-chat, you will see the tool_call differences. The first url contains only two "tool_call" in json, and the second contains 16 "tool_call" in json-format chat templates. This cause many differences related to message processing, including:

For example, chat template of Qwen 2.5-3B will add a <tool_call>functions and arguments</too_lcall> message to show the tool-calling process (also for gradient computation), and add a <tool_response>some resp</tool_response> message for the . Also at the begining of the conversation, it automately prints many discriptions of the tools available.

If you see the logged validation generations, you will see more differences. I will share some screenshots later, but the full code is not released. From my perspective, this will cause many many troubles (I rewrote the chat templates, still in-progress), including not backwarding gradients of the original <tool_call> message generated by the VLM.

Yuqi-Hu-2001 avatar Aug 07 '25 02:08 Yuqi-Hu-2001

It seems that the official processor of Qwen2.5-VL-7B-Instruct does not support tool calling, right? chat-template

Tavish9 avatar Aug 07 '25 02:08 Tavish9

Yes! Same thing for 3B-VL, I remember.

Yuqi-Hu-2001 avatar Aug 07 '25 02:08 Yuqi-Hu-2001

It seems that the official processor of Qwen2.5-VL-7B-Instruct does not support tool calling, right? chat-template

One Strange thing is that the processor has a special token for <tool_call>, but it does not make special processing to tool call messages. Can we just simply chaneg the chat template, from your suggestion? I guess just integrate original logics for processing image and video, and add the tool call features? Can you point/find something wrong with my suggestion/idea?

Yuqi-Hu-2001 avatar Aug 07 '25 02:08 Yuqi-Hu-2001

If the released chat_template does not handle tool calling, then it can be inferred that the model most likely was not trained for it either during pretraining.

So, it's not suitable to modify the template, as this could lead to a decline in instruction-following ability.

Possible solution might be one-shot prompt engineering. (Most of the VLMs tool calling do this from what I've seen)

Tavish9 avatar Aug 07 '25 03:08 Tavish9

I am using the multi-turn sglang rollout with tool-call feature. In the document, https://github.com/volcengine/verl/blob/main/docs/sglang_multiturn/multiturn.rst, I see that this feature supports multi-modal inputs for Qwen 2.5-VL model.

The doc is out-dated, I will submit a PR for that.

Tavish9 avatar Aug 07 '25 03:08 Tavish9

If the released chat_template does not handle tool calling, then it can be inferred that the model most likely was not trained for it either during pretraining.

So, it's not suitable to modify the template, as this could lead to a decline in instruction-following ability.

Possible solution might be one-shot prompt engineering. (Most of the VLMs tool calling do this from what I've seen)

One-shot prompt engineering is useful. From my experiments, without training, 3B VL models could correctly use my tools for over 50% cases, just by a very brief instruction at the begining. (similar to instructions in chat template of qwen 3b). However, the chat template is not supported currently. Any recommendations of other VLMs which support tool call? This doc and related code has supported VLMs, it is such a pity if all the VLMs are abandoned.

Yuqi-Hu-2001 avatar Aug 07 '25 03:08 Yuqi-Hu-2001

So, it's not suitable to modify the template, as this could lead to a decline in instruction-following ability. I do not quite understand the reason, what if our research goal is to make the VLM learn to follow instructions and use the tools? By one-shot prompts, it can already successfully use the tool (just json format tool, just some locations which qwen models can do) in most of cases, and RL could help it perform better. In my perspective, if modify the chat template could make the experiments run normally without other bugs, this solution can be reasonable.

Yuqi-Hu-2001 avatar Aug 07 '25 03:08 Yuqi-Hu-2001

Any recommendations of other VLMs which support tool call? This doc and related code has supported VLMs, it is such a pity if all the VLMs are abandoned.

stepfun can: stepfun-ai/step3

Tavish9 avatar Aug 07 '25 04:08 Tavish9

what if our research goal is to make the VLM learn to follow instructions and use the tools?

You can use one-shot prompt to reach your goal, without modifying the chat-template.

if modify the chat template could make the experiments run normally without other bugs, this solution can be reasonable.

Yes you can modify the template for downstream finetuning. But this model might not be used as general any more.

Tavish9 avatar Aug 07 '25 04:08 Tavish9

Thanks a lot, for stepfun model, I do not need to modify the chat template. For qwen, I could modify, but the model will not be used as general. Right? Thanks a lot for clarifying this.

Yuqi-Hu-2001 avatar Aug 07 '25 04:08 Yuqi-Hu-2001

You got it.

Tavish9 avatar Aug 07 '25 04:08 Tavish9

Thanks a lot, for stepfun model, I do not need to modify the chat template. For qwen, I could modify, but the model will not be used as general. Right? Thanks a lot for clarifying this.

You can refer to #2398.

Maxwell-Jia avatar Aug 08 '25 10:08 Maxwell-Jia

Thanks a lot, for stepfun model, I do not need to modify the chat template. For qwen, I could modify, but the model will not be used as general. Right? Thanks a lot for clarifying this.

You can refer to #2398.

Thanks a lot, this feature is so close to my project!

Yuqi-Hu-2001 avatar Aug 08 '25 13:08 Yuqi-Hu-2001