Skip to content

Conversation

@fzyzcjy
Copy link
Collaborator

@fzyzcjy fzyzcjy commented Nov 4, 2025

Motivation

Modifications

Accuracy Tests

Benchmarking and Profiling

Checklist

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @fzyzcjy, 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 significantly upgrades the internal debugging dumper utility by introducing more sophisticated control and contextual information. It enables developers to attach global context to dumped files, dynamically manage when and what data is dumped, and provides a new utility for comprehensive tensor inspection. These enhancements aim to streamline the debugging process by offering richer metadata and flexible options for examining intermediate states within the system.

Highlights

  • Enhanced Dumper Context: The dumper now supports a global context (_global_ctx) that allows users to attach arbitrary key-value pairs, such as layer_id, which will be automatically included in the filenames of dumped artifacts for better organization and traceability.
  • Dynamic Dumping Control: New methods set_ctx and override_enable have been introduced, providing programmatic control over the dumper's behavior. Users can now dynamically set context variables and override the dumper's enabled state, offering more flexibility for conditional debugging.
  • Improved Dump Method: The dump method has been updated to include device information for tensors in its log output and accepts a new save parameter, allowing users to log dump information without necessarily writing the data to a file.
  • Comprehensive Tensor Information Utility: A new utility function, get_tensor_info, has been added to provide detailed metadata about tensors, including shape, dtype, device, stride, requires_grad, min/max/mean values, and sample elements, which is invaluable for in-depth debugging.
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

The pull request introduces enhancements to the _Dumper class by adding context management and an override enable flag, which improves flexibility in debugging. New methods set_ctx and override_enable are added, and the dump method is updated to incorporate these features. Additionally, a get_tensor_info utility function is introduced for more detailed tensor logging. The changes are well-structured and improve the debugging capabilities of the dumper.

Comment on lines +156 to +157
torch.set_printoptions(precision=10)
x_sample = str(x.flatten()[:5])
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 torch.set_printoptions calls modify global print settings, which can lead to unexpected behavior if other parts of the application rely on different print options. It's generally safer to manage print options locally or restore them after use. A try...finally block could ensure the original print options are restored.

Suggested change
torch.set_printoptions(precision=10)
x_sample = str(x.flatten()[:5])
original_precision = torch.get_printoptions()['precision']
try:
torch.set_printoptions(precision=10)
x_sample = str(x.flatten()[:5])
finally:
torch.set_printoptions(precision=original_precision)

Comment on lines +37 to +38
self._global_ctx = {}
self._override_enable = None
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

These new attributes _global_ctx and _override_enable are introduced without type hints. Adding type hints would improve code readability and maintainability, making it clearer what type of data these attributes are expected to hold.

Suggested change
self._global_ctx = {}
self._override_enable = None
self._global_ctx: dict = {}
self._override_enable: Optional[bool] = None

Comment on lines +79 to +80
if self._forward_pass_id < 1:
print("Dump without on_forward_pass_start()")
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

The print statement for "Dump without on_forward_pass_start()" is useful for debugging, but it might be better to use a logging mechanism (e.g., logging.warning) instead of print for consistency and better control over log levels in a production environment.

Suggested change
if self._forward_pass_id < 1:
print("Dump without on_forward_pass_start()")
if self._forward_pass_id < 1:
# Consider using logging.warning here for better log management.
print("Dump without on_forward_pass_start()")

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