Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions slime/utils/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,9 @@ def _build_messages(data: dict, prompt_key: str, as_conversation: bool, multimod
if multimodal_data is not None:
multimodals[mt.placeholder] = (mt, list(multimodal_data))

if not multimodals:
return prompt

pattern = "(" + "|".join(re.escape(p) for p in multimodals.keys()) + ")"

for message in prompt:
Expand Down
30 changes: 28 additions & 2 deletions tests/test_filter_long_prompt.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,9 @@

import pytest

from slime.utils.data import filter_long_prompt
from slime.utils.data import _build_messages, filter_long_prompt
from slime.utils.types import Sample


NUM_GPUS = 0


Expand Down Expand Up @@ -110,3 +109,30 @@ def test_no_processor_path_still_preserves_order():
kept = filter_long_prompt(samples, _Tokenizer(), None, max_length=100)

assert [s.prompt for s in kept] == ["p0:5", "p2:5"]


@pytest.mark.unit
def test_text_only_row_keeps_string_content_with_multimodal_config():
data = {"prompt": "hello"}

prompt = _build_messages(data, "prompt", as_conversation=True, multimodal_keys={"image": "images"})

assert prompt == [{"role": "user", "content": "hello"}]


@pytest.mark.unit
def test_multimodal_placeholder_expansion_is_unchanged():
data = {"prompt": "look <image> here", "images": ["image.png"]}

prompt = _build_messages(data, "prompt", as_conversation=True, multimodal_keys={"image": "images"})

assert prompt == [
{
"role": "user",
"content": [
{"type": "text", "text": "look "},
{"type": "image", "image": "image.png"},
{"type": "text", "text": " here"},
],
}
]
Loading