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

feat(pt): support multitask argcheck #3925

Merged
merged 4 commits into from
Jul 2, 2024
Merged

Conversation

iProzd
Copy link
Collaborator

@iProzd iProzd commented Jun 28, 2024

Note that:

  1. docs for multitask args are not supported, may need help.
  2. trim_pattern="_*" is not supported for repeat dict Argument, may need to update dargs.

Summary by CodeRabbit

  • New Features

    • Enhanced training configuration to support multi-task mode with additional arguments for data configuration.
    • Updated example configurations to reflect multi-task mode changes.
  • Bug Fixes

    • Improved logic for updating and normalizing configuration during training regardless of multi-task mode.
  • Dependencies

    • Upgraded dargs package requirement to version >= 0.4.7.
  • Tests

    • Added new test cases for multi-task scenarios in TestExamples class.

Copy link
Contributor

coderabbitai bot commented Jun 28, 2024

Walkthrough

Walkthrough

The changes primarily enhance the multi-task functionalities in the deepmd framework. The train function now processes configurations uniformly regardless of the multi_task flag. New parameters for multi-task mode have been added to argument handling functions, and test cases have been updated to reflect these modifications. Additionally, a dependency upgrade has been made to the dargs package.

Changes

File Change Summary
deepmd/pt/entrypoints/main.py Updated train function to always update and normalize the config, regardless of multi_task.
deepmd/utils/argcheck.py Added new arguments for multi-task mode in training_args and updated gen_args to handle multi-task scenarios.
examples/water_multi_task/pytorch_example/input_torch.json Removed a comment under "loss_dict" for "water_1".
pyproject.toml Upgraded the version requirement for the dargs package from >= 0.4.6 to >= 0.4.7.
source/tests/common/test_examples.py Enhanced the TestExamples class with new imports, a new input_files_multi variable, and modified the test_arguments method to handle multiple input files differently based on input_files_multi.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant TrainFunction as train()
    participant ConfigUpdate as update_and_normalize_config()
    participant ArgsCheck as training_args()

    User->>TrainFunction: Call train(multi_task)
    TrainFunction->>ConfigUpdate: Update and normalize config

    alt multi_task is True
        ConfigUpdate->>TrainFunction: Return updated config
    else multi_task is False
        ConfigUpdate->>TrainFunction: Return updated config
    end
    TrainFunction->>ArgsCheck: Call training_args with multi_task
    ArgsCheck-->>TrainFunction: Return arguments based on multi_task
Loading

In this sequence diagram, the train function handles updating and normalizing the configuration consistently, regardless of the multi_task flag. The training_args function generates arguments based on the multi_task value, reflecting the new enhancements to support multi-task training scenarios.


Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 8b0ec07 and 24ab43d.

Files selected for processing (2)
  • pyproject.toml (1 hunks)
  • source/tests/common/test_examples.py (2 hunks)
Files skipped from review due to trivial changes (1)
  • pyproject.toml
Additional comments not posted (3)
source/tests/common/test_examples.py (3)

18-20: Import looks good.

The import of preprocess_shared_params is necessary for the new multi-task functionality.


58-60: Addition looks good.

The addition of input_files_multi is necessary for the new multi-task functionality.


65-72: Modification looks good.

The modification of the test_arguments method to handle multiple input files differently based on the presence of input_files_multi is necessary for the new multi-task functionality.


Tip

Early access features: enabled

We are currently testing the following features in early access:

  • OpenAI gpt-4o model for code reviews and chat: OpenAI claims that this model is better at understanding and generating code than the previous models. We seek your feedback over the next few weeks before making it generally available.

Note:

  • You can enable or disable early access features from the CodeRabbit UI or by updating the CodeRabbit configuration file.
  • Please join our Discord Community to provide feedback and report issues.
  • OSS projects are currently opted into early access features by default.

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>.
    • 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 generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @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 as 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.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration 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

Outside diff range and nitpick comments (5)
deepmd/pt/entrypoints/main.py (2)

Line range hint 117-117: Remove unused variable assignment.

- with h5py.File(stat_file_path_single, "w") as f:
+ with h5py.File(stat_file_path_single, "w"):

This change removes the unused variable f, addressing the static analysis warning.


Line range hint 373-376: Simplify argument parsing with the ternary operator.

- if not isinstance(args, argparse.Namespace):
-     FLAGS = parse_args(args=args)
- else:
-     FLAGS = args
+ FLAGS = parse_args(args=args) if not isinstance(args, argparse.Namespace) else args

This change simplifies the code by replacing the if-else block with a ternary operator, making the code more concise and readable.

deepmd/utils/argcheck.py (3)

Line range hint 75-75: Specify the stacklevel for warnings.

