Skip to content

Conversation

@caic99
Copy link
Member

@caic99 caic99 commented Aug 15, 2025

Summary by CodeRabbit

  • New Features

    • Training entrypoints now accept YAML configuration files in addition to JSON, offering more flexibility when launching training.
    • Unified configuration loading across frameworks for consistent behavior (PyTorch, Paddle, TensorFlow).
    • Backward compatible: existing JSON-based workflows continue to work unchanged.
  • Tests

    • Added coverage to verify YAML input produces the expected training output.
    • Improved test cleanup to remove generated artifacts after execution.

@caic99 caic99 requested review from Copilot and iProzd and removed request for Copilot August 15, 2025 08:18
Copilot AI review requested due to automatic review settings August 15, 2025 08:20
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Aug 15, 2025

📝 Walkthrough

Walkthrough

Unified config loading across PD/PT entrypoints by switching to deepmd.common.j_loader and updated TF entrypoint to import j_loader from deepmd.common. Added a test to verify YAML input handling in PT training and cleanup of generated artifacts.

Changes

Cohort / File(s) Summary of changes
PD/PT entrypoint config loading
deepmd/pd/entrypoints/main.py, deepmd/pt/entrypoints/main.py
Import j_loader from deepmd.common; replace manual JSON loading with config = j_loader(input_file) inside train(); function signatures unchanged.
TF entrypoint import path
deepmd/tf/entrypoints/train.py
Changed j_loader import source from deepmd.tf.common to deepmd.common; no logic changes.
PT training tests (YAML support)
source/tests/pt/test_training.py
Import train as train_entry; add test_yaml_input to exercise YAML config path and assert out.json creation; enhance tearDown to remove out.json and input.yaml.

Sequence Diagram(s)

sequenceDiagram
  participant Test as Test (pytest)
  participant Entry as PT Train Entrypoint
  participant Loader as deepmd.common.j_loader
  participant Train as Training Logic

  Test->>Entry: train_entry(input_file="input.yaml", ..., output="out.json")
  Entry->>Loader: j_loader("input.yaml")
  Loader-->>Entry: config (parsed YAML/JSON)
  Entry->>Train: run(config, params...)
  Train-->>Entry: writes out.json
  Entry-->>Test: return
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Tip

🔌 Remote MCP (Model Context Protocol) integration is now available!

Pro plan users can now connect to remote MCP servers from the Integrations page. Connect with popular remote MCPs such as Notion and Linear to add more context to your reviews and chats.

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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.
    • 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.
  • 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 the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

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

CodeRabbit Commands (Invoked using PR/Issue comments)

Type @coderabbitai help to get the list of available commands.

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

Status, Documentation and Community

  • Visit our Status Page to check the current availability of CodeRabbit.
  • 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: 1

🧹 Nitpick comments (3)
deepmd/pd/entrypoints/main.py (1)

239-239: Using j_loader(input_file) to enable YAML config: looks good; consider adding a Paddle YAML test

This aligns PD with PT/TF. To prevent regressions, consider adding a minimal PD test that:

  • writes self.config to input.yaml,
  • invokes pd.entrypoints.main.train(..., input_file="input.yaml", skip_neighbor_stat=True, output="out.json"),
  • asserts out.json exists.

I can draft that test if helpful.

source/tests/pt/test_training.py (2)

184-201: Solid YAML acceptance test; use a temp directory to avoid cross-test artifact collisions

Writing input.yaml and out.json to CWD can clash under parallel runs. Prefer a temp dir to confine artifacts and avoid extra cleanup.

Apply this diff:

-    def test_yaml_input(self) -> None:
-        import yaml
-
-        yaml_file = Path("input.yaml")
-        with open(yaml_file, "w") as fp:
-            yaml.safe_dump(self.config, fp)
-        train_entry(
-            input_file=str(yaml_file),
-            init_model=None,
-            restart=None,
-            finetune=None,
-            init_frz_model=None,
-            model_branch="main",
-            skip_neighbor_stat=True,
-            output="out.json",
-        )
-        self.assertTrue(Path("out.json").exists())
+    def test_yaml_input(self) -> None:
+        import yaml
+        import tempfile
+
+        with tempfile.TemporaryDirectory() as td:
+            td_path = Path(td)
+            yaml_file = td_path / "input.yaml"
+            out_file = td_path / "out.json"
+            with open(yaml_file, "w") as fp:
+                yaml.safe_dump(self.config, fp)
+            train_entry(
+                input_file=str(yaml_file),
+                init_model=None,
+                restart=None,
+                finetune=None,
+                init_frz_model=None,
+                model_branch="main",
+                skip_neighbor_stat=True,
+                output=str(out_file),
+            )
+            self.assertTrue(out_file.exists())

202-206: Optional: conditional cleanup can be dropped if using a temp dir

If you adopt the temp-dir approach above, this manual cleanup becomes unnecessary; otherwise, keeping it is fine.

📜 Review details

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

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled by default for public repositories
  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between e73bbff and 959367f.

📒 Files selected for processing (4)
  • deepmd/pd/entrypoints/main.py (2 hunks)
  • deepmd/pt/entrypoints/main.py (2 hunks)
  • deepmd/tf/entrypoints/train.py (1 hunks)
  • source/tests/pt/test_training.py (2 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (2)
deepmd/pd/entrypoints/main.py (2)
source/tests/tf/common.py (1)
  • j_loader (38-39)
source/tests/pd/common.py (1)
  • j_loader (23-24)
source/tests/pt/test_training.py (1)
deepmd/pt/entrypoints/main.py (2)
  • main (517-576)
  • train (242-365)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (20)
  • GitHub Check: Build C++ (cpu, cpu)
  • GitHub Check: Build C++ (cuda120, cuda)
  • GitHub Check: Test Python (5, 3.9)
  • GitHub Check: Test Python (2, 3.9)
  • GitHub Check: Test Python (1, 3.12)
  • GitHub Check: Test Python (2, 3.12)
  • GitHub Check: Test Python (3, 3.12)
  • GitHub Check: Test Python (3, 3.9)
  • GitHub Check: Test C++ (false)
  • GitHub Check: Test C++ (true)
  • GitHub Check: Build wheels for cp311-macosx_arm64
  • GitHub Check: Build wheels for cp310-manylinux_aarch64
  • GitHub Check: Build wheels for cp311-win_amd64
  • GitHub Check: Build wheels for cp311-macosx_x86_64
  • GitHub Check: Build wheels for cp311-manylinux_x86_64
  • GitHub Check: Build wheels for cp311-manylinux_x86_64
  • GitHub Check: Analyze (python)
  • GitHub Check: Analyze (c-cpp)
  • GitHub Check: Build C library (2.18, libdeepmd_c.tar.gz)
  • GitHub Check: Build C library (2.14, >=2.5.0,<2.15, libdeepmd_c_cu11.tar.gz)
🔇 Additional comments (4)
deepmd/pd/entrypoints/main.py (1)

24-26: Unified config loader import (deepmd.common.j_loader): LGTM

Centralizing on a single loader promotes consistency and enables YAML support across entrypoints.

deepmd/pt/entrypoints/main.py (2)

26-29: Unified config loader import (deepmd.common.j_loader): LGTM

Consistent with PD/TF; simplifies maintenance and enables YAML parsing uniformly.


258-258: Load config via j_loader(input_file): LGTM and enables YAML support

This is the key change the new test exercises; no functional regressions expected for JSON.

source/tests/pt/test_training.py (1)

19-19: Expose train_entry alias for tests: LGTM

Keeps callsites readable and decoupled from module path changes.

@HydrogenSulfate
Copy link
Collaborator

If you don’t mind, I’d like to recommend trying the YAML configuration mechanism based on Hydra + OmegaConf. It’s a more powerful YAML configuration approach that is very convenient for automated experiments. We’ve adopted this method in PaddleScience, which makes it easy to run automated serial and parallel experiments.
https://paddlescience-docs.readthedocs.io/zh-cn/latest/zh/user_guide/#113

@codecov
Copy link

codecov bot commented Aug 18, 2025

Codecov Report

❌ Patch coverage is 66.66667% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 84.29%. Comparing base (dc99ba2) to head (09b3275).
⚠️ Report is 70 commits behind head on devel.

Files with missing lines Patch % Lines
deepmd/pd/entrypoints/main.py 0.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##            devel    #4894      +/-   ##
==========================================
- Coverage   84.29%   84.29%   -0.01%     
==========================================
  Files         702      702              
  Lines       68664    68663       -1     
  Branches     3572     3572              
==========================================
- Hits        57883    57881       -2     
  Misses       9641     9641              
- Partials     1140     1141       +1     

☔ 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.

@caic99 caic99 requested a review from njzjz August 18, 2025 03:58
@njzjz njzjz added this pull request to the merge queue Aug 18, 2025
Merged via the queue into deepmodeling:devel with commit 1e75042 Aug 18, 2025
60 checks passed
@caic99 caic99 deleted the codex/add-yaml-input-support-and-unit-test branch August 19, 2025 02:54
ChiahsinChu pushed a commit to ChiahsinChu/deepmd-kit that referenced this pull request Dec 17, 2025
<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->

## Summary by CodeRabbit

* **New Features**
* Training entrypoints now accept YAML configuration files in addition
to JSON, offering more flexibility when launching training.
* Unified configuration loading across frameworks for consistent
behavior (PyTorch, Paddle, TensorFlow).
* Backward compatible: existing JSON-based workflows continue to work
unchanged.

* **Tests**
* Added coverage to verify YAML input produces the expected training
output.
  * Improved test cleanup to remove generated artifacts after execution.

<!-- end of auto-generated comment: release notes by coderabbit.ai -->

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
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