Commit e582360
authored
fix(jax): restore jax2tf savedmodel export (deepmodeling#5613)
## Summary
- restore the JAX `.savedmodel` conversion path to use
`jax2tf.convert(...)` instead of the TF2 SavedModel exporter
- keep the TF2 eager exporter on the `.savedmodeltf` suffix
- restore the graph-safe TensorFlow helper code used around the
jax2tf-converted model body and document why these helpers should not be
collapsed into TF2/ndtensorflow shims
## Background
`source/tests/infer/convert-models.sh` documents `.savedmodel` as the
JAX/JAX2TF output suffix and `.savedmodeltf` as the TF2 output suffix.
After deepmodeling#5598, the JAX `.savedmodel` branch delegated to the TF2 exporter,
so freshly exported `.savedmodel` and `.savedmodeltf` artifacts had the
same ordinary TF op structure and no `XlaCallModule` nodes.
This restores the historical contract: `.savedmodel` is a JAX/jax2tf
artifact and should contain `XlaCallModule`; `.savedmodeltf` remains the
TF2 eager SavedModel artifact.
## TF2 JIT note
I also checked why `DP_JIT=1` on the TF2 exporter does not create
`XlaCallModule` nodes. A minimal `tf.function(jit_compile=True)`
SavedModel in TF 2.21 stores `_XlaMustCompile: true` on the
FunctionDef/PartitionedCall, but the serialized graph still contains
ordinary TF ops and no `XlaCallModule`. In contrast, a minimal
`jax2tf.convert(...)` SavedModel serializes `XlaCallModule` nodes. So
`XlaCallModule` is a marker for the jax2tf native serialization path,
not for generic TF2 `jit_compile=True`.
## Validation
- `dp convert-backend source/tests/infer/deeppot_sea.yaml
/tmp/.../deeppot_sea.savedmodel`, parsed `saved_model.pb`: 8
`XlaCallModule` ops
- `dp convert-backend source/tests/infer/deeppot_dpa.yaml
/tmp/.../deeppot_dpa.savedmodel`, parsed `saved_model.pb`: 8
`XlaCallModule` ops
- `dp convert-backend source/tests/infer/deeppot_sea.yaml
/tmp/.../deeppot_sea.savedmodeltf`, parsed `saved_model.pb`: 0 XLA op
names, as expected for TF2 eager export
- `ruff format .`
- `ruff check .`
Please review, @wanghan-iapcm.
<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit
* **New Features**
* Enhanced JAX-based SavedModel export with additional execution
endpoints and metadata queries (including neighbor-list/selection and
output configuration).
* Added in-graph coordinate transforms and improved
neighbor-list/periodic ghost handling for export.
* **Bug Fixes**
* Corrected neighbor-list padding/truncation, cutoff masking, and stable
type-distinguished ordering.
* Improved handling of virtual atoms and empty-cell periodic extension
cases.
* **Tests**
* Migrated neighbor-list/region tests to pure TensorFlow ops.
* Added coverage for model call behavior and SavedModel export contents.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->1 parent b22a3c3 commit e582360
11 files changed
Lines changed: 966 additions & 168 deletions
File tree
- deepmd/jax
- jax2tf
- utils
- source/jax2tf_tests
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | | - | |
| 2 | + | |
3 | 3 | | |
4 | | - | |
5 | | - | |
6 | | - | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
7 | 11 | | |
8 | 12 | | |
9 | 13 | | |
10 | | - | |
11 | | - | |
12 | | - | |
13 | | - | |
14 | 14 | | |
15 | | - | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
16 | 34 | | |
17 | 35 | | |
| 36 | + | |
18 | 37 | | |
19 | | - | |
20 | | - | |
| 38 | + | |
| 39 | + | |
21 | 40 | | |
22 | 41 | | |
23 | 42 | | |
24 | | - | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | | - | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
3 | 10 | | |
4 | 11 | | |
5 | 12 | | |
6 | 13 | | |
7 | | - | |
8 | | - | |
9 | | - | |
10 | 14 | | |
11 | 15 | | |
12 | 16 | | |
13 | 17 | | |
14 | 18 | | |
15 | 19 | | |
16 | | - | |
17 | | - | |
18 | | - | |
19 | | - | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
20 | 23 | | |
21 | | - | |
22 | | - | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
23 | 29 | | |
24 | | - | |
25 | | - | |
26 | | - | |
27 | | - | |
28 | | - | |
29 | | - | |
30 | | - | |
31 | | - | |
32 | | - | |
33 | | - | |
34 | | - | |
35 | | - | |
36 | | - | |
37 | | - | |
38 | | - | |
39 | | - | |
40 | | - | |
41 | | - | |
42 | | - | |
43 | | - | |
44 | | - | |
45 | | - | |
46 | | - | |
47 | 30 | | |
48 | 31 | | |
49 | 32 | | |
50 | 33 | | |
51 | | - | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
52 | 45 | | |
53 | 46 | | |
54 | 47 | | |
| |||
60 | 53 | | |
61 | 54 | | |
62 | 55 | | |
63 | | - | |
64 | | - | |
65 | | - | |
66 | | - | |
67 | | - | |
68 | | - | |
69 | | - | |
70 | | - | |
71 | | - | |
72 | | - | |
73 | | - | |
74 | | - | |
75 | | - | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
76 | 65 | | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
77 | 95 | | |
| 96 | + | |
0 commit comments