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

chore: move LearningRateExp to deepmd.utils.learning_rate #4219

Merged
merged 3 commits into from
Oct 17, 2024

Conversation

njzjz
Copy link
Member

@njzjz njzjz commented Oct 15, 2024

Summary by CodeRabbit

  • New Features

    • Introduced a new exponential decay learning rate scheduler to enhance training efficiency.
    • Added functionality to compute learning rates at specific training steps.
  • Bug Fixes

    • Removed the outdated LearningRateExp class from the previous module to avoid confusion.

Copy link
Contributor

coderabbitai bot commented Oct 15, 2024

📝 Walkthrough
📝 Walkthrough

Walkthrough

The changes involve the removal of the LearningRateExp class from the deepmd/pt/utils/learning_rate.py file, including its constructor and value method. The __all__ declaration has been updated to include LearningRateExp, despite its removal. Conversely, new LearningRateExp classes have been introduced in both deepmd/utils/learning_rate.py and deepmd/dpmodel/utils/learning_rate.py, each implementing an exponential decay learning rate scheduler with constructors and methods to compute the learning rate at specific training steps.

Changes

File Path Change Summary
deepmd/pt/utils/learning_rate.py Removed LearningRateExp class, constructor, and value method; updated __all__ to include "LearningRateExp".
deepmd/utils/learning_rate.py Added new LearningRateExp class with constructor and value method for exponential decay learning rate scheduling.
deepmd/dpmodel/utils/learning_rate.py Added new LearningRateExp class with constructor and value method for exponential decay learning rate scheduling.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant LearningRateExp as Old_LearningRateExp
    participant LearningRateExp as New_LearningRateExp

    User->>Old_LearningRateExp: Instantiate
    Old_LearningRateExp-->>User: Class removed

    User->>New_LearningRateExp: Instantiate
    New_LearningRateExp-->>User: Class added
    User->>New_LearningRateExp: Call value(step)
    New_LearningRateExp-->>User: Returns computed learning rate
Loading

Possibly related PRs


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
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: 4

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 16172e6 and 367d33e.

📒 Files selected for processing (2)
  • deepmd/pt/utils/learning_rate.py (1 hunks)
  • deepmd/utils/learning_rate.py (1 hunks)
✅ Files skipped from review due to trivial changes (1)
  • deepmd/pt/utils/learning_rate.py
🧰 Additional context used

deepmd/utils/learning_rate.py Outdated Show resolved Hide resolved
deepmd/utils/learning_rate.py Outdated Show resolved Hide resolved
deepmd/utils/learning_rate.py Outdated Show resolved Hide resolved
deepmd/utils/learning_rate.py Outdated Show resolved Hide resolved
Copy link

codecov bot commented Oct 15, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 83.51%. Comparing base (16172e6) to head (90c6f9a).

Additional details and impacted files
@@           Coverage Diff           @@
##            devel    #4219   +/-   ##
=======================================
  Coverage   83.50%   83.51%           
=======================================
  Files         541      542    +1     
  Lines       52486    52488    +2     
  Branches     3043     3047    +4     
=======================================
+ Hits        43830    43833    +3     
  Misses       7708     7708           
+ Partials      948      947    -1     

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

@njzjz
Copy link
Member Author

njzjz commented Oct 16, 2024

Or, should we move it to deepmd.dpmodel.utils.learning_rate?

@iProzd
Copy link
Collaborator

iProzd commented Oct 16, 2024

Or, should we move it to deepmd.dpmodel.utils.learning_rate?

Is it easy to merge both tf and pt? If not (so far), deepmd.dpmodel.utils.learning_rate is better to me.

@njzjz
Copy link
Member Author

njzjz commented Oct 16, 2024

Is it easy to merge both tf and pt?

No, for performance, TF needs a static graph, even for the learning rate.

Signed-off-by: Jinzhe Zeng <[email protected]>
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 (2)
deepmd/dpmodel/utils/learning_rate.py (2)

37-40: Clarify the fallback mechanism for decay_steps in the docstring.

The logic for setting decay_steps includes a fallback mechanism that's not explained in the docstring. Consider adding an explanation in the docstring about how decay_steps is adjusted if it's greater than or equal to stop_steps.


6-14: Consider adding type hints to the constructor parameters.

Adding type hints to the constructor parameters would improve code readability and maintainability. It would also help catch potential type-related errors earlier in the development process.

Here's a suggested implementation with type hints:

def __init__(
    self,
    start_lr: float,
    stop_lr: float,
    decay_steps: int,
    stop_steps: int,
    decay_rate: Optional[float] = None,
    **kwargs,
) -> None:
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 367d33e and 465a0d8.

📒 Files selected for processing (2)
  • deepmd/dpmodel/utils/learning_rate.py (1 hunks)
  • deepmd/pt/utils/learning_rate.py (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • deepmd/pt/utils/learning_rate.py
🧰 Additional context used
🔇 Additional comments (3)
deepmd/dpmodel/utils/learning_rate.py (3)

5-5: LGTM: Class structure is appropriate for an exponential decay learning rate scheduler.

The LearningRateExp class provides a good structure for implementing an exponential decay learning rate scheduler. It includes a constructor for initialization and a method to compute the learning rate at a given step.


48-53: LGTM: The value method is correctly implemented.

The value method correctly implements the exponential decay formula for the learning rate. It also properly enforces the minimum learning rate (stop_lr). The use of a return type hint (np.float64) is a good practice for code clarity.


1-53: Overall assessment: Well-implemented exponential decay learning rate scheduler.

The LearningRateExp class provides a solid implementation of an exponential decay learning rate scheduler. The code is well-structured, documented, and follows good practices. The suggested improvements (clarifying the fallback mechanism for decay_steps and adding type hints) are minor and would further enhance the code's readability and maintainability.

Great job on implementing this functionality!

@iProzd iProzd added this pull request to the merge queue Oct 17, 2024
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Oct 17, 2024
@wanghan-iapcm wanghan-iapcm added this pull request to the merge queue Oct 17, 2024
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Oct 17, 2024
@njzjz njzjz added this pull request to the merge queue Oct 17, 2024
Merged via the queue into deepmodeling:devel with commit cc4b23d Oct 17, 2024
51 checks passed
@njzjz njzjz deleted the move-learning-rate branch October 17, 2024 18:09
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