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] DPA-2 model cannot convert to .dp format #4295

Open
njzjz opened this issue Nov 1, 2024 · 0 comments
Open

[BUG] DPA-2 model cannot convert to .dp format #4295

njzjz opened this issue Nov 1, 2024 · 0 comments
Labels
Milestone

Comments

@njzjz
Copy link
Member

njzjz commented Nov 1, 2024

Bug summary

When converting a DPA-2 .pth model to .dp format, an error is thrown (see below).

The reason is that we assume all NumPy arrays are in the @variables keys in the serialization data (see #2982). However, it seems that some arrays are stored out of the @variables.

if self.update_style == "res_residual":
data.update(
{
"g1_residual": [to_numpy_array(t) for t in self.g1_residual],
"g2_residual": [to_numpy_array(t) for t in self.g2_residual],
"h2_residual": [to_numpy_array(t) for t in self.h2_residual],
}
)
return data

We don't have a check to check it.

We need to discuss whether we insist on this rule.

DeePMD-kit Version

devel

Backend and its version

How did you download the software?

Built from source

Input Files, Running Commands, Error Log, etc.

Traceback (most recent call last):
  File "/home/jz748/anaconda3/bin/dp", line 8, in <module>
    sys.exit(main())
  File "/home/jz748/codes/deepmd-kit/deepmd/main.py", line 926, in main
    deepmd_main(args)
  File "/home/jz748/codes/deepmd-kit/deepmd/entrypoints/main.py", line 86, in main
    convert_backend(**dict_args)
  File "/home/jz748/codes/deepmd-kit/deepmd/entrypoints/convert_backend.py", line 27, in convert_backend
    out_hook(OUTPUT, data)
  File "/home/jz748/codes/deepmd-kit/deepmd/dpmodel/utils/serialization.py", line 106, in save_dp_model
    f.attrs["json"] = json.dumps(save_dict, separators=(",", ":"))
  File "/home/jz748/anaconda3/lib/python3.10/json/__init__.py", line 238, in dumps
    **kw).encode(obj)
  File "/home/jz748/anaconda3/lib/python3.10/json/encoder.py", line 199, in encode
    chunks = self.iterencode(o, _one_shot=True)
  File "/home/jz748/anaconda3/lib/python3.10/json/encoder.py", line 257, in iterencode
    return _iterencode(o, 0)
  File "/home/jz748/anaconda3/lib/python3.10/json/encoder.py", line 179, in default
    raise TypeError(f'Object of type {o.__class__.__name__} '
TypeError: Object of type ndarray is not JSON serializable

Steps to Reproduce

cd examples/water/dpa2
# change the number of steps to 0
dp --pt train input_torch_small.json
dp --pt freeze
dp convert-backend frozen_model.pth frozen_model.dp

Further Information, Files, and Links

No response

@njzjz njzjz added the bug label Nov 1, 2024
@njzjz njzjz added this to the v3.0.0 milestone Nov 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

No branches or pull requests

1 participant