ACEsuit / mace

MACE - Fast and accurate machine learning interatomic potentials with higher order equivariant message passing.
Other
547 stars 203 forks source link

How to transfer the mace pre-trained model from dtype_float64 to dtype_float32 while running lammps #603

Closed junqili closed 1 month ago

junqili commented 1 month ago

I download the pre-trained model "2023-12-10-mace-128-L0_epoch-199.model", and i can transfer the model to dtype_float32 in python:

from mace.calculators import MACECalculator from mace.calculators import mace_mp macemp = mace_mp(device='cuda',default_dtype="float32", model="./2023-12-03-mace-128-L1_epoch-199.model", dispersion=False)

but how can i save this float32 model, and so that i can use mace_create_lammps to generate model from lammps?

wcwitt commented 1 month ago

Not sure I understand the question, sorry. The mace_create_lammps script should be able to handle a float32 model, although it will convert to float64 when preparing the LAMMPS model.

junqili commented 1 month ago

Not sure I understand the question, sorry. The mace_create_lammps script should be able to handle a float32 model, although it will convert to float64 when preparing the LAMMPS model.

thank you for your answear, i am sorry about the unclear question. my question is i only download the float64 model, and i want to transfer to float32 model for lammps, how can i use the "mace_create_lammps" to create float32 model for lammps?

owen-rett commented 1 month ago

I'll leave this comment with the caveat that I am not associated with MACE. I've attempted to run float32 lammps before, and got the following "recipe" working.

Firstly edit the file ${mace_install}/mace/cli/create_lammps_model.py by changing line 58 (in the current version).

model = model.double().to("cpu") to model = model.float().to("cpu")

Then run that file to compile a model with float32 precision, which will not work with the default lammps compilation specified in the mace documentation. Next you'll need to compile the mace-kokkos-sp branch of lammps (https://github.com/ACEsuit/lammps/tree/mace-kokkos-sp) to work with your system's architecture. You'll need to test the results relative to both the double precision lammps branch and the ASE calculator to see if there are any major changes: energy vs time, temperature fluctuations, density, etc.

ilyes319 commented 1 month ago

Thank you @owen-rett,

I think this is the right way to do it. I have added an option in the create_lammps_model.py to directly convert it float32 via selecting --dtype="float32". You will still need to do the special compilation.