Help: video is popped after ``_build_messages(doc)``, leading to input videos=None in ``processor()`` when ``filter_overlong_prompts``
Hi, I encountered an error when using a video dataset (with train.parquet containing the path to .mp4 files) and setting filter_overlong_prompts as True.
Within RLHFDataset.maybe_filter_out_long_prompts(), when processor is not None and filter_overlong_prompts is True, the execution order is:
# Step 1: Build messages
messages = self._build_messages(doc) # ← video_key is popped from doc, messages still contain path to mp4 files
# Step 2: Apply chat template
raw_prompt = self.processor.apply_chat_template(messages, ...) # ← video place holders added
# Step 3: Check if video exists (but video_key was already popped!)
if video_key in doc and doc[video_key]: # ← False, process_video() is not executed
videos, video_metadata = zip(*[process_video(video, ...) for video in doc[video_key]], strict=True,)
....
else:
videos = None # ← videos is set as None
videos_kwargs = {}
# Step 4: Call processor with videos=None
processor(text=[raw_prompt], images=images, videos=videos, ...) # ← videos is None, leading to later error
Video data is popped from doc after _build_messages(doc), causing the processor to receive videos=None while the raw_prompt still contains video placeholders. I wonder if there is specific format or type of video data required by train.parquet in VL case or if it is a bug. I would appreciate it if anyone could help me check this.
Thank you for the detailed analysis. This does appear to be a bug in the RLHFDataset.maybe_filter_out_long_prompts() method.
The issue is that _build_messages(doc) pops the video_key from doc, so the subsequent check if video_key in doc always evaluates to False when filter_overlong_prompts=True.
Potential fix: Preserve the video data before calling _build_messages:
# Before _build_messages
video_data = doc.get(video_key, None) if video_key else None
messages = self._build_messages(doc)
raw_prompt = self.processor.apply_chat_template(messages, ...)
# Use preserved video_data instead of checking doc
if video_data:
videos, video_metadata = zip(*[process_video(video, ...) for video in video_data], strict=True)
...
Would you be interested in contributing a PR for this fix? This would benefit other users working with video datasets in RLHF training.
@Kirrito-k423 Thank you very much for the quick response and guidance! 🙏 I'm currently using a similar workaround to avoid this bug, and I am more than happy to contribute a PR to fix it! I will follow your suggestion and mention you when I propose the PR.
I opened a PR for this issue: #5799
The fix avoids mutating the dataset row in _build_messages() during overlong prompt filtering and adds a regression test for video samples.