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

Error when using IS2RE models #919

Open
lanchoxie opened this issue Nov 18, 2024 · 2 comments
Open

Error when using IS2RE models #919

lanchoxie opened this issue Nov 18, 2024 · 2 comments
Labels

Comments

@lanchoxie
Copy link

Hi, I was using painn_h1024_bs4x8_is2re_all.pt to execute the initial structure to relaxed energy prediction, and I got the following errors: (which did not appear in S2EF models)

from fairchem.core.common.relaxation.ase_utils import OCPCalculator
from ase.io import read
from ase.io import write
import matplotlib.pyplot as plt
from ase.visualize.plot import plot_atoms
from io import StringIO
import contextlib
import os
import numpy as np
import sys

local_model_dir='/home/bingxing2/home/scx8jte/ai4s/fairchem_benchmark/examples/fairchem_checkpoints/'
model='painn_h1024_bs4x8_is2re_all.pt'
id='90614'

system = read(f'vasp_files/combine-{id}.vasp')  

write('initial_structure.vasp', system)
system.set_tags(np.ones(len(system)))  #only when use gemnet

checkpoint_path = os.path.join(local_model_dir,model)  
with contextlib.redirect_stdout(StringIO()) as _:
    calc = OCPCalculator(checkpoint_path=checkpoint_path, cpu=False)
system.set_calculator(calc)
E_slab_adsorbate = system.get_potential_energy()
print(E_slab_adsorbate)

Here is my Error

INFO:root:Loading model: painn
/home/bingxing2/home/scx8jte/.conda/envs/fair-chem/lib/python3.9/site-packages/torch_geometric/nn/conv/message_passing.py:988: UserWarning: 'PaiNNMessage.jittable' is deprecated and a no-op. Please remove its usage.
warnings.warn(f"'{self.class.name}.jittable' is deprecated "
INFO:root:Loaded PaiNN with 72255495 parameters.
INFO:root:Loading checkpoint in inference-only mode, not loading keys associated with trainer state!
INFO:root:Overwriting scaling factors with those loaded from checkpoint. If you're generating predictions with a pretrained checkpoint, this is the correct behavior. To disable this, delete scale_dict from the checkpoint.
/home/bingxing2/home/scx8jte/ai4s/fairchem_benchmark/fairchem/packages/fairchem-core/src/fairchem/core/modules/normalization/normalizer.py:69: UserWarning: To copy construct from a tensor, it is recommended to use sourceTensor.clone().detach() or sourceTensor.clone().detach().requires_grad_(True), rather than torch.tensor(sourceTensor).
"mean": torch.tensor(state_dict["mean"]),
WARNING:root:No seed has been set in modelcheckpoint or OCPCalculator! Results may not be reproducible on re-run
/home/bingxing2/home/scx8jte/ai4s/fairchem_benchmark/examples/combined_system_IS2RE_2.py:49: DeprecationWarning: Please use atoms.calc = calc
system.set_calculator(calc)
/home/bingxing2/home/scx8jte/ai4s/fairchem_benchmark/fairchem/packages/fairchem-core/src/fairchem/core/trainers/ocp_trainer.py:461: FutureWarning: torch.cuda.amp.autocast(args...) is deprecated. Please use torch.amp.autocast('cuda', args...) instead.
with torch.cuda.amp.autocast(enabled=self.scaler is not None):
Traceback (most recent call last):
File "/home/bingxing2/home/scx8jte/ai4s/fairchem_benchmark/examples/combined_system_IS2RE_2.py", line 51, in
E_slab_adsorbate = system.get_potential_energy()
File "/home/bingxing2/home/scx8jte/.conda/envs/fair-chem/lib/python3.9/site-packages/ase/atoms.py", line 755, in get_potential_energy
energy = self._calc.get_potential_energy(self)
File "/home/bingxing2/home/scx8jte/.conda/envs/fair-chem/lib/python3.9/site-packages/ase/calculators/abc.py", line 24, in get_potential_energy
return self.get_property(name, atoms)
File "/home/bingxing2/home/scx8jte/.conda/envs/fair-chem/lib/python3.9/site-packages/ase/calculators/calculator.py", line 538, in get_property
self.calculate(atoms, [name], system_changes)
File "/home/bingxing2/home/scx8jte/ai4s/fairchem_benchmark/fairchem/packages/fairchem-core/src/fairchem/core/common/relaxation/ase_utils.py", line 233, in calculate
predictions = self.trainer.predict(batch, per_image=False, disable_tqdm=True)
File "/home/bingxing2/home/scx8jte/.conda/envs/fair-chem/lib/python3.9/site-packages/torch/utils/_contextlib.py", line 116, in decorate_context
return func(*args, **kwargs)
File "/home/bingxing2/home/scx8jte/ai4s/fairchem_benchmark/fairchem/packages/fairchem-core/src/fairchem/core/trainers/ocp_trainer.py", line 462, in predict
out = self._forward(batch)
File "/home/bingxing2/home/scx8jte/ai4s/fairchem_benchmark/fairchem/packages/fairchem-core/src/fairchem/core/trainers/ocp_trainer.py", line 293, in _forward
raise AttributeError(
AttributeError: Output target: 'forces', not found in model outputs: ['energy']

@misko
Copy link
Collaborator

misko commented Nov 19, 2024

Hi!
Thank you for this, you are totally right, this is an issue! I have created a fix here , #922 , and will hopefully have this merged soon.

In the meantime if this is blocking you please try to use the branch, add_calculator_only_output_field

Copy link

This issue has been marked as stale because it has been open for 30 days with no activity.

@github-actions github-actions bot added the stale label Dec 20, 2024
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