Skip to content

Commit 8e5ec83

Browse files
committed
fix
1 parent 6373f24 commit 8e5ec83

6 files changed

Lines changed: 52 additions & 40 deletions

File tree

deepmd/kernels/cuda/dpa1/graph_compress.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,6 @@
3535
"op_available",
3636
]
3737

38-
_TILE_EDGES = 128 # matches kTileEdges in dpa1_graph_compress.cu
39-
4038
# Instantiated table widths in dpa1_graph_compress.cu; each divides the 256
4139
# threads per block, so the moment walk splits channels evenly. An arbitrary
4240
# ``ng`` is served by the smallest width that is at least ``ng``, zero-padding

deepmd/kernels/triton/dpa1/sweep_tile_configs.py

Lines changed: 24 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -73,9 +73,6 @@
7373
# the per-program register tile small, large values amortize launch overhead.
7474
_BLOCK_E_CANDIDATES = (1, 2, 4, 8, 16, 32)
7575
_WARP_CANDIDATES = (2, 4, 8)
76-
# Reject a configuration whose forward+backward is slower than this multiple of
77-
# the best observed time; a large backward regression signals a register spill.
78-
_REJECT_RATIO = 3.0
7976
_REL_TOL = 1e-5
8077
# An edge_conv candidate is only recorded when it beats the universal default by
8178
# more than ``1 - _EDGE_WIN_RATIO`` (5%); otherwise the default is kept, so a
@@ -186,16 +183,20 @@ def fwd_bwd(bn: int, nw: int) -> None:
186183

187184
def _make_edge_inputs(
188185
n_edge: int, n_node: int, ng: int, h1: int, device: torch.device
189-
) -> tuple[Tensor, Tensor, Tensor, Tensor, Tensor, Tensor]:
186+
) -> tuple[Tensor, Tensor, Tensor, Tensor, Tensor, Tensor, Tensor, Tensor, Tensor]:
187+
p = 4096
190188
z2 = torch.randn(n_edge, ng, dtype=torch.float32, device=device)
191189
h1t = torch.randn(n_edge, h1, dtype=torch.float32, device=device)
192190
idt = torch.ones(ng, dtype=torch.float32, device=device)
191+
tt = torch.randn(p, ng, dtype=torch.float32, device=device) * 0.3
192+
idx = torch.randint(0, p, (n_edge,), dtype=torch.int64, device=device)
193+
sw = torch.rand(n_edge, dtype=torch.float32, device=device)
193194
rr = torch.randn(n_edge, 4, dtype=torch.float32, device=device)
194195
dst = torch.randint(0, n_node, (n_edge,), dtype=torch.int64, device=device)
195196
edge_mask = (torch.rand(n_edge, dtype=torch.float32, device=device) > 0.05).to(
196197
dtype=torch.float32
197198
)
198-
return z2, h1t, idt, rr, dst, edge_mask
199+
return z2, h1t, idt, tt, idx, sw, rr, dst, edge_mask
199200

200201

