verl icon indicating copy to clipboard operation
verl copied to clipboard

When the tool returns an image in Agentloop, the error message "Image features and image tokens do not match" appears.

Open DBMing opened this issue 1 year ago • 0 comments

System Info

bug info I discovered an issue with the official implementation when using tool_agent_loop within Agentloop for multi-round tool calls, and when the tool returns images as results. The specific code is available in a(/experimental/agent_loop/tool_agent_loop.py#L320).

I discovered an issue with the official implementation when using tool_agent_loop within Agentloop for multi-round tool calls, and when the tool results return images. The specific code is as follows:

When the current round's tool result exceeds self.response_length, the multi-round call ends. However, if the current round's tool result includes an image, and that image has already been added to agent_data.image_data, subsequent training will result in the following error message:

File "/root/merge_dev/verl/verl/workers/actor/dp_actor.py", line 339, in compute_log_prob
    entropy, log_probs = self._forward_micro_batch(
                         ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/root/merge_dev/verl/verl/workers/actor/dp_actor.py", line 170, in _forward_micro_batch
    output = self.actor_module(
             ^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/dist-packages/torch/nn/modules/module.py", line 1773, in _wrapped_call_impl
    return self._call_impl(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/dist-packages/torch/nn/modules/module.py", line 1784, in _call_impl
    return forward_call(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/dist-packages/torch/distributed/fsdp/fully_sharded_data_parallel.py", line 854, in forward
    output = self._fsdp_wrapped_module(*args, **kwargs)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/dist-packages/torch/nn/modules/module.py", line 1773, in _wrapped_call_impl
    return self._call_impl(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/dist-packages/torch/nn/modules/module.py", line 1784, in _call_impl
    return forward_call(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/root/merge_dev/verl/verl/models/transformers/qwen3_vl.py", line 261, in forward_with_normal_backend
    outputs = self.model(input_ids, **kwargs)
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/dist-packages/torch/nn/modules/module.py", line 1773, in _wrapped_call_impl
    return self._call_impl(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/dist-packages/torch/nn/modules/module.py", line 1784, in _call_impl
    return forward_call(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/root/merge_dev/verl/verl/models/transformers/qwen3_vl.py", line 244, in qwen3_vl_base_forward
    input_kwargs = _get_input_embeds(
                   ^^^^^^^^^^^^^^^^^^
  File "/root/merge_dev/verl/verl/models/transformers/qwen3_vl.py", line 153, in _get_input_embeds
    raise ValueError(
ValueError: Image features and image tokens do not match: tokens: 1170, features 1404

system info

python scripts/diagnose.py
----------Python Info----------
Version      : 3.12.3
Compiler     : GCC 13.3.0
Build        : ('main', 'Feb  4 2025 14:48:35')
Arch         : ('64bit', 'ELF')
------------Pip Info-----------
Version      : 25.3
Directory    : /usr/local/lib/python3.12/dist-packages/pip
vllm         : 0.11.0
sglang       : 0.5.2
ray          : 2.49.2
torch        : 2.8.0
----------verl Info-----------
Version      : 0.7.0.dev
Directory    : /root/merge_dev/verl/verl
Commit Hash  : 5107987da124b111ee00026224a3db0627a60217

Information

  • [ ] The official example scripts
  • [x] My own modified scripts

Tasks

  • [ ] An officially supported task in the examples folder (such as GLUE/SQuAD, ...)
  • [x] My own task or dataset (give details below)

Reproduction

none

Expected behavior

I believe the code should be modified as shown below. I can submit a PR if needed.

if len(agent_data.response_mask) + len(response_ids) >= self.response_length:
            return AgentState.TERMINATED
if new_images_this_turn:
            if agent_data.image_data is None:
                agent_data.image_data = []
            elif not isinstance(agent_data.image_data, list):
                agent_data.image_data = [agent_data.image_data]
            for image in new_images_this_turn:
                agent_data.image_data.append(image)

DBMing avatar Nov 07 '25 07:11 DBMing