-
Notifications
You must be signed in to change notification settings - Fork 599
Fix: Square atom_norm in non-Huber energy and virial loss calculations. #5332
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -346,7 +346,7 @@ def build( | |
| more_loss = {} | ||
| if self.has_e: | ||
| if not self.use_huber: | ||
| loss += atom_norm_ener * (pref_e * l2_ener_loss) | ||
| loss += atom_norm_ener**2 * (pref_e * l2_ener_loss) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Finish the TensorFlow normalization fix in the remaining loss variants.
Minimal follow-up diff- if self.has_e:
- l2_loss += atom_norm_ener * (pref_e * l2_ener_loss)
+ if self.has_e:
+ l2_loss += atom_norm_ener**2 * (pref_e * l2_ener_loss)
@@
- if self.has_v:
- l2_loss += global_cvt_2_ener_float(atom_norm * (pref_v * l2_virial_loss))
+ if self.has_v:
+ l2_loss += global_cvt_2_ener_float(atom_norm**2 * (pref_v * l2_virial_loss))
@@
- l2_loss += atom_norm_ener * (pref_e * l2_ener_loss)
+ l2_loss += atom_norm_ener**2 * (pref_e * l2_ener_loss)Also applies to: 373-375 🤖 Prompt for AI Agents |
||
| else: | ||
| l_huber_loss = custom_huber_loss( | ||
| atom_norm_ener * energy, | ||
|
|
@@ -370,7 +370,9 @@ def build( | |
| ) | ||
| if self.has_v: | ||
| if not self.use_huber: | ||
| loss += global_cvt_2_ener_float(atom_norm * (pref_v * l2_virial_loss)) | ||
| loss += global_cvt_2_ener_float( | ||
| atom_norm**2 * (pref_v * l2_virial_loss) | ||
| ) | ||
|
Comment on lines
348
to
+375
|
||
| else: | ||
| l_huber_loss = custom_huber_loss( | ||
| atom_norm * tf.reshape(virial, [-1]), | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are tests comparing losses across backends, but they don’t assert the intended natoms-scaling explicitly. Since this change fixes a subtle normalization bug (MSE energy/virial terms should scale with 1/natoms^2), consider adding a small regression test that checks the loss contribution scales correctly when natoms changes, so future refactors can’t accidentally revert to 1/natoms.