Add opt-in hook to exempt fields from the fp-dtype downcast#127
Open
EricZQu wants to merge 2 commits into
Open
Add opt-in hook to exempt fields from the fp-dtype downcast#127EricZQu wants to merge 2 commits into
EricZQu wants to merge 2 commits into
Conversation
AtomicData.check_fp_dtype_consistency casts every floating-point tensor to
positions.dtype (typically float32) so the model computes in one precision.
That is the right default for compute inputs, but it also downcasts label
fields: e.g. total energy is extensive (~1e4-1e5 eV for large systems), so
float32 quantizes it to ~1e-2 eV and reconstructed energies come out
discrete/staircased downstream.
Add a _precision_preserving_keys ClassVar and skip those fields in the cast.
It is empty by default, so behavior is unchanged; a subclass can opt a
high-precision label out of the downcast, e.g.
class MyData(AtomicData):
_precision_preserving_keys = frozenset({"energy"})
The exemption holds across add_system_property / add_node_property, since
validate_assignment=True re-runs the validator on every setattr.
Signed-off-by: Eric Qu <ericq@nvidia.com>
Contributor
Greptile SummaryThis PR adds an opt-in
Important Files Changed
Reviews (1): Last reviewed commit: "Merge branch 'main' into allow-fp64-ener..." | Re-trigger Greptile |
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.
ALCHEMI Toolkit Pull Request
Description
Add opt-in hook to exempt fields from the fp-dtype downcast.
Type of Change
Related Issues
Changes Made
AtomicData.check_fp_dtype_consistency casts every floating-point tensor to positions.dtype (typically float32) so the model computes in one precision. That is the right default for compute inputs, but it also downcasts label fields: e.g. total energy is extensive (~1e4-1e5 eV for large systems), so float32 quantizes it to ~1e-2 eV and reconstructed energies come out discrete/staircased downstream.
Add a _precision_preserving_keys ClassVar and skip those fields in the cast. It is empty by default, so behavior is unchanged; a subclass can opt a high-precision label out of the downcast, e.g.
The exemption holds across add_system_property / add_node_property, since validate_assignment=True re-runs the validator on every setattr.
Testing
make pytest)make lint)Checklist
Additional Notes
Tip
This repository uses Greptile, an AI code review service, to help conduct
pull request reviews. We encourage contributors to read and consider suggestions
made by Greptile, but note that human maintainers will provide the necessary
reviews for merging: Greptile's comments are not a qualitative judgement
of your code, nor is it an indication that the PR will be accepted/rejected.
We encourage the use of emoji reactions to Greptile comments, depending on
their usefulness and accuracy.