From 866726e5b65e09bba6a9afefe3dbcee42c7eea96 Mon Sep 17 00:00:00 2001 From: Jinzhe Zeng Date: Thu, 5 Sep 2024 21:19:24 -0400 Subject: [PATCH] fix(pt): convert `torch.__version__` to `str` when serializing (#4106) ```py >>> type(torch.__version__) ``` This causes a YAML error: ``` File "/home/jz748/anaconda3/lib/python3.10/site-packages/yaml/representer.py", line 231, in represent_undefined raise RepresenterError("cannot represent an object", data) yaml.representer.RepresenterError: ('cannot represent an object', '2.3.1+cu121') ``` ## Summary by CodeRabbit - **Bug Fixes** - Improved the serialization of the PyTorch version by ensuring it is represented as a string, enhancing data clarity and consistency. Signed-off-by: Jinzhe Zeng --- deepmd/pt/utils/serialization.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/deepmd/pt/utils/serialization.py b/deepmd/pt/utils/serialization.py index 98906ca455..aab6d100a5 100644 --- a/deepmd/pt/utils/serialization.py +++ b/deepmd/pt/utils/serialization.py @@ -47,7 +47,7 @@ def serialize_from_file(model_file: str) -> dict: model_dict = model.serialize() data = { "backend": "PyTorch", - "pt_version": torch.__version__, + "pt_version": str(torch.__version__), "model": model_dict, "model_def_script": model_def_script, "@variables": {},