Skip to content

Commit 8d11cd0

Browse files
committed
feat(pt): add optimized Neo CuTe inference path
Add the production Neo CuTe inference integration, architecture-specific kernels, correctness coverage, runtime dependencies, licensing, and final review cleanup.
1 parent ced0016 commit 8d11cd0

82 files changed

Lines changed: 31677 additions & 79 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/test_cuda.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,14 +58,15 @@ jobs:
5858
- run: |
5959
export PYTORCH_ROOT=$(python -c 'import torch;print(torch.__path__[0])')
6060
export TENSORFLOW_ROOT=$(python -c 'import importlib.util,pathlib;print(pathlib.Path(importlib.util.find_spec("tensorflow").origin).parent)')
61-
source/install/uv_with_retry.sh pip install --system -v -e .[gpu,test,lmp,cu12,torch,jax] mpi4py --reinstall-package deepmd-kit
61+
source/install/uv_with_retry.sh pip install --system -v -e .[gpu,test,lmp,cu12,cute,torch,jax] mpi4py --reinstall-package deepmd-kit
6262
# See https://github.com/jax-ml/jax/issues/29042
6363
source/install/uv_with_retry.sh pip install --system -U 'nvidia-cublas-cu12>=12.9.0.13'
6464
env:
6565
DP_VARIANT: cuda
6666
DP_ENABLE_NATIVE_OPTIMIZATION: 1
6767
DP_ENABLE_PYTORCH: 1
6868
- run: dp --version
69+
- run: python -c "import cutlass.cute"
6970
- run: python -m pytest source/tests --ignore=source/tests/pd
7071
env:
7172
NUM_WORKERS: 0
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
2+
# SPDX-License-Identifier: LGPL-3.0-or-later
3+
"""Neo-specialized CuTe kernels and PyTorch integration."""
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
# SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
2+
# SPDX-License-Identifier: LGPL-3.0-or-later
3+
"""Device-aware caching for architecture-specific CuTe compilation."""
4+
5+
from __future__ import (
6+
annotations,
7+
)
8+
9+
from collections.abc import (
10+
Callable,
11+
)
12+
from contextlib import (
13+
nullcontext,
14+
)
15+
from functools import (
16+
lru_cache,
17+
wraps,
18+
)
19+
from typing import (
20+
Any,
21+
TypeVar,
22+
cast,
23+
)
24+
25+
_T = TypeVar("_T", bound=Callable[..., Any])
26+
27+
28+
def current_cuda_compile_identity() -> tuple[int, int, int]:
29+
"""Return the current CUDA device and its compute capability."""
30+
import torch
31+
32+
device_index = torch.cuda.current_device()
33+
major, minor = torch.cuda.get_device_capability(device_index)
34+
return device_index, major, minor
35+
36+
37+
def device_aware_lru_cache(
38+
*,
39+
maxsize: int,
40+
identity_getter: Callable[[], tuple[int, int, int]] = current_cuda_compile_identity,
41+
) -> Callable[[_T], _T]:
42+
"""Cache a compile factory separately for each CUDA device architecture."""
43+
44+
def decorate(function: _T) -> _T:
45+
@lru_cache(maxsize=maxsize)
46+
def cached(
47+
identity: tuple[int, int, int],
48+
args: tuple[Any, ...],
49+
kwargs: tuple[tuple[str, Any], ...],
50+
) -> Any:
51+
import torch
52+
53+
device_index = identity[0]
54+
device_count = getattr(torch.cuda, "device_count", None)
55+
device_is_visible = device_count is None or device_index < device_count()
56+
compile_device = (
57+
torch.cuda.device(device_index)
58+
if torch.cuda.is_available() and device_is_visible
59+
else nullcontext()
60+
)
61+
with compile_device:
62+
return function(*args, **dict(kwargs))
63+
64+
@wraps(function)
65+
def wrapper(*args: Any, **kwargs: Any) -> Any:
66+
return cached(
67+
identity_getter(),
68+
args,
69+
tuple(sorted(kwargs.items())),
70+
)
71+
72+
wrapper.cache_clear = cached.cache_clear
73+
wrapper.cache_info = cached.cache_info
74+
wrapper.cache_parameters = cached.cache_parameters
75+
wrapper._deepmd_cute_cached = True
76+
return cast("_T", wrapper)
77+
78+
return decorate

0 commit comments

Comments
 (0)