Skip to content

Commit 29c0369

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 29c0369

82 files changed

Lines changed: 30930 additions & 82 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: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
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 annotations
6+
7+
from collections.abc import Callable
8+
from contextlib import nullcontext
9+
from functools import lru_cache, wraps
10+
from typing import Any, TypeVar, cast
11+
12+
13+
_T = TypeVar("_T", bound=Callable[..., Any])
14+
15+
16+
def current_cuda_compile_identity() -> tuple[int, int, int]:
17+
"""Return the current CUDA device and its compute capability."""
18+
import torch
19+
20+
device_index = torch.cuda.current_device()
21+
major, minor = torch.cuda.get_device_capability(device_index)
22+
return device_index, major, minor
23+
24+
25+
def device_aware_lru_cache(
26+
*,
27+
maxsize: int,
28+
identity_getter: Callable[[], tuple[int, int, int]] = current_cuda_compile_identity,
29+
) -> Callable[[_T], _T]:
30+
"""Cache a compile factory separately for each CUDA device architecture."""
31+
32+
def decorate(function: _T) -> _T:
33+
@lru_cache(maxsize=maxsize)
34+
def cached(
35+
identity: tuple[int, int, int],
36+
args: tuple[Any, ...],
37+
kwargs: tuple[tuple[str, Any], ...],
38+
) -> Any:
39+
import torch
40+
41+
device_index = identity[0]
42+
device_count = getattr(torch.cuda, "device_count", None)
43+
device_is_visible = device_count is None or device_index < device_count()
44+
compile_device = (
45+
torch.cuda.device(device_index)
46+
if torch.cuda.is_available() and device_is_visible
47+
else nullcontext()
48+
)
49+
with compile_device:
50+
return function(*args, **dict(kwargs))
51+
52+
@wraps(function)
53+
def wrapper(*args: Any, **kwargs: Any) -> Any:
54+
return cached(
55+
identity_getter(),
56+
args,
57+
tuple(sorted(kwargs.items())),
58+
)
59+
60+
wrapper.cache_clear = cached.cache_clear
61+
wrapper.cache_info = cached.cache_info
62+
wrapper.cache_parameters = cached.cache_parameters
63+
wrapper._deepmd_cute_cached = True
64+
return cast("_T", wrapper)
65+
66+
return decorate

0 commit comments

Comments
 (0)