Batch D3 and SevenNetD3Model for Torch-Sim interface#300
Open
alphalm4 wants to merge 17 commits into
Open
Conversation
Contributor
Author
|
Something like this might force Torch-Sim to run in float64 while preserving SevenNet works in float32. |
Member
|
I dont know the context but why dont we just cast 7net model to float64? For speed? |
Contributor
Author
|
7net model을 64로 올리지않는건 speed 때문이 맞습니다. (굳..이?) 맥락을 추가하자면 해당 항목은 TorchSim state precision이 model precision을 따라가기 때문입니다. SevenNet은 float32 만 받기 때문에 현재 기준으로는 강제로 MD도 float32로 돌려야 합니다. 아주 정밀하게 확인한 건 아니지만, float64 wrapper 구현 후 ensemble invariant (e.g. npt_nose_hoover_invariant) fluctuation을 확인했을 때 float32보다 줄어드는 것으로 보입니다 (즉 계산 오차 감소가 눈에 보입니다). 반드시 그것뿐만이 아니라도, MD precision을 선택할 방법은 있어야 할 것 같습니다. |
YutackPark
previously approved these changes
Jun 9, 2026
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.
Batch D3 is implemented.
How it works
(heuristic, but I found some evidences that current batch D3 is also faster than serial D3 when the system size is smaller than 1k. Also, in very large cell, it slows down than serial D3. So I think better criterion for choosing serial/batch should consider the system size, but ...)
Precision
Batch D3's precision policy is FP32+64 (same with serial D3) but it utilizes Kahan summation inside each thread. It greatly diminishes precision-related rounding error in pairwise dispersion energy, approaching the reference FP64 fortran-dftd3 values within (|ΔE,F| < 1e-7, |ΔS| < 3e-7 in ase units)
The above difference in summation makes the output energy of batch D3 kernel slightly different with serial D3.
Applying Kahan summation also in serial D3 can nearly remove this discrepancy between serial/batch (|ΔE,F,S| < 1e-7 in ase units), but I think this should be addressed in a separate conversation. (since it breaks backward compatibility of calculation results)
code review @dambi3613
Float64 wrapper for double-precision MD computation flow
speed benchmark (especially, check
nvalchemiops_dftd3) -> done, found custom batch D3 implementation is still valuabletest scripts
replace SevenNetD3Model with batched D3 version then remove
torchsim_d3.pyoverflow issues (only applied for batched D3, not serial D3)
Doc