Skip to content

Conversation

@HwVanICI
Copy link
Collaborator

Description

This PR adds a missing get_device_stats method to TrainController.
The absence of this method caused an AttributeError in the single-controller
PPO workflow when PPOActorController attempted to access device runtime
statistics during training.

Related Issue

Fixes #761

Type of Change

  • Bug fix (non-breaking change that fixes an issue)
  • New feature (non-breaking change that adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not
    work as expected)
  • Documentation update
  • Code refactoring (no functional changes)
  • Performance improvement
  • Test coverage improvement

Checklist

  • I have read the Contributing Guide
  • I have run formatting tools (pre-commit or manual)
  • I have run relevant unit tests and they pass
  • I have added tests for new functionality
  • I have updated documentation if needed
  • My branch is up to date with main
  • This PR introduces breaking changes (if yes, fill out details below)
  • If this PR changes documentation, I have built and previewed it locally with
    jb build docs
  • No critical issues raised by AI reviewers (/gemini review)

Breaking Change Details (if applicable):

N/A

Additional Context

The fix forwards get_device_stats calls from TrainController to the
underlying training engines via RPC, matching the expectations of
PPOActorController and existing training workflows.

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @HwVanICI, 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 a critical bug in the TrainController by introducing the previously missing get_device_stats method. This ensures that the PPOActorController can successfully retrieve device runtime statistics during training, thereby preventing AttributeError exceptions and allowing single-controller PPO workflows to function correctly and gather necessary performance data.

Highlights

  • Missing Method Implementation: Implemented the get_device_stats method within the TrainController class.
  • Bug Fix: Resolved an AttributeError that occurred in the single-controller PPO workflow when PPOActorController attempted to access device runtime statistics.
  • RPC Forwarding: The new get_device_stats method forwards calls to the underlying training engines using RPC, ensuring compatibility with existing training workflows.

🧠 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 correctly identifies and fixes an AttributeError by adding the missing get_device_stats method to TrainController. My review focuses on ensuring the implementation of this new method is robust for various distributed training scenarios. I've suggested an improvement to how device statistics are collected to ensure that in a multi-worker setup, stats from all workers are returned, rather than just from a single worker, which would provide a more accurate and complete view of the system's state.

Comment on lines +490 to +491
def get_device_stats(self):
return self._custom_function_call("get_device_stats")
Copy link
Contributor

Choose a reason for hiding this comment

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

high

The current implementation using _custom_function_call will only return the device statistics from the first data-parallel head worker. This is because _custom_function_call is designed for scenarios where results from workers are either identical or can be merged like tensors. For device statistics, where each worker has unique information, this approach leads to loss of data from other workers.

In a multi-worker environment, this would result in incomplete and potentially misleading statistics. A better approach is to explicitly gather the stats from all workers and return them as a list. This ensures that the caller receives a complete picture of the device status across the entire training setup.

Suggested change
def get_device_stats(self):
return self._custom_function_call("get_device_stats")
def get_device_stats(self):
"""Gets device statistics from all managed workers.
Returns:
list: A list of device statistics objects, one for each worker.
"""
tasks = [
self.scheduler.async_call_engine(worker.id, "get_device_stats")
for worker in self.workers
]
return self._run_async_task(asyncio.gather(*tasks))

@garrett4wade garrett4wade merged commit 4f8a853 into inclusionAI:main Dec 24, 2025
1 check passed
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.

[BUG] Missing get_device_stats in TrainController

2 participants