Skip to content
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

Print the reminder for the illegal memory error in the AutoBatchSize under tf #4283

Merged
merged 3 commits into from
Oct 31, 2024

Conversation

Yi-FanLi
Copy link
Collaborator

@Yi-FanLi Yi-FanLi commented Oct 30, 2024

#3822 added a reminder for the illegal memory error. However, this reminder is only needed for tf. This PR moves the illegal memory reminder from base class AutoBatchSize to the inherited class under tf.

Summary by CodeRabbit

  • New Features
    • Enhanced AutoBatchSize class to initialize batch size from an environment variable, improving user guidance on memory management with TensorFlow.
  • Bug Fixes
    • Removed redundant logging during initialization to streamline the process when GPU resources are available.

Copy link
Contributor

coderabbitai bot commented Oct 30, 2024

📝 Walkthrough

Walkthrough

The changes in this pull request focus on the AutoBatchSize class within two files: deepmd/tf/utils/batch_size.py and deepmd/utils/batch_size.py. Modifications include the addition of a log import and initialization of the DP_INFER_BATCH_SIZE variable in the former, while the latter involves the removal of a log message from the constructor. These adjustments aim to streamline the class's initialization process without altering its core functionality.

Changes

File Path Change Summary
deepmd/tf/utils/batch_size.py Added import for log, initialized DP_INFER_BATCH_SIZE from environment variable, added log message for memory access issues.
deepmd/utils/batch_size.py Removed a log message from the __init__ method regarding DP_INFER_BATCH_SIZE.

Possibly related PRs

  • Add a reminder for the illegal memory error #3822: This PR adds a log message in the batch_size.py file to guide users on setting the DP_INFER_BATCH_SIZE environment variable to avoid illegal memory access errors, which is directly related to the changes made in the AutoBatchSize class in the main PR.

Suggested labels

Core

Suggested reviewers

  • wanghan-iapcm

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

codecov bot commented Oct 30, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 84.30%. Comparing base (d165fee) to head (94b2d41).

Additional details and impacted files
@@           Coverage Diff           @@
##            devel    #4283   +/-   ##
=======================================
  Coverage   84.29%   84.30%           
=======================================
  Files         553      553           
  Lines       51820    51827    +7     
  Branches     3052     3052           
=======================================
+ Hits        43683    43692    +9     
+ Misses       7177     7176    -1     
+ Partials      960      959    -1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Outside diff range and nitpick comments (1)
deepmd/tf/utils/batch_size.py (1)

22-31: Simplify the conditional logic structure

While the implementation correctly moves the TF-specific memory error handling to this class, we can simplify the nested conditions.

Consider this cleaner structure:

 def __init__(self, initial_batch_size: int = 1024, factor: float = 2.0) -> None:
     super().__init__(initial_batch_size, factor)
     DP_INFER_BATCH_SIZE = int(os.environ.get("DP_INFER_BATCH_SIZE", 0))
-    if not DP_INFER_BATCH_SIZE > 0:
-        if self.is_gpu_available():
-            log.info(
+    if not DP_INFER_BATCH_SIZE > 0 and self.is_gpu_available():
+        log.info(
🧰 Tools
🪛 Ruff

25-26: Use a single if statement instead of nested if statements

(SIM102)

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 94b2d41 and 5870a93.

📒 Files selected for processing (1)
  • deepmd/tf/utils/batch_size.py (2 hunks)
🧰 Additional context used
🪛 Ruff
deepmd/tf/utils/batch_size.py

25-26: Use a single if statement instead of nested if statements

(SIM102)

🔇 Additional comments (2)
deepmd/tf/utils/batch_size.py (2)

Line range hint 2-18: LGTM: Import changes align with PR objectives

The new imports support the relocation of the logging functionality from the base class to this TF-specific implementation.

🧰 Tools
🪛 Ruff

25-26: Use a single if statement instead of nested if statements

(SIM102)


22-32: Implementation successfully meets PR objectives

The changes effectively:

  1. Move the illegal memory reminder to the TF-specific class
  2. Only show the message in relevant contexts (GPU with TF)
  3. Maintain helpful guidance for users
🧰 Tools
🪛 Ruff

25-26: Use a single if statement instead of nested if statements

(SIM102)

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Outside diff range and nitpick comments (1)
deepmd/tf/utils/batch_size.py (1)

22-30: LGTM with a minor suggestion for robustness

The constructor implementation successfully moves the TensorFlow-specific memory error reminder to the appropriate class. The message is clear and actionable.

Consider adding error handling for invalid environment variable values:

-        DP_INFER_BATCH_SIZE = int(os.environ.get("DP_INFER_BATCH_SIZE", 0))
+        try:
+            DP_INFER_BATCH_SIZE = int(os.environ.get("DP_INFER_BATCH_SIZE", 0))
+        except ValueError:
+            log.warning("Invalid DP_INFER_BATCH_SIZE value, defaulting to 0")
+            DP_INFER_BATCH_SIZE = 0
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between d165fee and 94b2d41.

📒 Files selected for processing (2)
  • deepmd/tf/utils/batch_size.py (2 hunks)
  • deepmd/utils/batch_size.py (0 hunks)
💤 Files with no reviewable changes (1)
  • deepmd/utils/batch_size.py
🔇 Additional comments (2)
deepmd/tf/utils/batch_size.py (2)

16-18: LGTM: Clean import addition

The log import is properly placed and follows the existing import style.


22-30: Verify corresponding removal in base class

Let's confirm that the reminder message was properly removed from the base class.

✅ Verification successful

The verification results show that:

  1. The reminder message is not present in the base class (deepmd/utils/batch_size.py)
  2. The reminder message is only present in the TF-specific class (deepmd/tf/utils/batch_size.py)

Let me verify if this was indeed a move from base class to TF-specific class by checking the git history:


Verified: Reminder message correctly moved from base to TF-specific class

The git history confirms that the reminder message was properly moved from the base class (AutoBatchSize in deepmd/utils/batch_size.py) to the TF-specific class in deepmd/tf/utils/batch_size.py. This aligns with the PR's objective of making the TensorFlow-specific error message only appear in the TF implementation.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify that the reminder message was removed from the base class
# and only exists in the TF-specific class

# Check for the reminder message in the base class
echo "Checking base class (should not find the message):"
rg "an illegal memory access was encountered" "deepmd/utils/batch_size.py"

# Check for the reminder message in the TF class (should find the message)
echo -e "\nChecking TF class (should find the message):"
rg "an illegal memory access was encountered" "deepmd/tf/utils/batch_size.py"

Length of output: 497


Script:

#!/bin/bash
# Check git history for the reminder message to confirm it was moved
git log -p | rg -B 5 -A 5 "an illegal memory access was encountered"

Length of output: 3149

@wanghan-iapcm wanghan-iapcm added this pull request to the merge queue Oct 31, 2024
Merged via the queue into deepmodeling:devel with commit 0d13911 Oct 31, 2024
51 checks passed
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.

3 participants