Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] Cannot convert tensor pt model to tf model #4411

Open
ChiahsinChu opened this issue Nov 24, 2024 · 1 comment
Open

[BUG] Cannot convert tensor pt model to tf model #4411

ChiahsinChu opened this issue Nov 24, 2024 · 1 comment
Labels

Comments

@ChiahsinChu
Copy link
Contributor

Bug summary

I trained a dipole model with pytorch backend. But when I tried to convert it into TensorFlow backed (for further training of the DPLR model), I got an error shown below, which probably comes from the out_bias in the dipole model.

DeePMD-kit Version

DeePMD-kit v3.0.0

Backend and its version

v2.4.1.post302-gUnknown

How did you download the software?

conda

Input Files, Running Commands, Error Log, etc.

Input files: deepmd-kit/examples/water_tensor/dipole/dipole_input_torch.json

Running commands:

dp convert-backend dw_model.pth dw_model.pb

Error Log:

Traceback (most recent call last):
  File "/home/jxzhu/apps/micromamba/2.0.2-2/envs/deepmd-v3.0.0/bin/dp", line 10, in <module>
    sys.exit(main())
             ^^^^^^
  File "/home/jxzhu/apps/micromamba/2.0.2-2/envs/deepmd-v3.0.0/lib/python3.12/site-packages/deepmd/main.py", line 927, in main
    deepmd_main(args)
  File "/home/jxzhu/apps/micromamba/2.0.2-2/envs/deepmd-v3.0.0/lib/python3.12/site-packages/deepmd/entrypoints/main.py", line 86, in main
    convert_backend(**dict_args)
  File "/home/jxzhu/apps/micromamba/2.0.2-2/envs/deepmd-v3.0.0/lib/python3.12/site-packages/deepmd/entrypoints/convert_backend.py", line 27, in convert_backend
    out_hook(OUTPUT, data)
  File "/home/jxzhu/apps/micromamba/2.0.2-2/envs/deepmd-v3.0.0/lib/python3.12/site-packages/deepmd/tf/utils/serialization.py", line 77, in deserialize_to_file
    model = Model.deserialize(data["model"])
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/jxzhu/apps/micromamba/2.0.2-2/envs/deepmd-v3.0.0/lib/python3.12/site-packages/deepmd/tf/model/model.py", line 566, in deserialize
    return Model.get_class_by_type(data.get("type", "standard")).deserialize(
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/jxzhu/apps/micromamba/2.0.2-2/envs/deepmd-v3.0.0/lib/python3.12/site-packages/deepmd/tf/model/model.py", line 834, in deserialize
    ]["bias_atom_e"] + data["@variables"]["out_bias"].reshape(
                       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
ValueError: cannot reshape array of size 6 into shape (2,100)

Steps to Reproduce

git clone https://github.com/deepmodeling/deepmd-kit.git deepmd-kit
cd deepmd-kit/examples/water_tensor/dipole
dp --pt train dipole_input_torch.json
dp --pt freeze -o dw_model.pth
dp convert-backend dw_model.pth dw_model.pb

Further Information, Files, and Links

No response

@njzjz
Copy link
Member

njzjz commented Nov 24, 2024

The conversation needs more work besides this issue, including #3672 and different implementation for sel_type (see documentation).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants