Per-element (per-atom) force loss weighting - #1542
Open
mikyneb wants to merge 1 commit into
Open
Conversation
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.
Closes #1539.
Adds opt-in per-atom force loss weighting via a new xyz arrays column, REF_forces_atomic_weights (one scalar per atom). Per-element weighting is achieved by expanding an element→weight map into this column during preprocessing. Defaults to uniform, so existing training runs are unchanged.
Changes
As noted in the issue thread, loading already supports arbitrary per-atom arrays — the work is loss-side plus registering the key.
default_keys.py / arg_parser.py / data/utils.py: registerforces_atomic_weightsas an arrays key, add--forces_atomic_weights_keyto the train and preprocess parsers.data/atomic_data.py:forces_atomic_weightsas a first-class node field, shape(n_atoms, 1), defaulting to ones infrom_config(keeps batches homogeneous when only some configs carry the column, and keeps the feature strictly opt-in).modules/loss.py: a getattr-based helper multiplies the weights into every force path —mean_squared_error_forces,mean_normed_error_forces,conditional_mse_forces,conditional_huber_forces(via a new optional arg), and both branches ofWeightedHuberEnergyForcesStressLoss. Covers the weighted, forces_only, stress, huber, universal, and l1l2energyforces losses.Out of Scope
filter_nonzero_weightstill masks by config, not atom).(n, 3)weights — scalar-per-atom is the clean v1;mean_normed_error_forcescan't use per-component weights anyway.Usage
Tests
New
tests/test_forces_atomic_weights.py(uniform-weights-match-default, linear scaling, zero-weight masking, per-element ratio, mixed/legacy batches, xyz round-trip, DDP-reduction consistency). Existingtest_modules,test_data,test_run_trainpass.