Skip to content

[Tests] Start oneshot tests on CPU #1555

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

kylesayrs
Copy link
Collaborator

Purpose

  • Speed up tests by reducing device movement

Background

As of #1263, the model is dispatched to different device maps depending on which pipelines are used. If the model starts on anything but the CPU, then these dispatches and undispatches create device movement. Starting on the CPU will ensure no device movement occurs when offloaded dispatches happen.

@kylesayrs kylesayrs marked this pull request as draft June 16, 2025 19:49
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.

Summary of Changes

Hello @kylesayrs, 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 aims to enhance the efficiency and speed of our test suite by optimizing how large language models are loaded. By ensuring models are initially loaded onto the CPU, we eliminate redundant device transfers that previously slowed down test execution, particularly in scenarios involving dynamic device mapping.

Highlights

  • Test Performance Improvement: I have removed the device_map="auto" argument from AutoModelForCausalLM.from_pretrained calls across several test files. This change ensures that models are initially loaded onto the CPU, preventing automatic device movement that can incur performance overhead in test environments.
  • Reduced Device Movement: By explicitly allowing models to load on the CPU (the default when device_map is not specified), I've addressed a known issue where models dispatched to non-CPU devices would cause unnecessary device transfers during subsequent offloaded dispatches, as noted in issue [Performance] Sequential onloading #1263.
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 in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands.

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 issue 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 is currently in preview and 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 to provide feedback.

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

The pull request aims to optimize test execution speed by ensuring models in oneshot tests are initially loaded onto the CPU. This is achieved by removing the device_map="auto" parameter from AutoModelForCausalLM.from_pretrained calls across various test files. The rationale, as described, is that starting on the CPU prevents potentially suboptimal device mapping by device_map="auto", thereby reducing unnecessary device-to-device data movements when subsequent offloaded dispatches occur.

The changes are consistent, targeted, and directly address the stated purpose. By defaulting to CPU loading, the tests should have a more predictable starting state for device management, which is intended to improve test efficiency. This modification appears well-aligned with the goal of streamlining test performance.

No issues of medium, high, or critical severity were identified in these changes.

Base automatically changed from kylesayrs/sequential-onloading to main June 17, 2025 20:45
@kylesayrs kylesayrs force-pushed the kylesayrs/testing-device-map branch from bd8db69 to 8d575e2 Compare June 20, 2025 22:14
@kylesayrs kylesayrs marked this pull request as ready for review June 20, 2025 22:15
@kylesayrs kylesayrs added the ready When a PR is ready for review label Jun 20, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ready When a PR is ready for review
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants