Repository navigation
settings.dtype and MACE-style calculator default_dtype - #45
Merged
Merged
Conversation
Add a top-level `precision` key (fp32 / fp16 / bf16). fp16 and bf16 use Keras mixed precision so variables stay float32. fp16 uses a static loss scale of 128.
Keep precision as a child of numeric so later numerical knobs (loss scale, TF32) have a place without sitting on network or optimizer.
YAML only configures training: settings.train_dtype is float32 or float64 (default float32) for all float weights and ops. The ASE calculator takes default_dtype as a constructor argument, not a YAML key. If it differs from training, checkpoint weights are cast once at load (like model.float()/double()) and the network runs in that dtype. ASE MD remains float64.
zzy2014
reviewed
Aug 25, 2026
| Train a PiNN model given a parameter file. | ||
|
|
||
| The parameter YAML may include `settings.train_dtype` (`float32` or | ||
| `float64`; default `float32`). That key is training-only: it sets Keras |
Contributor
There was a problem hiding this comment.
Why the key is training-only? In my view, it is controlling all the precision of PiNN on both training/validation and prediction stages.
Contributor
Author
There was a problem hiding this comment.
Training here means training stage, opposite to inference/MD stage. You cant control how to use the model in the input yaml file
Roy-Kid
commented
Aug 25, 2026
| The parameter YAML may include `settings.train_dtype` (`float32` or | ||
| `float64`; default `float32`). That key is training-only: it sets Keras | ||
| `floatx` / dtype policy, so new network weights, Keras ops, and numpy/ANI | ||
| float inputs use that width. Integer indices stay `int32`. TFRecords keep |
Contributor
Author
There was a problem hiding this comment.
no! int32 means we set dtype of index(ind_1, ind_2) as int32, unchanged.
Roy-Kid
commented
Aug 25, 2026
| `settings` is training-time configuration. The only dtype key in the YAML is | ||
| `train_dtype` (`float32` or `float64`; default `float32`). It is **not** the | ||
| ASE calculator's `default_dtype` (that argument exists only on | ||
| `PiNN_calc` / `get_calc`, see [Potential](potential.md#ase-calculator)). |
Contributor
Author
There was a problem hiding this comment.
YAML already describes training, so use settings.dtype with TF names only (float32/float64). Drop fp aliases and canonical helpers; default to float32 unless settings overrides. Slim docs; calculator default_dtype None follows settings.dtype.
tf.as_dtype raises TypeError for names it does not know (e.g. fp64); wrap that so settings.dtype typos stay a consistent ValueError.
Roy-Kid
force-pushed
the
feat/train-precision
branch
from
August 26, 2026 08:24
ac6948b to
dae3423
Compare
_CastSaver.restore ran var.assign(ndarray), which adds a const + assign op pair to the graph. The Estimator finalizes the graph before the scaffold's saver restores, so serving a float32 checkpoint at float64 (or the reverse) through PiNN_calc always raised "Graph is finalized and cannot be modified". var.load() feeds the value into the variable's existing initializer instead, creating no ops. Add a regression test that trains a tiny float32 model and predicts through PiNN_calc at both dtypes -- the previous test only covered the dtype plumbing, never a cross-dtype restore. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
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.
Summary
settings.dtypeisfloat32orfloat64(defaultfloat32). Float weights and Keras ops use that dtype.default_dtypeis a constructor argument only (not YAML), same idea as MACE.Nonefollowssettings.dtype.default_dtypeand the checkpoint is cast once at load (tf.castinto the new variables — TF equivalent ofmodel.float()/model.double()). After that the whole network runs in that dtype.default_dtype.Test plan
tests/test_precision.py: name parsing, YAMLdtype, calculator override, float32 default, float64 short train