Repository navigation
Honor calculator dtype in GraphConverter.convert - #174
Open
shaneraphel wants to merge 1 commit into
Open
shaneraphel wants to merge 1 commit into
shaneraphel wants to merge 1 commit into
Conversation
The leftover path builds atom_pos, cell, pbc_offsets and labels with torch.FloatTensor, which is float32 even when MatterSimCalculator is constructed with dtype="float64". The later upcast cannot recover the rounded coordinates, so a rigid translation at large cell coordinates changes energy and forces. Thread the requested dtype through convert and pass it on the leftover build_dataloader path. The direct-graph sibling already constructed positions at self.dtype.
Author
|
@microsoft-github-policy-service agree |
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
GraphConverter.convertis the current graph I/O used byMatterSimCalculator.calculatewhendirect_graphis off. It builtatom_pos,cell,pbc_offsets, and the optional energy/force/stress labels withtorch.FloatTensor, which is float32 regardless of the calculator's requesteddtype.calculate()later upcasts floating tensors whendtypeis float64. That upcast cannot recover digits already rounded away. A rigid translation of a water molecule by 1000 Å in a 4000 Å cell therefore changes the stored coordinates at the 1e-5 Å scale, and the issue's energy/force comparison is the physical consequence of that rounding.The direct-graph sibling (
_build_graph_direct) already constructs positions and cell withdtype=self.dtype. This change puts the current converter on the same contract:convertreadskwargs["dtype"](default still float32) for every floating tensor it builds, andcalculate()passesdtype=self.dtypeintobuild_dataloader, which already forwards**kwargsintoconvert.Default float32 inference is unchanged.
BatchGraphConverteris a separate construction path and is not rewritten here.Paired observations on the issue's H2O geometry (no checkpoint):
FloatTensormax |Δ| vs ASE float64 positions: 1.2681640612299816e-05 Åtensor(..., dtype=float64)max |Δ|: 0FloatTensorReproducer from the issue still applies after this change: construct
MatterSimCalculator(..., dtype="float64"), compare energy and forces of a structure and its rigid translate. The two should now agree at float64 scale on the current dataloader path.