Skip to content

Conversation

@iProzd
Copy link
Collaborator

@iProzd iProzd commented May 21, 2025

Summary by CodeRabbit

  • New Features

    • Added support for the "AdamW" optimizer in training configurations.
    • Introduced a "weight_decay" parameter for optimizer settings, with a default value of 0.001.
  • Chores

    • Updated configuration options to allow selection of "AdamW" as an optimizer type.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented May 21, 2025

Warning

Rate limit exceeded

@iProzd has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 2 minutes and 5 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

📥 Commits

Reviewing files that changed from the base of the PR and between 5e79487 and 6e20c18.

📒 Files selected for processing (1)
  • deepmd/pt/train/training.py (3 hunks)
📝 Walkthrough

Walkthrough

The changes add support for the "AdamW" optimizer in the training module, including a new "weight_decay" parameter. The optimizer selection logic and argument validation are updated to accept "AdamW" as a valid option, alongside the existing "Adam" and "LKF" optimizers. No other public interfaces are modified.

Changes

File(s) Change Summary
deepmd/pt/train/training.py Added support for "AdamW" optimizer, including handling of "weight_decay" parameter and selection logic.
deepmd/utils/argcheck.py Updated argument validation to include "AdamW" as a valid optimizer type option.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant TrainingConfig
    participant TrainingModule
    participant Optimizer

    User->>TrainingConfig: Specify opt_type ("Adam" or "AdamW") and weight_decay
    TrainingConfig->>TrainingModule: Pass configuration
    TrainingModule->>Optimizer: Initialize with opt_type and weight_decay
    Optimizer-->>TrainingModule: Return optimizer instance (Adam or AdamW)
    TrainingModule->>TrainingModule: Proceed with training loop using optimizer
Loading
✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ 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.
    • Explain this complex logic.
    • 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 explain this code block.
    • @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 explain its main purpose.
    • @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.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

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 generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this 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: 0

🧹 Nitpick comments (1)
deepmd/pt/train/training.py (1)

613-626: Good implementation of AdamW optimizer support.

The code correctly extends the optimizer initialization to handle both "Adam" and "AdamW" types, initializing the appropriate PyTorch optimizer in each case.

Consider simplifying line 618 from fused=False if DEVICE.type == "cpu" else True to fused=DEVICE.type != "cpu" for better readability.

-            fused=False if DEVICE.type == "cpu" else True,
+            fused=DEVICE.type != "cpu",

Also, for consistency, consider adding the fused parameter to the AdamW optimizer as well if it's supported in your PyTorch version:

            self.optimizer = torch.optim.AdamW(
                self.wrapper.parameters(),
                lr=self.lr_exp.start_lr,
                weight_decay=float(self.opt_param["weight_decay"]),
+               fused=DEVICE.type != "cpu",
            )
🧰 Tools
🪛 Ruff (0.11.9)

618-618: Use not ... instead of False if ... else True

Replace with not ...

(SIM211)

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 8176173 and 5e79487.

📒 Files selected for processing (2)
  • deepmd/pt/train/training.py (3 hunks)
  • deepmd/utils/argcheck.py (1 hunks)
🧰 Additional context used
🪛 Ruff (0.11.9)
deepmd/pt/train/training.py

618-618: Use not ... instead of False if ... else True

Replace with not ...

(SIM211)

🔇 Additional comments (3)
deepmd/utils/argcheck.py (1)

3180-3180: AdamW optimizer addition looks good!

The addition of "AdamW" as a valid optimizer type is appropriate and aligns with the PR objective to add AdamW support for PyTorch training. This change ensures the argument validation system recognizes AdamW as a valid option alongside the existing Adam and LKF optimizers.

deepmd/pt/train/training.py (2)

161-161: Good addition of weight_decay parameter.

The implementation correctly adds a weight_decay parameter with a default value of 0.001, which will be used by the AdamW optimizer.


721-721: Good update to the optimizer condition in training step.

The condition has been correctly updated to include "AdamW" along with "Adam" for the optimizer type check, ensuring the learning rate scheduler and optimization step logic work for both optimizers.

@codecov
Copy link

codecov bot commented May 21, 2025

Codecov Report

❌ Patch coverage is 80.00000% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 84.73%. Comparing base (8176173) to head (6e20c18).
⚠️ Report is 86 commits behind head on devel.

Files with missing lines Patch % Lines
deepmd/pt/train/training.py 80.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##            devel    #4757      +/-   ##
==========================================
+ Coverage   84.70%   84.73%   +0.02%     
==========================================
  Files         697      697              
  Lines       67424    67426       +2     
  Branches     3541     3540       -1     
==========================================
+ Hits        57112    57132      +20     
+ Misses       9182     9161      -21     
- Partials     1130     1133       +3     

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

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@iProzd iProzd added this pull request to the merge queue May 22, 2025
github-merge-queue bot pushed a commit that referenced this pull request May 22, 2025
<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->

## Summary by CodeRabbit

- **New Features**
  - Added support for the "AdamW" optimizer in training configurations.
- Introduced a "weight_decay" parameter for optimizer settings, with a
default value of 0.001.

- **Chores**
- Updated configuration options to allow selection of "AdamW" as an
optimizer type.

<!-- end of auto-generated comment: release notes by coderabbit.ai -->
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks May 22, 2025
@iProzd iProzd added this pull request to the merge queue May 22, 2025
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks May 22, 2025
@iProzd iProzd added this pull request to the merge queue May 22, 2025
Merged via the queue into deepmodeling:devel with commit 2279459 May 22, 2025
60 checks passed
@iProzd iProzd deleted the D0520_adamw branch May 22, 2025 17:24
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