Skip to content

Comments

fix: video fps accumulation bug in _collate_prompt_completion#413

Open
yurekami wants to merge 1 commit intounslothai:mainfrom
yurekami:fix-319-video-only-samples
Open

fix: video fps accumulation bug in _collate_prompt_completion#413
yurekami wants to merge 1 commit intounslothai:mainfrom
yurekami:fix-319-video-only-samples

Conversation

@yurekami
Copy link
Contributor

Summary

  • Fixed broken video fps handling in prompt/completion collation path
  • Enables video-only samples to work correctly

Problem

In _collate_prompt_completion, there were multiple bugs with fps accumulation:

  1. No batch-level accumulator: video_kwargs was not initialized, so fps values couldn't be accumulated across examples
  2. Self-extending bug: Line vids_kwarg['fps'].extend(vids_kwarg['fps']) was extending the list with itself, doubling values on each iteration
  3. Wrong variable used: After the loop, vids_kwarg (last example's kwargs) was used instead of accumulated values

This caused video-only batches to fail because fps list length didn't match video count.

Changes

  • unsloth_zoo/vision_utils.py:
    • Initialize video_kwargs = {'fps': []} at batch level
    • Fix accumulation: video_kwargs['fps'].extend(vids_kwarg['fps'])
    • Use video_kwargs instead of vids_kwarg after loop

Fixes #319

🤖 Generated with Claude Code

Fixed broken video fps handling in prompt/completion collation:

1. Added batch-level `video_kwargs` initialization to accumulate fps
   values across examples
2. Fixed `vids_kwarg['fps'].extend(vids_kwarg['fps'])` which was
   extending with itself (doubling values) instead of accumulating
3. Changed to use `video_kwargs` instead of per-example `vids_kwarg`
   after the loop

This fixes video-only sample handling where fps values were not being
properly accumulated across batch samples, causing mismatched lengths
between videos and fps lists.

Fixes unslothai#319

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @yurekami, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request addresses critical bugs within the _collate_prompt_completion function that prevented correct video FPS accumulation, particularly impacting video-only samples. The changes ensure that video frame rates are properly collected and processed across a batch, resolving issues where video_kwargs was not initialized, FPS lists were incorrectly extended, and the wrong variable was used for final processing. This fix enables robust handling of video data within the system.

Highlights

  • Video FPS Accumulation Fix: Resolved multiple bugs in _collate_prompt_completion related to video FPS accumulation, ensuring correct handling for video-only samples.
  • Batch-level video_kwargs Initialization: Introduced an explicit initialization of video_kwargs = {'fps': []} at the batch level to correctly accumulate FPS values across examples.
  • Corrected FPS Accumulation Logic: Modified the FPS accumulation line to video_kwargs['fps'].extend(vids_kwarg['fps']), preventing self-extension and ensuring proper aggregation.
  • Consistent Variable Usage: Ensured that the accumulated video_kwargs is consistently used after the loop for processing video parameters, rather than the last example's vids_kwarg.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request effectively addresses a critical bug in video frame-per-second (FPS) handling within the _collate_prompt_completion function. The changes correctly introduce a batch-level accumulator for video keyword arguments, fix the erroneous self-extending list logic, and ensure the accumulated values are used instead of the last example's values. These fixes are well-implemented and directly resolve the issues described, enabling correct processing of video-only samples. The code is now more robust and correct. Great work on this fix!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Vision Utils Breaks on Video Only Samples

1 participant