The function deprecate_argument_extra_check uses warnings.warn without specifying the stacklevel. Specifying stacklevel helps in identifying where the warning was triggered from, making debugging easier.

-            warnings.warn(f"{key} has been removed and takes no effect.", FutureWarning)
+            warnings.warn(f"{key} has been removed and takes no effect.", FutureWarning, stacklevel=2)

Line range hint 1167-1174: Remove unused local variables.

Several local variables (link_lf, link_se_e2_a, link_se_e2_r, link_se_e3, link_se_a_tpe, link_hybrid, link_se_atten, link_se_atten_v2) are defined but never used in the function descrpt_variant_type_args. This is likely a code cleanup issue.

-    link_lf = make_link("loc_frame", "model/descriptor[loc_frame]")
-    link_se_e2_a = make_link("se_e2_a", "model/descriptor[se_e2_a]")
-    link_se_e2_r = make_link("se_e2_r", "model/descriptor[se_e2_r]")
-    link_se_e3 = make_link("se_e3", "model/descriptor[se_e3]")
-    link_se_a_tpe = make_link("se_a_tpe", "model/descriptor[se_a_tpe]")
-    link_hybrid = make_link("hybrid", "model/descriptor[hybrid]")
-    link_se_atten = make_link("se_atten", "model/descriptor[se_atten]")
-    link_se_atten_v2 = make_link("se_atten_v2", "model/descriptor[se_atten_v2]")

Line range hint 2328-2564: Review the structure and logic of training_args and related functions.

The training_args function is well-structured with clear separation of concerns, handling both single and multi-task scenarios. However, ensure that the documentation for each argument is clear and detailed enough for users to understand without ambiguity, especially for complex configurations like multi_task. Consider adding more examples or detailed descriptions in the documentation strings.

However, there's a potential improvement in how documentation is handled:

# Suggestion to improve documentation readability and maintenance
def add_detailed_docs(argument, details):
    argument.doc += " " + details

# Example usage
add_detailed_docs(arg_numb_steps, "This determines how many batches the model is trained with each epoch.")

Copy link

codecov bot commented Jun 28, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 82.88%. Comparing base (4e72a97) to head (24ab43d).
Report is 116 commits behind head on devel.

Additional details and impacted files
@@            Coverage Diff             @@
##            devel    #3925      +/-   ##
==========================================
+ Coverage   82.87%   82.88%   +0.01%     
==========================================
  Files         519      520       +1     
  Lines       50666    50697      +31     
  Branches     3015     3015              
==========================================
+ Hits        41990    42022      +32     
+ Misses       7739     7738       -1     
  Partials      937      937              

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

@iProzd iProzd requested review from njzjz and wanghan-iapcm June 28, 2024 15:10
@iProzd iProzd linked an issue Jun 28, 2024 that may be closed by this pull request
Copy link
Member

@njzjz njzjz left a comment

Choose a reason for hiding this comment

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

Need to bump dargs to >=0.4.7

@njzjz
Copy link
Member

njzjz commented Jun 28, 2024

trim_pattern="_*" is not supported for repeat dict Argument, may need to update dargs.

I checked the dargs API and it is not easy to do so. It uses a sub_hook API but this API is also used by check_strict, which we don't want to call.

Maybe raise an issue in dargs...

@iProzd
Copy link
Collaborator Author

iProzd commented Jul 2, 2024

trim_pattern="_*" is not supported for repeat dict Argument, may need to update dargs.

I checked the dargs API and it is not easy to do so. It uses a sub_hook API but this API is also used by check_strict, which we don't want to call.

Maybe raise an issue in dargs...

Tracked in deepmodeling/dargs#70

@iProzd iProzd added this pull request to the merge queue Jul 2, 2024
Merged via the queue into deepmodeling:devel with commit c98185c Jul 2, 2024
60 checks passed
@iProzd iProzd deleted the multi_arg branch July 2, 2024 10:19
mtaillefumier pushed a commit to mtaillefumier/deepmd-kit that referenced this pull request Sep 18, 2024
Note that:
1. docs for multitask args are not supported, may need help.
2. `trim_pattern="_*"` is not supported for repeat dict Argument, may
need to update dargs.

<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit

- **New Features**
- Enhanced training configuration to support multi-task mode with
additional arguments for data configuration.
  - Updated example configurations to reflect multi-task mode changes.

- **Bug Fixes**
- Improved logic for updating and normalizing configuration during
training regardless of multi-task mode.

- **Dependencies**
  - Upgraded `dargs` package requirement to version `>= 0.4.7`.

- **Tests**
- Added new test cases for multi-task scenarios in `TestExamples` class.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Feature Request] add multi-task arguments
3 participants