201202
def sweep_edge(
@@ -238,22 +239,31 @@ def sweep_edge(
238239
device = device or torch.device("cuda")
239240
torch.backends.cuda.matmul.allow_tf32 = False
240241
act = 0
241-
z2, h1t, idt, rr, dst, em = _make_edge_inputs(n_edge, n_node, ng, h1, device)
242-
ref = _edge_conv_reference(z2, h1t, idt, rr, dst, em, n_node, resnet_mult, act)
242+
# The launch configuration is keyed by (ng, H1) and is independent of the
243+
# tebd-input mode; the strip gate (gated = 1) is the register-heaviest case,
244+
# so its optimum is a safe upper bound for concat (gated = 0).
245+
gated = 1
246+
# Shared leading arguments of the three edge_conv entry points, ordered to
247+
# match their signatures so each call splats this tuple and appends only its
248+
# launch configuration.
249+
edge_args = (
250+
*_make_edge_inputs(n_edge, n_node, ng, h1, device),
251+
n_node,
252+
resnet_mult,
253+
act,
254+
gated,
255+
)
256+
ref = _edge_conv_reference(*edge_args)
243257
gout = torch.randn_like(ref)
244258

245259
def fwd_bwd(be: int, nw: int) -> None:
246-
_edge_conv_fwd_impl(z2, h1t, idt, rr, dst, em, n_node, resnet_mult, act, be, nw)
247-
_edge_conv_bwd_impl(
248-
gout, z2, h1t, idt, rr, dst, em, n_node, resnet_mult, act, be, nw
249-
)
260+
_edge_conv_fwd_impl(*edge_args, be, nw)
261+
_edge_conv_bwd_impl(gout, *edge_args, be, nw)
250262

251263
results: dict[tuple[int, int], float] = {}
252264
for be, nw in itertools.product(_BLOCK_E_CANDIDATES, _WARP_CANDIDATES):
253265
try:
254-
out = _edge_conv_fwd_impl(
255-
z2, h1t, idt, rr, dst, em, n_node, resnet_mult, act, be, nw
256-
)
266+
out = _edge_conv_fwd_impl(*edge_args, be, nw)
257267
rel = (out - ref).abs().max().item() / ref.abs().max().item()
258268
if rel > _REL_TOL:
259269
continue

deepmd/kernels/triton/env_mat.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -475,7 +475,6 @@ def _env_mat_reference(
475475
use_exp_switch: bool,
476476
) -> tuple[Tensor, Tensor, Tensor]:
477477
"""Eager environment matrix, numerically identical to ``prod_env_mat``."""
478-
nf, nloc, nnei = nlist.shape
479478
mask, _, d, length_safe, _ = _geometry(coord, nlist)
480479
q = length_safe + protection
481480
sw_raw, _ = _switch_reference(length_safe, rcut_smth, rcut, use_exp_switch)

deepmd/pt/model/descriptor/se_atten.py

Lines changed: 8 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -667,15 +667,10 @@ def forward(
667667
rr,
668668
gated=0,
669669
)
670-
# ``gg`` (the pair representation g2) is not formed on this path.
671-
gg = torch.empty(
672-
nframes,
673-
nloc,
674-
self.nnei,
675-
self.filter_neuron[-1],
676-
dtype=xyz_scatter.dtype,
677-
device=xyz_scatter.device,
678-
)
670+
# ``gg`` (the pair representation g2) is not formed on this path;
671+
# it is returned as ``None``, so a zero-element placeholder keeps
672+
# ``gg`` a tensor without the full (nf, nloc, nnei, ng) allocation.
673+
gg = xyz_scatter.new_empty(0)
679674
g2_is_none = True
680675
else:
681676
# nfnl x nnei x ng
@@ -755,15 +750,10 @@ def forward(
755750
rr,
756751
gated=1,
757752
)
758-
# ``gg`` (the pair representation g2) is not formed on this path.
759-
gg = torch.empty(
760-
nframes,
761-
nloc,
762-
self.nnei,
763-
self.filter_neuron[-1],
764-
dtype=xyz_scatter.dtype,
765-
device=xyz_scatter.device,
766-
)
753+
# ``gg`` (the pair representation g2) is not formed on this path;
754+
# it is returned as ``None``, so a zero-element placeholder keeps
755+
# ``gg`` a tensor without the full (nf, nloc, nnei, ng) allocation.
756+
gg = xyz_scatter.new_empty(0)
767757
g2_is_none = True
768758
else:
769759
# (nf x nl) x nnei x ng

source/op/pt/CMakeLists.txt

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,20 @@
11
file(GLOB OP_SRC print_summary.cc comm.cc tabulate_multi_device.cc)
2-
# Fused graph-lower inference operators (CUDA / cuBLAS); GPU builds only.
2+
# Fused graph-lower inference operators (CUDA / cuBLAS); GPU builds only. The
3+
# CUDA language is scoped per directory, so it must be enabled here: the sibling
4+
# GPU library turns it on only within its own subtree, which does not cover this
5+
# target.
36
if(USE_CUDA_TOOLKIT)
7+
find_package(CUDAToolkit REQUIRED)
8+
if(NOT DEFINED CMAKE_CUDA_ARCHITECTURES)
9+
# CUDA 12.9 and 13.x CCCL fail to compile CUB/Thrust with -arch=all.
10+
if(CUDAToolkit_VERSION VERSION_GREATER_EQUAL "12.9" AND CUDAToolkit_VERSION
11+
VERSION_LESS "14.0")
12+
set(CMAKE_CUDA_ARCHITECTURES all-major)
13+
else()
14+
set(CMAKE_CUDA_ARCHITECTURES all)
15+
endif()
16+
endif()
17+
enable_language(CUDA)
418
list(
519
APPEND
620
OP_SRC

source/op/pt/graph_fitting.cu

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,11 @@ torch::Tensor graph_fitting_backward(torch::Tensor d_e,
266266
std::vector<int64_t> resnets,
267267
torch::Tensor w_head) {
268268
const long n_node = x.size(0);
269+
auto d_x = torch::empty_like(x);
270+
// Guard the empty system before the division by ``n_node`` below.
271+
if (n_node == 0) {
272+
return d_x;
273+
}
269274
auto stream = at::cuda::getCurrentCUDAStream();
270275
const int n_layer = (int)ws.size();
271276
const long total_width = saved.numel() / (2 * n_node);
@@ -274,10 +279,6 @@ torch::Tensor graph_fitting_backward(torch::Tensor d_e,
274279
offset[l + 1] = offset[l] + ws[l].size(1);
275280
}
276281
auto f32 = x.options().dtype(torch::kFloat32);
277-
auto d_x = torch::empty_like(x);
278-
if (n_node == 0) {
279-
return d_x;
280-
}
281282
auto d_e_c = d_e.contiguous();
282283

283284
long width_max = 0;

0 commit comments

Comments
 (0)