Upload folder using huggingface_hub
Browse files
equiformer_ase_calculator.py
CHANGED
|
@@ -42,7 +42,7 @@ class EquiformerASECalculator(Calculator):
|
|
| 42 |
|
| 43 |
def __init__(
|
| 44 |
self,
|
| 45 |
-
checkpoint_path: str,
|
| 46 |
device: Optional[torch.device] = None,
|
| 47 |
project_root: str = None,
|
| 48 |
**kwargs,
|
|
@@ -69,6 +69,9 @@ class EquiformerASECalculator(Calculator):
|
|
| 69 |
config = yaml.safe_load(file)
|
| 70 |
model_config = config["model"]
|
| 71 |
self.model = EquiformerV2_OC20(**model_config)
|
|
|
|
|
|
|
|
|
|
| 72 |
state_dict = torch.load(checkpoint_path, weights_only=True)["state_dict"]
|
| 73 |
state_dict = {k.replace("potential.", ""): v for k, v in state_dict.items()}
|
| 74 |
self.model.load_state_dict(state_dict, strict=False)
|
|
|
|
| 42 |
|
| 43 |
def __init__(
|
| 44 |
self,
|
| 45 |
+
checkpoint_path: Optional[str] = None,
|
| 46 |
device: Optional[torch.device] = None,
|
| 47 |
project_root: str = None,
|
| 48 |
**kwargs,
|
|
|
|
| 69 |
config = yaml.safe_load(file)
|
| 70 |
model_config = config["model"]
|
| 71 |
self.model = EquiformerV2_OC20(**model_config)
|
| 72 |
+
|
| 73 |
+
if checkpoint_path is None:
|
| 74 |
+
checkpoint_path = os.path.join(project_root, "ckpt/eqv2.ckpt")
|
| 75 |
state_dict = torch.load(checkpoint_path, weights_only=True)["state_dict"]
|
| 76 |
state_dict = {k.replace("potential.", ""): v for k, v in state_dict.items()}
|
| 77 |
self.model.load_state_dict(state_dict, strict=False)
|
ocpmodels/checkpointing.py
CHANGED
|
@@ -2,12 +2,13 @@ import torch
|
|
| 2 |
import itertools
|
| 3 |
import warnings
|
| 4 |
from collections import OrderedDict
|
| 5 |
-
from typing import Any, List, Mapping, namedtuple
|
| 6 |
|
| 7 |
# from torch/nn/modules/module.py
|
| 8 |
|
| 9 |
_EXTRA_STATE_KEY_SUFFIX = "_extra_state"
|
| 10 |
|
|
|
|
| 11 |
class _IncompatibleKeys(
|
| 12 |
namedtuple("IncompatibleKeys", ["missing_keys", "unexpected_keys"]),
|
| 13 |
):
|
|
@@ -18,6 +19,7 @@ class _IncompatibleKeys(
|
|
| 18 |
|
| 19 |
__str__ = __repr__
|
| 20 |
|
|
|
|
| 21 |
def _load_from_state_dict(
|
| 22 |
self,
|
| 23 |
state_dict,
|
|
@@ -199,8 +201,10 @@ def _load_from_state_dict(
|
|
| 199 |
elif input_name[0] not in local_state:
|
| 200 |
unexpected_keys.append(key)
|
| 201 |
|
|
|
|
| 202 |
def load_state_dict(
|
| 203 |
-
self,
|
|
|
|
| 204 |
assign: bool = False,
|
| 205 |
strict_unexpected_keys: bool = False,
|
| 206 |
strict_missing_keys: bool = False,
|
|
@@ -242,9 +246,7 @@ def load_state_dict(
|
|
| 242 |
``RuntimeError``.
|
| 243 |
"""
|
| 244 |
if not isinstance(state_dict, Mapping):
|
| 245 |
-
raise TypeError(
|
| 246 |
-
f"Expected state_dict to be dict-like, got {type(state_dict)}."
|
| 247 |
-
)
|
| 248 |
|
| 249 |
missing_keys: List[str] = []
|
| 250 |
unexpected_keys: List[str] = []
|
|
@@ -307,7 +309,7 @@ def load_state_dict(
|
|
| 307 |
", ".join(f'"{k}"' for k in unexpected_keys[:20])
|
| 308 |
),
|
| 309 |
)
|
| 310 |
-
|
| 311 |
if strict_missing_keys:
|
| 312 |
if len(missing_keys) > 0:
|
| 313 |
error_msgs.insert(
|
|
@@ -323,4 +325,4 @@ def load_state_dict(
|
|
| 323 |
self.__class__.__name__, "\n\t".join(error_msgs)
|
| 324 |
)
|
| 325 |
)
|
| 326 |
-
return _IncompatibleKeys(missing_keys, unexpected_keys)
|
|
|
|
| 2 |
import itertools
|
| 3 |
import warnings
|
| 4 |
from collections import OrderedDict
|
| 5 |
+
from typing import Any, List, Mapping, namedtuple
|
| 6 |
|
| 7 |
# from torch/nn/modules/module.py
|
| 8 |
|
| 9 |
_EXTRA_STATE_KEY_SUFFIX = "_extra_state"
|
| 10 |
|
| 11 |
+
|
| 12 |
class _IncompatibleKeys(
|
| 13 |
namedtuple("IncompatibleKeys", ["missing_keys", "unexpected_keys"]),
|
| 14 |
):
|
|
|
|
| 19 |
|
| 20 |
__str__ = __repr__
|
| 21 |
|
| 22 |
+
|
| 23 |
def _load_from_state_dict(
|
| 24 |
self,
|
| 25 |
state_dict,
|
|
|
|
| 201 |
elif input_name[0] not in local_state:
|
| 202 |
unexpected_keys.append(key)
|
| 203 |
|
| 204 |
+
|
| 205 |
def load_state_dict(
|
| 206 |
+
self,
|
| 207 |
+
state_dict: Mapping[str, Any],
|
| 208 |
assign: bool = False,
|
| 209 |
strict_unexpected_keys: bool = False,
|
| 210 |
strict_missing_keys: bool = False,
|
|
|
|
| 246 |
``RuntimeError``.
|
| 247 |
"""
|
| 248 |
if not isinstance(state_dict, Mapping):
|
| 249 |
+
raise TypeError(f"Expected state_dict to be dict-like, got {type(state_dict)}.")
|
|
|
|
|
|
|
| 250 |
|
| 251 |
missing_keys: List[str] = []
|
| 252 |
unexpected_keys: List[str] = []
|
|
|
|
| 309 |
", ".join(f'"{k}"' for k in unexpected_keys[:20])
|
| 310 |
),
|
| 311 |
)
|
| 312 |
+
|
| 313 |
if strict_missing_keys:
|
| 314 |
if len(missing_keys) > 0:
|
| 315 |
error_msgs.insert(
|
|
|
|
| 325 |
self.__class__.__name__, "\n\t".join(error_msgs)
|
| 326 |
)
|
| 327 |
)
|
| 328 |
+
return _IncompatibleKeys(missing_keys, unexpected_keys)
|