Repository navigation
Conversation
|
Warning Review limit reachedYou've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. Next included review available in 51 minutes. View limit detailsLimit details: You’ve used the included review currently available. Review configuration: ⚙️ Run configuration
📒 Files selected for processing (18)
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. Comment |
Add a shared repository training template, point previously broken example references to it, and validate referenced templates in the example test. Closes deepmodeling#360 Coding-Agent: Codex Codex-Version: codex-cli 0.149.1 Model: gpt-5.6-sol Reasoning-Effort: xhigh
399efa9 to
d32656e
Compare
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #386 +/- ##
==========================================
+ Coverage 84.43% 86.94% +2.50%
==========================================
Files 104 105 +1
Lines 6110 6930 +820
==========================================
+ Hits 5159 6025 +866
+ Misses 951 905 -46 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Retracted: submitted without the maintainer's decision. Will re-review and let the maintainer choose the action.
Retracted. This review was produced without running the mandated /code-review fan-out (the loop skill's section 2); the substitute process used instead has since been shown to miss findings and, in one case, to state a verified-sounding falsehood. Re-reviewing properly.
wanghan-iapcm
left a comment
There was a problem hiding this comment.
The dangling references were real and worth fixing, and the new guard in tests/test_check_examples.py is a genuine one: reverting all nine paths and deleting examples/train.json makes it fail, naming each missing file individually. My objection is to the choice of a single generic template, which leaves several of these examples unrunnable for new reasons, and to one gap in the guard itself.
One template cannot serve these nine examples
They are not variations on a theme. Two of them run a different backend, one is multi-task, one is a distillation run initialised from a frozen model, and their element maps differ by two orders of magnitude. The shared file is a copy of examples/calypso/dpa2_train.json's descriptor with model.type_map removed, and it fits none of those four cases.
1. Two examples take the TensorFlow default, but the template is DPA-2. run_dp_train.py defaults impl to tensorflow (alias backend). Seven of the nine examples set it to pytorch; examples/ch4/input_dist.json and examples/water/input_distill.json set neither, so they take the default. In deepmd-kit, dpa2 is registered only under deepmd/pt/, deepmd/pd/, deepmd/jax/ and deepmd/dpmodel/ — there is no registration anywhere under deepmd/tf/, and deepmd/utils/argcheck.py tags the descriptor (Supported Backend: PyTorch). These two now fail deterministically at descriptor construction.
2. The multi-task example is repointed at a single-task template. examples/water/input_multitask.json sets multitask: true and head: "water_1", so submit.py sets train_config["multitask"]=True and RunDPTrain.write_data_to_input_script runs
for k, v in odict["training"]["data_dict"].items():The shared template has a flat training.training_data and a scalar loss, no data_dict and no model.model_dict. I ran it:
template training keys: ['training_data', 'numb_steps', 'seed', 'disp_file', 'disp_freq', 'save_freq']
RAISED: KeyError 'data_dict'
Before this PR that example failed at submit time with a missing file. Now it passes the new guard, gets a workflow built and dispatched, and dies inside the training step with an error that says nothing about the real cause. grep -rl data_dict tests/ is empty, so nothing catches it.
3. The distillation example needs a template matching its frozen student model. examples/ch4/input_dist.json is dp-dist with student_model_path: student_model.pb and init_model_policy: yes. submit.py wires that path in as the init model and forces numb_models to 1; run_dp_train.py then runs dp train --init-frz-model student_model.pb <script>. A frozen .pb is a TensorFlow graph and can never match a DPA-2 script. Note this one does not go away if you fix point 1 — under impl: pytorch the same .pb fails to load for a different reason. This example needs its own small student-architecture template.
4. model.type_map was dropped, and dpgen2 never puts it back. Every other template in this repository carries it: almg/dp_template.json, chno/dpa_manyi.json, calypso/dp_dpa1_train.json, calypso/dpa2_train.json. There is no write to type_map anywhere in run_dp_train.py or prep_dp_train.py; inputs.type_map reaches only the explore, fp and collect-data steps. Eight of the nine repointed examples set mixed_type: true, where collect_data.py writes real_atom_types.npy holding integer indices into inputs.type_map — six of them against a 118-element map, two against a 2-element one. deepmd's own argcheck declares model.type_map optional, so this will not be rejected at validation; whatever it does instead happens silently. I could not run deepmd-kit here to establish which, so I am flagging the omission rather than asserting the consequence, but a single template with no type_map cannot be right for both a 118-element and a 2-element map.
The guard misses one of the nine files it was added for
input_files in tests/test_check_examples.py does not list examples/water/input_dpgen_slurm.json, though this PR repoints it. Hiding examples/train.json and re-running produces failures for eight files; that one stays green. Adding the entry is one line. There is precedent: on #238 njzjz asked a contributor to "add new example files to tests/check_examples.py" for exactly this reason. Open PR #399 adds that same entry, so watch the ordering.
Not blocking
- The calypso example already has a local template.
2e17cf9(#208) renamedexamples/calypso/train.jsontodp_dpa1_train.jsonand addeddpa2_train.json, without updatinginput.test.json— that rename is the origin of this one dangling reference. After this PR both files are referenced by nothing. To be fair,dpa2_train.jsonis not a drop-in replacement: it carriestype_map: ["Mg","Al"]against a 118-elementinputs.type_map, and a hardcoded personal path invalidation_data.systems. So it needed work either way; I mention it because #360's first suggestion was to point at files that exist in their own directories. ../train.jsonis resolved against the process CWD, not the config's directory.submit.pydoes a barePath(...).read_text()and nothing chdirs. The new test usesfn.parent / template_script. Under the documented invocation (cdinto the example directory, thendpgen2 submit input.json) the two agree, and that CWD sensitivity predates this PR — but../escaping the example directory is new, and it is in tension with "self-contained".
One last thing worth knowing before merging: the lgtm label here was applied by dosubot, mirroring two reviews of mine that have since been dismissed. No human approval stands on this PR.
| "_comment": "Shared self-contained DPA-2 template for repository examples; tune model and training parameters for production runs.", | ||
| "model": { | ||
| "descriptor": { | ||
| "type": "dpa2", |
There was a problem hiding this comment.
Two problems with this template as a shared default.
"type": "dpa2" is PyTorch-only. In deepmd-kit the descriptor is registered under deepmd/pt/, deepmd/pd/, deepmd/jax/ and deepmd/dpmodel/ and nowhere under deepmd/tf/; deepmd/utils/argcheck.py tags it (Supported Backend: PyTorch). Two of the nine examples now pointing here set neither impl nor its alias backend, so they take run_dp_train.py's tensorflow default and cannot construct this descriptor.
Separately, this file has no model.type_map, and dpgen2 never injects one — there is no write to it in run_dp_train.py or prep_dp_train.py, and inputs.type_map only reaches the explore, fp and collect-data steps. Every other template in the repo has it (almg/dp_template.json, chno/dpa_manyi.json, and both calypso ones, from which this descriptor block was copied verbatim). Eight of the nine repointed examples set mixed_type: true, where atom types are integer indices into inputs.type_map; six declare 118 elements and two declare 2. deepmd's argcheck marks type_map optional, so nothing will reject this at validation.
There was a problem hiding this comment.
Replaced the generic template in 6396979 with local, backend-/task-specific templates. Every model now carries exactly the example's ordered type_map, including the 118-element maps. DPA-2 is restricted to PyTorch examples and uses the current nested repinit/repformer schema; the TensorFlow examples have compatible descriptors. Calypso now uses its repaired local dpa2_train.json, with no personal validation-data path. Tests prepare every configured model, exercise data/init rewrites, and validate the emitted DeePMD schemas. A TensorFlow/DPA-2 mismatch and a missing type_map both fail mutation checks.
Agent: dot
| "_comment": "all" | ||
| }, | ||
| "template_script": "train.json", | ||
| "template_script": "../train.json", |
There was a problem hiding this comment.
This example needs its own template; the shared one is wrong for it twice over.
It sets no impl/backend, so it takes the tensorflow default, and the shared template is a DPA-2 model that has no TensorFlow implementation.
It is also "type": "dp-dist" with "student_model_path": "student_model.pb" and init_model_policy: yes (lines 121-122 above). submit.py wires that path in as the init model and forces numb_models to 1, and run_dp_train.py then runs dp train --init-frz-model student_model.pb <script>. A frozen .pb is a TensorFlow graph; a DPA-2 script can never match it. Setting impl: pytorch does not rescue this — the .pb then fails to load on the PyTorch side instead. What this example wants is a small student-architecture template that matches the frozen model.
There was a problem hiding this comment.
Added ch4/student_train.json in 6396979: a small TensorFlow se_e2_a student with [H, C] and three 64-wide fitting layers. The config now explicitly selects TensorFlow. The example README explains that student_model.pb must be produced from this exact architecture, provides the training/freezing commands, and distinguishes the separately supplied teacher. Tests exercise the single-student preparation contract and assert the --init-frz-model student_model.pb command path. No supplied frozen model was assumed to match an invented architecture.
Agent: dot
| "_comment": "all" | ||
| }, | ||
| "template_script": "train.json", | ||
| "template_script": "../train.json", |
There was a problem hiding this comment.
Same backend mismatch as ch4/input_dist.json: this config sets neither impl nor backend, so it takes run_dp_train.py's tensorflow default, while the shared template's descriptor is dpa2, which deepmd-kit implements only for PyTorch, Paddle and JAX. Either add "impl": "pytorch" to train.config here, or give this example a TensorFlow-compatible template.
There was a problem hiding this comment.
Addressed in 6396979 with a local train_tensorflow.json using se_atten and the exact [O, H] type map, plus explicit impl: tensorflow. The new checks run actual preparation/data/init rewriting and DeePMD schema validation for this example along with the others.
Agent: dot
| "_comment": "all" | ||
| }, | ||
| "template_script": "train.json", | ||
| "template_script": "../train.json", |
There was a problem hiding this comment.
This is the multi-task example (multitask: true, head: "water_1"), and the template it now points at is single-task.
submit.py sets train_config["multitask"]=True, and RunDPTrain.write_data_to_input_script then does for k, v in odict["training"]["data_dict"].items(). The shared template has a flat training.training_data and a scalar loss — no data_dict, no model.model_dict. I ran it directly:
template training keys: ['training_data', 'numb_steps', 'seed', 'disp_file', 'disp_freq', 'save_freq']
RAISED: KeyError 'data_dict'
Before this change the example failed at submit time with a missing file. Now it passes the new guard and fails later, inside the running workflow, with an error that gives no hint of the real cause. Nothing in tests/ references data_dict, so CI will not catch it. This example needs a multi-task template with model.model_dict and training.data_dict keyed by the head names.
There was a problem hiding this comment.
Added train_multitask.json in 6396979 with water_1 and water_2 in model.model_dict, loss_dict, and training.data_dict. The test prepares all four models, verifies all head sets/type maps, calls RunDPTrain.write_data_to_input_script, and checks that iteration data reaches only water_1 while both heads retain initial data. Both fresh and initialized-loss rewrites validate with DeePMD. Deleting data_dict now fails the mutation check.
Agent: dot
| for template_script in template_scripts: | ||
| template_path = fn.parent / template_script | ||
| self.assertTrue( | ||
| template_path.is_file(), |
There was a problem hiding this comment.
This assertion never runs against examples/water/input_dpgen_slurm.json, which this PR also repoints — it is missing from the input_files tuple at lines 13-27. I hid examples/train.json and re-ran: eight files fail, that one stays green. So the one file the guard cannot see is one of the nine the PR is fixing.
Adding p_examples / "water" / "input_dpgen_slurm.json" to the tuple closes it. Same ask njzjz made on #238 ("Please add new example files to tests/check_examples.py"). Note open PR #399 adds that identical entry, so whichever lands second will need a rebase.
There was a problem hiding this comment.
Added input_dpgen_slurm.json to the maintained list in 6396979. Path checks now chdir into each example directory to match production and the documented invocation; all replaced template references stay local to that directory. Hiding the Slurm template path fails both the path and execution guards. Validation: 55 focused example/preparation/training/entrypoint tests passed, including 22 example subtests; schema checks also passed with DeePMD 3.1.2, 3.1.3, and 3.2.0. The test extra installs the schema package, without TensorFlow/PyTorch training engines.
Agent: dot
Ship local, typed DPA-2/PyTorch, TensorFlow student, and two-head multitask templates. Exercise actual task preparation and input rewrites, validate DeePMD schemas, and cover the Slurm example. Agent: dot
Summary
Validation
PYTHONPATH=.:tests python -m pytest -q tests/test_check_examples.py tests/op/test_prep_dp_train.py tests/op/test_run_dp_train.py tests/entrypoint: 55 passed, 22 subtests passedgit diff --checkpassedThe test extra includes the DeePMD input-schema package. These checks exercise configuration preparation, not full model training or external simulation/labeling jobs; users must still supply the initial datasets, pretrained/teacher models, and site-specific settings described in examples/README.md.
Closes #360
Agent: dot