Skip to content

Avoid sync CUDA transfer in data loader#1443

Merged
finbarrtimbers merged 2 commits intomainfrom
codex/fix-cuda-warning-in-data_loader.py
Mar 18, 2026
Merged

Avoid sync CUDA transfer in data loader#1443
finbarrtimbers merged 2 commits intomainfrom
codex/fix-cuda-warning-in-data_loader.py

Conversation

@finbarrtimbers
Copy link
Copy Markdown
Collaborator

Motivation

  • Prevent the runtime warning about synchronizing CUDA operations when moving batch tensors to the device by avoiding redundant transfers and enabling non-blocking device moves.

Description

  • Change to_device in open_instruct/data_loader.py to skip non-tensor entries, avoid re-moving tensors already on the target device, and use non_blocking=True when moving CPU tensors to a CUDA device; also add a changelog entry referencing this PR (https://github.com/allenai/open-instruct/pull/0000).

Testing

  • Ran make style && make quality which passed, and uv run pytest which finished with 495 passed, 6 skipped.

Codex Task

@gemini-code-assist
Copy link
Copy Markdown
Contributor

Summary of Changes

Hello @finbarrtimbers, 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 focuses on enhancing the data loading process by optimizing how tensors are moved to compute devices, particularly CUDA. The changes aim to eliminate performance bottlenecks and warnings associated with synchronous data transfers and unnecessary device-to-device operations, leading to a smoother and more efficient data pipeline.

Highlights

  • Optimized CUDA Data Transfers: The to_device utility function in open_instruct/data_loader.py has been refactored to prevent synchronous CUDA operations and redundant data transfers. This addresses runtime warnings and improves efficiency when moving batch tensors to a CUDA device.
  • Enhanced to_device Logic: The to_device function now intelligently handles batch items by skipping non-tensor entries, avoiding re-moving tensors that are already on the target device, and utilizing non_blocking=True specifically when transferring tensors from CPU to a CUDA device.
  • Changelog Update: A new entry has been added to CHANGELOG.md documenting the fix for avoiding synchronous CUDA transfers during batch processing.

🧠 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
Copy Markdown
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 improves the to_device function in the data loader to avoid synchronous CUDA transfers. It achieves this by skipping tensors already on the target device and using non_blocking=True for CPU-to-CUDA transfers. The changes are correct and align with the goal of preventing runtime warnings. I've added a couple of suggestions: one to update a placeholder PR number in the changelog, and another to refactor the to_device function for better conciseness.

Comment thread CHANGELOG.md Outdated
Comment thread open_instruct/data_loader.py Outdated
@finbarrtimbers finbarrtimbers force-pushed the codex/fix-cuda-warning-in-data_loader.py branch from 80a75ae to b397deb Compare March 18, 2026 15:12
…hangelog Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@finbarrtimbers finbarrtimbers added this pull request to the merge queue Mar 18, 2026
Merged via the queue into main with commit 03703a4 Mar 18, 2026
6 of 7 checks passed
@finbarrtimbers finbarrtimbers deleted the codex/fix-cuda-warning-in-data_loader.py branch March 18, 2026 16:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants