Skip to content

feat(jax): support shared_dict in multi-task training#5740

Merged
njzjz merged 4 commits into
deepmodeling:masterfrom
njzjz:feat/jax-shared-dict
Jul 12, 2026
Merged

feat(jax): support shared_dict in multi-task training#5740
njzjz merged 4 commits into
deepmodeling:masterfrom
njzjz:feat/jax-shared-dict

Conversation

@njzjz

@njzjz njzjz commented Jul 6, 2026

Copy link
Copy Markdown
Member

Summary

  • move shared_dict preprocessing and shared-link traversal into dpmodel utilities
  • reuse the common shared-link traversal from pt_expt and JAX backends
  • enable JAX multi-task shared_dict preprocessing and apply shared descriptor/fitting links before optimizer setup

Tests

  • ruff check .
  • ruff format deepmd/dpmodel/utils/multi_task.py deepmd/jax/utils/multi_task.py deepmd/jax/entrypoints/train.py deepmd/jax/train/trainer.py deepmd/pt_expt/utils/multi_task.py deepmd/pt_expt/train/wrapper.py source/tests/jax/test_training.py
  • pytest source/tests/jax/test_training.py -q
  • pytest source/tests/pt_expt/test_multitask.py::TestMultiTaskSeA::test_multitask_train source/tests/pt_expt/test_multitask.py::TestMultiTaskSeAShareFit::test_multitask_train -q

Note

  • ruff format --check . currently reports existing unrelated formatting drift in dpa_adapt/cli.py.

Summary by CodeRabbit

  • New Features
    • Multi-task models can now declare shared_dict to reuse descriptor and fitting settings across model branches.
    • Shared-parameter “links” are created during config preprocessing and then applied when building the JAX training model.
  • Bug Fixes
    • Improved validation and resume-aware merging of shared descriptor and fitting statistics during training.
  • Tests
    • Added JAX regression coverage for shared_dict preprocessing, link propagation, and correct shared-stat/parameter behavior.

Copilot AI review requested due to automatic review settings July 6, 2026 08:40
@dosubot dosubot Bot added the new feature label Jul 6, 2026
@github-actions github-actions Bot added the Python label Jul 6, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@njzjz
njzjz requested a review from wanghan-iapcm July 6, 2026 08:42
Comment thread deepmd/jax/utils/multi_task.py Fixed
Comment thread deepmd/jax/utils/multi_task.py Fixed
@coderabbitai

coderabbitai Bot commented Jul 6, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: efc0e511-3b7b-4ba9-9888-509e3f7ac7de

📥 Commits

Reviewing files that changed from the base of the PR and between 0b0d3ba and 5b327a7.

📒 Files selected for processing (1)
  • deepmd/dpmodel/utils/multi_task.py
🚧 Files skipped from review as they are similar to previous changes (1)
  • deepmd/dpmodel/utils/multi_task.py

📝 Walkthrough

Walkthrough

This PR adds backend-neutral multi-task shared-parameter preprocessing and application, integrates shared_dict support into JAX training, reuses the utilities in pt_expt, and adds JAX regression tests for sharing and statistic merging.

Changes

Multi-task shared parameter support

Layer / File(s) Summary
Common multi-task shared-link utilities
deepmd/dpmodel/utils/multi_task.py
Adds shared_dict preprocessing, link traversal, descriptor accessors, atomic-model lookup, link sanitization, and probability-ratio handling.
JAX entrypoint and preprocessing wiring
deepmd/jax/utils/multi_task.py, deepmd/jax/entrypoints/train.py
Adds JAX class resolution and preprocessing, tracks shared_links, and passes them into DPTrainer.
JAX trainer shared-parameter application
deepmd/jax/train/trainer.py
Applies descriptor and fitting links during setup, including resume-aware sharing and weighted statistic merging.
pt_expt refactor to reuse shared helpers
deepmd/pt_expt/train/wrapper.py, deepmd/pt_expt/utils/multi_task.py
Delegates shared-link application and multi-task preprocessing to common utilities.
JAX multitask training tests
source/tests/jax/test_training.py
Adds coverage for preprocessing, link propagation, object sharing, and weighted statistic merges.

Estimated code review effort: 4 (Complex) | ~60 minutes

Possibly related PRs

Suggested labels: enhancement

Suggested reviewers: wanghan-iapcm, iProzd

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes the main change: adding shared_dict support to multi-task training, especially for JAX.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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

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

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@deepmd/jax/entrypoints/train.py`:
- Around line 109-117: The shared-task preprocessing in `TrainEntrypoint` can
leave `self.shared_links` stale because `preprocess_shared_params()` runs before
the later `init_model`/`use_pretrain_script` model replacement in the same flow.
Update the `is_multi_task` handling so the final `config["model"]` is
established before calling `preprocess_shared_params()`, or explicitly clear and
recompute `self.shared_links` after any model overwrite, ensuring the value
passed to `DPTrainer` matches the actual model.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 6af13361-7181-40a4-bfcf-d87b6ac5eccc

📥 Commits

Reviewing files that changed from the base of the PR and between 3d73c67 and 568b0cd.

📒 Files selected for processing (7)
  • deepmd/dpmodel/utils/multi_task.py
  • deepmd/jax/entrypoints/train.py
  • deepmd/jax/train/trainer.py
  • deepmd/jax/utils/multi_task.py
  • deepmd/pt_expt/train/wrapper.py
  • deepmd/pt_expt/utils/multi_task.py
  • source/tests/jax/test_training.py

Comment thread deepmd/jax/entrypoints/train.py Outdated
@codecov

codecov Bot commented Jul 6, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 78.18930% with 53 lines in your changes missing coverage. Please review.
✅ Project coverage is 79.53%. Comparing base (3d73c67) to head (5b327a7).
⚠️ Report is 15 commits behind head on master.

Files with missing lines Patch % Lines
deepmd/dpmodel/utils/multi_task.py 75.93% 32 Missing ⚠️
deepmd/jax/train/trainer.py 75.64% 19 Missing ⚠️
deepmd/jax/entrypoints/train.py 87.50% 1 Missing ⚠️
deepmd/jax/utils/multi_task.py 93.33% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #5740      +/-   ##
==========================================
- Coverage   81.36%   79.53%   -1.83%     
==========================================
  Files         991     1017      +26     
  Lines      111198   115900    +4702     
  Branches     4235     4277      +42     
==========================================
+ Hits        90474    92183    +1709     
- Misses      19199    22173    +2974     
- Partials     1525     1544      +19     

☔ View full report in Codecov by Harness.
📢 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.

Comment thread deepmd/jax/train/trainer.py
@njzjz
njzjz requested a review from wanghan-iapcm July 8, 2026 11:15
Comment thread deepmd/dpmodel/utils/multi_task.py Outdated
@njzjz
njzjz requested a review from wanghan-iapcm July 10, 2026 15:58
@njzjz
njzjz added this pull request to the merge queue Jul 11, 2026
Merged via the queue into deepmodeling:master with commit c175b9b Jul 12, 2026
56 checks passed
@njzjz
njzjz deleted the feat/jax-shared-dict branch July 12, 2026 01:05
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.

5 participants