Reduce CUDA memory use in non-local SKALA layers - #101
Conversation
|
@microsoft-github-policy-service agree |
|
cool, thanks for the PR. We will have a look |
|
thanks Dynamics of Condensed Matter (@DCM-Uni-Paderborn) for the PR. There are two changes in this PR:
|
93cac4a to
6169778
Compare
|
Thanks, we agree with both points. We have removed the two dtype changes and retained the explicit double-precision grid reductions and geometry calculations. The updated PR now contains only the split linear projection. We repeated the split-only comparison using identical weights and the unchanged FP64 reduction path. On two A40 GPUs, three-run medians show peak memory decreasing from We also strengthened the CUDA test to compare both the forward result and all five relevant input gradients against the original concatenation path. A six-step, 96-atom CP2K SCF trajectory differed by at most Atom chunking is already used independently by the CP2K native SKALA path, so the split projection reduces the remaining allocation within each atom subchunk. Gradient checkpointing is worth investigating separately because it trades activation memory for recomputation during every VXC backward evaluation. |
6169778 to
f6a021a
Compare
|
Rebased onto the current |
Summary
Motivation
CUDA profiles of native-grid SKALA in CP2K show that the skip-connection concatenation creates a large short-lived fine-grid allocation and an associated copy kernel.
The split projection is mathematically equivalent to the existing concatenated linear layer:
W [features, update] + b = W_features features + b + W_update updateIt reuses the existing weights and does not change checkpoint compatibility. This is primarily a memory optimization; the runtime effect is workload dependent.
Validation
pytest -q tests/test_model.py: 14 passed on an NVIDIA GB10ruff check src/skala/functional/model.py tests/test_model.pyruff format --check src/skala/functional/model.py tests/test_model.pyA six-step, 96-atom CP2K SCF trajectory on the GB10 differed from the unchanged reference by at most
5.13e-8 Hain energy and1e-8in the convergence measure.For the isolated split-projection comparison on two NVIDIA A40 GPUs, using three-run medians with identical weights and the unchanged double-precision reduction path:
10253/8945 MiBto9093/7883 MiB, or about11-12%per GPU26.943 sto25.792 sand wall time from30.174 sto29.001 s3.34e-8 HaAn earlier isolated comparison showed only a
0.7%runtime difference, so no general speedup is claimed.Model artifact
The source change takes effect after scripting/tracing a new CUDA
.funartifact. Existing published artifacts are not modified by this PR. A new CUDA model revision can be uploaded and added to the version mapping after this code is accepted; the CPU artifact can remain unchanged.Related to cp2k/cp2k#5439.