Skip to content

Commit a3054f2

Browse files
author
Han Wang
committed
fix
1 parent 6b4748d commit a3054f2

1 file changed

Lines changed: 8 additions & 1 deletion

File tree

deepmd/pt_expt/common.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,14 @@ def _auto_wrap_native_op(value: NativeOP) -> torch.nn.Module:
160160
{"forward": lambda self, *args, **kwargs: self.call(*args, **kwargs)},
161161
)
162162
_AUTO_WRAPPED_CLASSES[cls] = torch_module(wrapped)
163-
return _AUTO_WRAPPED_CLASSES[cls].deserialize(value.serialize())
163+
wrapped_cls = _AUTO_WRAPPED_CLASSES[cls]
164+
if not (hasattr(value, "serialize") and hasattr(wrapped_cls, "deserialize")):
165+
raise TypeError(
166+
f"Cannot auto-wrap {cls.__name__}: "
167+
"it must implement serialize()/deserialize() or be explicitly "
168+
"registered via register_dpmodel_mapping()."
169+
)
170+
return wrapped_cls.deserialize(value.serialize())
164171

165172

166173
def _try_convert_list(name: str, value: list) -> torch.nn.Module | None:

0 commit comments

Comments
 (0)