Skip to content

Commit e1e3ccc

Browse files
committed
perf(pt/dpa4): add toy CuTe realization
1 parent 5000a7d commit e1e3ccc

7 files changed

Lines changed: 1705 additions & 1104 deletions

File tree

Lines changed: 36 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,54 @@
11
# SPDX-License-Identifier: LGPL-3.0-or-later
22
"""
3-
CuTe-DSL accelerated SO(2) rotation operators for SeZM / DPA4.
3+
CuTe-DSL fused SO(2) value-path operator for SeZM / DPA4.
44
5-
This package provides a self-contained, ``torch.compile``-friendly implementation
6-
of the two fused gather + batched-GEMM operators used by the SeZM SO(2) edge
7-
convolution:
5+
This package hosts a single bucketed CuTe operator that folds the entire per-edge
6+
value path of :class:`~deepmd.pt.model.descriptor.sezm_nn.so2.SO2Convolution`
7+
(``rotate_to_local`` -> radial degree mix -> the three-layer gated SO(2) mixing
8+
stack -> focus competition) into a fused forward kernel and a matching
9+
recompute backward kernel, keeping the per-edge intermediates on chip. It is an
10+
opt-in inference path enabled by ``DP_CUTE_INFER``; the final local features are
11+
handed to the committed flash-attention aggregation for rotate-back and scatter.
12+
Kernel entry points are internal implementation details of the SeZM descriptor;
13+
the package-level API only exposes availability and the value-path factory.
814
9-
* ``rotate_to_local`` : ``out[e] = wigner[e][coeff_index] @ x[src[e]]``
10-
* ``rotate_back`` : ``out[e] = wigner[e][:, coeff_index] @ x_local[e]``
15+
Current limitations
16+
-------------------
17+
Performance
18+
On H20 / fp32 the operator is about 2.8x slower than the compiled Triton +
19+
flash-attention path (roughly 489 / 724 ms versus 174 / 262 ms per force step
20+
at 2000 / 4000 atoms). Peak memory is at parity with, or marginally below,
21+
the compiled path (about 0.5 / 0.8 GB lower) and roughly 1.68x below the
22+
eager path. The bottleneck is the recompute backward, which dominates the
23+
kernel time: its occupancy is capped by the block-diagonal weight held
24+
resident in shared memory, and both the forward and backward GEMMs run at the
25+
hand-written plateau of about 21% of fp32 peak (versus about 52% for cuBLAS).
1126
12-
The kernels are written with the NVIDIA CuTe DSL (``cutlass.cute``) and fuse the
13-
Wigner-row/column gather and the source-node gather directly into the matmul, so
14-
the large ``D_to_m`` / ``x_src`` intermediates are never materialized. They are
15-
exposed through the modern ``torch.library.custom_op`` API (functional, with
16-
``register_fake`` + ``register_autograd``) so that they compose correctly with
17-
``torch.compile`` and autograd.
27+
Deployment
28+
This is a Python-inference-only path. The ``cutlass.cute`` kernels are
29+
nvcc / NVRTC JIT-compiled at runtime and do not bake into the AOTInductor
30+
``.pt2`` artifact, so the operator is unavailable to the LAMMPS / GPUMD C++
31+
inference path. ``DP_CUTE_INFER`` is an independent path from
32+
``DP_TRITON_INFER``; it engages regardless of the Triton flag and reuses the
33+
committed flash-attention aggregation kernel when it is active.
1834
19-
The top-level entry points are re-exported here for convenience.
35+
Correctness
36+
The force is bit-exact against the eager reference (energy relative error
37+
about 1e-9, force relative error about 5e-7 in fp32).
2038
"""
2139

2240
from __future__ import (
2341
annotations,
2442
)
2543

26-
from .so2_rotation import (
44+
from .forward import (
2745
SEZM_CUTE_AVAILABLE,
28-
rotate_back_cute,
29-
rotate_to_local_cute,
46+
)
47+
from .operator import (
48+
make_cute_value_path,
3049
)
3150

3251
__all__ = [
3352
"SEZM_CUTE_AVAILABLE",
34-
"rotate_back_cute",
35-
"rotate_to_local_cute",
53+
"make_cute_value_path",
3654
]

0 commit comments

Comments
 (0)