Comments (13)
Hmm interesting. The MEGNet implementation doesn't suffer from this problem. So it must be in the threebody computations. @kenko911 pls fix this asap.
from matgl.
I debugged a little. I can confirm that in the forward method, the node_feat and edge_feat are consistent. But the
node_vec = self.readout(g)
vec = torch.hstack([node_vec, state_feat]) if self.inc...```
are stochastic. So there must be some issue with the readout layer. MEGNet does not use the same readout.
from matgl.
@BowenD-UCB Thanks a lot for reporting the issue and I will figure out the problem and fix it ASAP.
from matgl.
It seems that M3GNet UP is not having this issue.
from matgl.
Because the UP is not intensive and so does not call the readout.
from matgl.
I have confirmed that the stochasticity resulted from the Set2Set in dgl.nn. For instance, I replaced the set2set call in Set2SetReadout by the following code:
for i in range(3):
set2set = Set2Set(in_feats, n_iters=self.num_steps, n_layers=self.num_layers)
print(g.ndata["node_feat"])
out_tensor = set2set(g, g.ndata["node_feat"])
print(f"out={out_tensor}")
The out tensor is different all three times, despite there being no change in initialization and the input.
from matgl.
I just pushed a fix. The trick is to init the Set2Set only once. Every time it is init, it introduces stochasticity.
from matgl.
However, it should be noted that multiple loads of the model will still lead to stochasticity. I am not sure how to solve that. I am reopening this issue for now.
from matgl.
@kenko911 I think you need to look into whether there is some random seed somewhere that needs to be fixed for dgl.nn for the Set2Set initialization. It is rather strange it is not deterministic.
from matgl.
Scratch what I wrote previously. The dgl.seed does not do anything. Right now, the stochasticity with single model loading is solved. But the stochasticity with multiple model loadings is not.
from pymatgen.core import Lattice, Structure
import matgl
import torch
torch.manual_seed(0)
import random
random.seed(0)
import dgl
dgl.seed(0)
# This is the structure obtained from the Materials Project.
struct = Structure.from_spacegroup("Pm-3m", Lattice.cubic(4.1437), ["Cs", "Cl"], [[0, 0, 0], [0.5, 0.5, 0.5]])
for i in range(10):
model = matgl.load_model("M3GNet-MP-2018.6.1-Eform")
eform = model.predict_structure(struct)
print(f"The predicted formation energy for CsCl is {float(eform.numpy()):.3f} eV/atom.")
still gives stochastic results. Note, the difference between @BowenD-UCB 's code and this one is just the model loading is now in the for loop, so a load is carried out each time. If the load is outside of the for loop, results are now deterministic within that session.
from matgl.
See this is a known issue with LSTM: pytorch/pytorch#35661
from matgl.
Note that it seems that if you fix the torch.manual_seed, all stochasticity is gone.
This is the fix that I pushed. I am still not sure why this non-deterministic behavior occurs in m3gnet but not MEGNet. MEGnet seems to work fine without any manual seed set. It may be due to the number of layers in the set2set? M3Gnet uses 3 layers while MEGnet uses just 1.
from matgl.
@BowenD-UCB Just a note that Kenko pushed a final fix this morning. A new version has been released. The main issue was that the final layer was not in the init and so the weights were not saved. The new code fixes this problem. The only model that was affected was the M3GNet formation energy model. I also added an integration test to make sure it does not recur in future.
from matgl.
Related Issues (20)
- Converting graph information from dgl.Graph back into Structure HOT 9
- Supporting TorchScript? HOT 2
- M3GNet Training Tutorial Not Working HOT 4
- Setting datatypes consistently HOT 10
- Error when trying trainer.test HOT 2
- [Feature Request]: allow distinguishing atoms of the same symbol HOT 2
- [Bug]: Error in forward pass to compute stress HOT 4
- [Bug]: Error in prediction using finetuning model HOT 4
- [Feature Request]: Request for M3GNet Training Example for Property Prediction HOT 4
- [Feature Request]: multi-fidelity code or explanation for the extended QM7b data set HOT 1
- How to make a multi-target regression with m3gnet model? HOT 4
- [Bug]: Release workflow broken HOT 2
- [Bug]: Urgent! ValueError: Bad serialized model or bad model name HOT 2
- [Bug]: Multi-GPU Training not Working in 0.7.1 and 0.8.5 HOT 3
- Periodic Boundaries not recognized during molecular dynamics simulation HOT 2
- Issues with training M3GNet potential on GPUs. HOT 2
- [Feature Request]: Relaxation under pressure HOT 1
- [Bug]: Data type for ASE potential energy result is not a float
- matgl - now available on conda-forge HOT 1
- [Bug]: Retrained M3Gnet potential cannot be used HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from matgl.