Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions deepmd/entrypoints/convert.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from deepmd.utils.convert import convert_13_to_20
from deepmd.utils.convert import convert_13_to_20, convert_12_to_20

def convert(
*,
Expand All @@ -7,7 +7,9 @@ def convert(
output_model: str,
**kwargs,
):
if FROM == '1.3':
if FROM == '1.2':
convert_12_to_20(input_model, output_model)
elif FROM == '1.3':
convert_13_to_20(input_model, output_model)
else:
raise RuntimeError('unsupported model version ' + FROM)
4 changes: 2 additions & 2 deletions deepmd/entrypoints/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,7 @@ def parse_args(args: Optional[List[str]] = None):
)

# * convert models
# supported: 1.3->2.0
# supported: 1.2->2.0, 1.3->2.0
parser_transform = subparsers.add_parser(
'convert-from',
parents=[parser_log],
Expand All @@ -370,7 +370,7 @@ def parse_args(args: Optional[List[str]] = None):
parser_transform.add_argument(
'FROM',
type = str,
choices = ['1.3'],
choices = ['1.2', '1.3'],
help="The original model compatibility",
)
parser_transform.add_argument(
Expand Down
31 changes: 31 additions & 0 deletions deepmd/utils/convert.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,15 @@ def convert_13_to_20(input_model: str, output_model: str):
os.remove('frozen_model.pbtxt')
print("the converted output model (2.0 support) is saved in %s" % output_model)

def convert_12_to_20(input_model: str, output_model: str):
convert_pb_to_pbtxt(input_model, 'frozen_model.pbtxt')
convert_dp12_to_dp13('frozen_model.pbtxt')
convert_dp13_to_dp20('frozen_model.pbtxt')
convert_pbtxt_to_pb('frozen_model.pbtxt', output_model)
if os.path.isfile('frozen_model.pbtxt'):
os.remove('frozen_model.pbtxt')
print("the converted output model (2.0 support) is saved in %s" % output_model)

def convert_pb_to_pbtxt(pbfile: str, pbtxtfile: str):
with gfile.FastGFile(pbfile, 'rb') as f:
graph_def = tf.GraphDef()
Expand All @@ -26,6 +35,28 @@ def convert_pbtxt_to_pb(pbtxtfile: str, pbfile: str):
text_format.Merge(file_content, graph_def)
tf.train.write_graph(graph_def, './', pbfile, as_text=False)

def convert_dp12_to_dp13(file):
file_data = ""
with open(file, "r", encoding="utf-8") as f:
ii = 0
lines = f.readlines()
while (ii < len(lines)):
line = lines[ii]
file_data += line
ii+=1
if 'name' in line and ('DescrptSeA' in line or 'ProdForceSeA' in line or 'ProdVirialSeA' in line):
while not('attr' in lines[ii] and '{' in lines[ii]):
file_data += lines[ii]
ii+=1
file_data += ' attr {\n'
file_data += ' key: \"T\"\n'
file_data += ' value {\n'
file_data += ' type: DT_DOUBLE\n'
file_data += ' }\n'
file_data += ' }\n'
with open(file, "w", encoding="utf-8") as f:
f.write(file_data)

def convert_dp13_to_dp20(fname: str):
with open(fname) as fp:
file_content = fp.read()
Expand Down
4 changes: 4 additions & 0 deletions doc/getting-started.md
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,8 @@ The model compression method requires that the version of DeePMD-kit used in ori

## Model inference

Note that the model for inference is required to be compatible with the DeePMD-kit package. See [Model compatibility](troubleshooting/model-compatability.md) for details.

### Python interface
One may use the python interface of DeePMD-kit for model inference, an example is given as follows
```python
Expand Down Expand Up @@ -360,6 +362,8 @@ and then run the program:

## Run MD

Note that the model for MD simulations is required to be compatible with the DeePMD-kit package. See [Model compatibility](troubleshooting/model-compatability.md) for details.

### Run MD with LAMMPS
Include deepmd in the pair_style

Expand Down
15 changes: 13 additions & 2 deletions doc/troubleshooting/model-compatability.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
# Model compatability
# Model compatibility

When the version of DeePMD-kit used to training model is different from the that of DeePMD-kit running MDs, one has the problem of model compatability.
When the version of DeePMD-kit used to training model is different from the that of DeePMD-kit running MDs, one has the problem of model compatibility.

DeePMD-kit guarantees that the codes with the same major and minor revisions are compatible. That is to say v0.12.5 is compatible to v0.12.0, but is not compatible to v0.11.0 nor v1.0.0.

One can execuate `dp convert-from` to convert an old model to a new one.

| Model version | v0.12 | v1.0 | v1.1 | v1.2 | v1.3 | v2.0 |
|:-:|:-----------:|:----------:|:----------:|:----------:|:----------:|:----------:|
| Compatibility | 😢 | 😢 | 😢 | 😊 | 😊 | 😄 |

**Legend**:
- 😄: The model is compatible with the DeePMD-kit package.
- 😊: The model is incompatible with the DeePMD-kit package, but one can execuate `dp convert-from` to convert an old model to v2.0.
- 😢: The model is incompatible with the DeePMD-kit package, and there is no way to convert models.
2 changes: 1 addition & 1 deletion source/op/descrpt.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ typedef double boxtensor_t ;
typedef double compute_t;

REGISTER_OP("Descrpt")
.Attr("T: {float, double}")
.Attr("T: {float, double} = DT_DOUBLE")
.Input("coord: T")
.Input("type: int32")
.Input("natoms: int32")
Expand Down
2 changes: 1 addition & 1 deletion source/op/descrpt_se_a_ef.cc
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ typedef double boxtensor_t ;
typedef double compute_t;

REGISTER_OP("DescrptSeAEf")
.Attr("T: {float, double}")
.Attr("T: {float, double} = DT_DOUBLE")
.Input("coord: T")
.Input("type: int32")
.Input("natoms: int32")
Expand Down
2 changes: 1 addition & 1 deletion source/op/descrpt_se_a_ef_para.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ typedef double boxtensor_t ;
typedef double compute_t;

REGISTER_OP("DescrptSeAEfPara")
.Attr("T: {float, double}")
.Attr("T: {float, double} = DT_DOUBLE")
.Input("coord: T")
.Input("type: int32")
.Input("natoms: int32")
Expand Down
2 changes: 1 addition & 1 deletion source/op/descrpt_se_a_ef_vert.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ typedef double boxtensor_t ;
typedef double compute_t;

REGISTER_OP("DescrptSeAEfVert")
.Attr("T: {float, double}")
.Attr("T: {float, double} = DT_DOUBLE")
.Input("coord: T")
.Input("type: int32")
.Input("natoms: int32")
Expand Down
2 changes: 1 addition & 1 deletion source/op/ewald_recp.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ typedef double boxtensor_t ;
typedef double compute_t;

REGISTER_OP("EwaldRecp")
.Attr("T: {float, double}")
.Attr("T: {float, double} = DT_DOUBLE")
.Input("coord: T")
.Input("charge: T")
.Input("natoms: int32")
Expand Down
6 changes: 3 additions & 3 deletions source/op/gelu_multi_device.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,18 @@
#include "gelu.h"

REGISTER_OP("Gelu")
.Attr("T: {float, double}")
.Attr("T: {float, double} = DT_DOUBLE")
.Input("x: T")
.Output("output: T");

REGISTER_OP("GeluGrad")
.Attr("T: {float, double}")
.Attr("T: {float, double} = DT_DOUBLE")
.Input("dy: T")
.Input("x: T")
.Output("output: T");

REGISTER_OP("GeluGradGrad")
.Attr("T: {float, double}")
.Attr("T: {float, double} = DT_DOUBLE")
.Input("dy: T")
.Input("dy_: T")
.Input("x: T")
Expand Down
2 changes: 1 addition & 1 deletion source/op/map_aparam.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#include "map_aparam.h"

REGISTER_OP("MapAparam")
.Attr("T: {float, double}")
.Attr("T: {float, double} = DT_DOUBLE")
.Input("aparam: T")
.Input("nlist: int32")
.Input("natoms: int32")
Expand Down
2 changes: 1 addition & 1 deletion source/op/neighbor_stat.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ typedef double boxtensor_t ;
typedef double compute_t;

REGISTER_OP("NeighborStat")
.Attr("T: {float, double}")
.Attr("T: {float, double} = DT_DOUBLE")
.Input("coord: T")
.Input("type: int32")
.Input("natoms: int32")
Expand Down
2 changes: 1 addition & 1 deletion source/op/pair_tab.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#include "pair_tab.h"

REGISTER_OP("PairTab")
.Attr("T: {float, double}")
.Attr("T: {float, double} = DT_DOUBLE")
.Input("table_info: double")
.Input("table_data: double")
.Input("type: int32")
Expand Down
10 changes: 6 additions & 4 deletions source/op/prod_env_mat_multi_device.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#include "prod_env_mat.h"

REGISTER_OP("ProdEnvMatA")
.Attr("T: {float, double}")
.Attr("T: {float, double} = DT_DOUBLE")
.Input("coord: T") //atomic coordinates
.Input("type: int32") //atomic type
.Input("natoms: int32") //local atomic number; each type atomic number; daizheyingxiangqude atomic numbers
Expand All @@ -27,7 +27,9 @@ REGISTER_OP("ProdEnvMatA")

// an alias of ProdEnvMatA -- Compatible with v1.3
REGISTER_OP("DescrptSeA")
.Attr("T: {float, double}")
.Attr("T: {float, double} = DT_DOUBLE")
// give a default value to T, compatible with v1.2
// See https://www.tensorflow.org/guide/create_op#backwards_compatibility
.Input("coord: T")
.Input("type: int32")
.Input("natoms: int32")
Expand All @@ -46,7 +48,7 @@ REGISTER_OP("DescrptSeA")
.Output("nlist: int32");

REGISTER_OP("ProdEnvMatR")
.Attr("T: {float, double}")
.Attr("T: {float, double} = DT_DOUBLE")
.Input("coord: T")
.Input("type: int32")
.Input("natoms: int32")
Expand All @@ -64,7 +66,7 @@ REGISTER_OP("ProdEnvMatR")

// an alias of ProdEnvMatR -- Compatible with v1.3
REGISTER_OP("DescrptSeR")
.Attr("T: {float, double}")
.Attr("T: {float, double} = DT_DOUBLE")
.Input("coord: T")
.Input("type: int32")
.Input("natoms: int32")
Expand Down
2 changes: 1 addition & 1 deletion source/op/prod_force.cc
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#include "custom_op.h"

REGISTER_OP("ProdForce")
.Attr("T: {float, double}")
.Attr("T: {float, double} = DT_DOUBLE")
.Input("net_deriv: T")
.Input("in_deriv: T")
.Input("nlist: int32")
Expand Down
2 changes: 1 addition & 1 deletion source/op/prod_force_grad.cc
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#include "custom_op.h"

REGISTER_OP("ProdForceGrad")
.Attr("T: {float, double}")
.Attr("T: {float, double} = DT_DOUBLE")
.Input("grad: T")
.Input("net_deriv: T")
.Input("in_deriv: T")
Expand Down
4 changes: 2 additions & 2 deletions source/op/prod_force_grad_multi_device.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#include "prod_force_grad.h"

REGISTER_OP("ProdForceSeAGrad")
.Attr("T: {float, double}")
.Attr("T: {float, double} = DT_DOUBLE")
.Input("grad: T")
.Input("net_deriv: T")
.Input("in_deriv: T")
Expand All @@ -13,7 +13,7 @@ REGISTER_OP("ProdForceSeAGrad")
.Output("grad_net: T");

REGISTER_OP("ProdForceSeRGrad")
.Attr("T: {float, double}")
.Attr("T: {float, double} = DT_DOUBLE")
.Input("grad: T")
.Input("net_deriv: T")
.Input("in_deriv: T")
Expand Down
4 changes: 2 additions & 2 deletions source/op/prod_force_multi_device.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#include "prod_force.h"

REGISTER_OP("ProdForceSeA")
.Attr("T: {float, double}")
.Attr("T: {float, double} = DT_DOUBLE")
.Input("net_deriv: T")
.Input("in_deriv: T")
.Input("nlist: int32")
Expand All @@ -12,7 +12,7 @@ REGISTER_OP("ProdForceSeA")
.Output("force: T");

REGISTER_OP("ProdForceSeR")
.Attr("T: {float, double}")
.Attr("T: {float, double} = DT_DOUBLE")
.Input("net_deriv: T")
.Input("in_deriv: T")
.Input("nlist: int32")
Expand Down
2 changes: 1 addition & 1 deletion source/op/prod_force_se_a_grad.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#include "prod_force_grad.h"

REGISTER_OP("ProdForceSeAGrad")
.Attr("T: {float, double}")
.Attr("T: {float, double} = DT_DOUBLE")
.Input("grad: T")
.Input("net_deriv: T")
.Input("in_deriv: T")
Expand Down
2 changes: 1 addition & 1 deletion source/op/prod_force_se_r_grad.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#include "prod_force_grad.h"

REGISTER_OP("ProdForceSeRGrad")
.Attr("T: {float, double}")
.Attr("T: {float, double} = DT_DOUBLE")
.Input("grad: T")
.Input("net_deriv: T")
.Input("in_deriv: T")
Expand Down
2 changes: 1 addition & 1 deletion source/op/prod_virial.cc
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#include "custom_op.h"

REGISTER_OP("ProdVirial")
.Attr("T: {float, double}")
.Attr("T: {float, double} = DT_DOUBLE")
.Input("net_deriv: T")
.Input("in_deriv: T")
.Input("rij: T")
Expand Down
2 changes: 1 addition & 1 deletion source/op/prod_virial_grad.cc
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#include "custom_op.h"

REGISTER_OP("ProdVirialGrad")
.Attr("T: {float, double}")
.Attr("T: {float, double} = DT_DOUBLE")
.Input("grad: T")
.Input("net_deriv: T")
.Input("in_deriv: T")
Expand Down
4 changes: 2 additions & 2 deletions source/op/prod_virial_grad_multi_device.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#include "prod_virial_grad.h"

REGISTER_OP("ProdVirialSeAGrad")
.Attr("T: {float, double}")
.Attr("T: {float, double} = DT_DOUBLE")
.Input("grad: T")
.Input("net_deriv: T")
.Input("in_deriv: T")
Expand All @@ -14,7 +14,7 @@ REGISTER_OP("ProdVirialSeAGrad")
.Output("grad_net: T");

REGISTER_OP("ProdVirialSeRGrad")
.Attr("T: {float, double}")
.Attr("T: {float, double} = DT_DOUBLE")
.Input("grad: T")
.Input("net_deriv: T")
.Input("in_deriv: T")
Expand Down
4 changes: 2 additions & 2 deletions source/op/prod_virial_multi_device.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#include "prod_virial.h"

REGISTER_OP("ProdVirialSeA")
.Attr("T: {float, double}")
.Attr("T: {float, double} = DT_DOUBLE")
.Input("net_deriv: T")
.Input("in_deriv: T")
.Input("rij: T")
Expand All @@ -14,7 +14,7 @@ REGISTER_OP("ProdVirialSeA")
.Output("atom_virial: T");

REGISTER_OP("ProdVirialSeR")
.Attr("T: {float, double}")
.Attr("T: {float, double} = DT_DOUBLE")
.Input("net_deriv: T")
.Input("in_deriv: T")
.Input("rij: T")
Expand Down
2 changes: 1 addition & 1 deletion source/op/prod_virial_se_a_grad.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#include "prod_virial_grad.h"

REGISTER_OP("ProdVirialSeAGrad")
.Attr("T: {float, double}")
.Attr("T: {float, double} = DT_DOUBLE")
.Input("grad: T")
.Input("net_deriv: T")
.Input("in_deriv: T")
Expand Down
2 changes: 1 addition & 1 deletion source/op/prod_virial_se_r_grad.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#include "prod_virial_grad.h"

REGISTER_OP("ProdVirialSeRGrad")
.Attr("T: {float, double}")
.Attr("T: {float, double} = DT_DOUBLE")
.Input("grad: T")
.Input("net_deriv: T")
.Input("in_deriv: T")
Expand Down
Loading