Skip to content

Commit c9df92e

Browse files
authored
Merge branch 'master' into test/reuse-pt2-aot-fixtures
2 parents 0cf6550 + 4f827cc commit c9df92e

395 files changed

Lines changed: 43449 additions & 4453 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/build_cc.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ jobs:
2828
dp_variant: clang
2929
steps:
3030
- uses: actions/checkout@v7
31-
- uses: actions/setup-python@v6
31+
- uses: actions/setup-python@v7
3232
with:
3333
python-version: "3.11"
3434
- uses: lukka/get-cmake@latest

.github/workflows/build_wheel.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ jobs:
162162
path: dist/packages
163163
pattern: cibw-*
164164
merge-multiple: true
165-
- uses: actions/setup-python@v6
165+
- uses: actions/setup-python@v7
166166
name: Install Python
167167
with:
168168
python-version: "3.11"

.github/workflows/codeql.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ jobs:
3131
steps:
3232
- name: Checkout repository
3333
uses: actions/checkout@v7
34-
- uses: actions/setup-python@v6
34+
- uses: actions/setup-python@v7
3535
with:
3636
python-version: "3.11"
3737
cache: "pip"

.github/workflows/copilot-setup-steps.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ jobs:
3333
uses: actions/checkout@v7
3434

3535
- name: Set up Python
36-
uses: actions/setup-python@v6
36+
uses: actions/setup-python@v7
3737
with:
3838
python-version: "3.10"
3939

.github/workflows/labeler.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,6 @@ jobs:
99
pull-requests: write
1010
runs-on: ubuntu-slim
1111
steps:
12-
- uses: actions/labeler@v6
12+
- uses: actions/labeler@v7
1313
with:
1414
repo-token: "${{ secrets.GITHUB_TOKEN }}"

.github/workflows/test_cc.yml

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,11 @@ name: Test C++
1414
jobs:
1515
testcc:
1616
name: Test C++
17-
runs-on: ubuntu-22.04
17+
runs-on: ${{ matrix.check_memleak == false && github.repository_owner == 'deepmodeling' && 'cpu' || 'ubuntu-22.04' }}
1818
strategy:
1919
matrix:
20+
# Only regular jobs run the LAMMPS tests. Use self-hosted CPU runners
21+
# for those jobs in deepmodeling, with a hosted fallback for forks.
2022
include:
2123
- check_memleak: true
2224
enable_tensorflow: true
@@ -36,7 +38,12 @@ jobs:
3638
enable_paddle: true
3739
steps:
3840
- uses: actions/checkout@v7
39-
- uses: actions/setup-python@v6
41+
- name: Install GCC
42+
run: |
43+
sudo apt-get update
44+
sudo apt-get install --yes build-essential
45+
if: ${{ matrix.check_memleak == false && github.repository_owner == 'deepmodeling' }}
46+
- uses: actions/setup-python@v7
4047
with:
4148
python-version: "3.11"
4249
cache: "pip"

.github/workflows/test_cuda.yml

Lines changed: 52 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,19 @@ concurrency:
1414
cancel-in-progress: true
1515
name: Test CUDA
1616
jobs:
17-
test_cuda:
18-
name: Test Python and C++ on CUDA
17+
test_python:
18+
name: Test Python on CUDA
1919
runs-on: gpu
20+
# The serial Python test suite can take several hours on the GPU runner.
21+
timeout-minutes: 480
2022
# https://github.com/deepmodeling/deepmd-kit/pull/2884#issuecomment-1744216845
2123
# container:
2224
# image: nvidia/cuda:12.9.1-cudnn-devel-ubuntu22.04
2325
# options: --gpus all
2426
if: github.repository_owner == 'deepmodeling' && (github.event_name == 'pull_request' && github.event.label && github.event.label.name == 'Test CUDA' || github.event_name == 'workflow_dispatch' || github.event_name == 'merge_group')
2527
steps:
2628
- uses: actions/checkout@v7
27-
- uses: actions/setup-python@v6
29+
- uses: actions/setup-python@v7
2830
with:
2931
python-version: "3.11"
3032
# cache: 'pip'
@@ -68,6 +70,51 @@ jobs:
6870
XLA_PYTHON_CLIENT_PREALLOCATE: false
6971
XLA_PYTHON_CLIENT_ALLOCATOR: platform
7072
FLAGS_use_stride_compute_kernel: 0
73+
74+
test_cc:
75+
name: Test C++ on CUDA
76+
runs-on: gpu
77+
if: github.repository_owner == 'deepmodeling' && (github.event_name == 'pull_request' && github.event.label && github.event.label.name == 'Test CUDA' || github.event_name == 'workflow_dispatch' || github.event_name == 'merge_group')
78+
steps:
79+
# Jobs run on separate runners, so the C++ job needs its own complete
80+
# CUDA toolchain and Python dependency installation.
81+
- uses: actions/checkout@v7
82+
- uses: actions/setup-python@v7
83+
with:
84+
python-version: "3.11"
85+
# cache: 'pip'
86+
- name: Install wget and unzip
87+
run: sudo apt-get update && sudo apt-get install -y wget unzip
88+
- uses: lukka/get-cmake@latest
89+
with:
90+
useLocalCache: true
91+
useCloudCache: false
92+
- run: |
93+
UBUNTU_VERSION=$(lsb_release -rs | tr -d '.')
94+
OS_NAME="ubuntu${UBUNTU_VERSION}"
95+
echo "Current OS: ${OS_NAME}"
96+
97+
wget https://developer.download.nvidia.com/compute/cuda/repos/${OS_NAME}/x86_64/cuda-keyring_1.1-1_all.deb \
98+
&& sudo dpkg -i cuda-keyring_1.1-1_all.deb \
99+
&& sudo apt-get update \
100+
&& sudo apt-get -y install cuda-toolkit-12-9 cudnn9-cuda-12
101+
echo "CUDA_PATH=/usr/local/cuda-12.9" >> $GITHUB_ENV
102+
echo "/usr/local/cuda-12.9/bin" >> $GITHUB_PATH
103+
# if: false # skip as we use nvidia image
104+
- run: python -m pip install -U uv
105+
- run: source/install/uv_with_retry.sh pip install --system --group pin_tensorflow_gpu --group pin_pytorch_gpu --group pin_jax_gpu
106+
- run: |
107+
export PYTORCH_ROOT=$(python -c 'import torch;print(torch.__path__[0])')
108+
export TENSORFLOW_ROOT=$(python -c 'import importlib.util,pathlib;print(pathlib.Path(importlib.util.find_spec("tensorflow").origin).parent)')
109+
pip install --find-links "https://www.paddlepaddle.org.cn/packages/nightly/cu126/paddlepaddle-gpu/" --index-url https://pypi.org/simple --trusted-host www.paddlepaddle.org.cn --trusted-host paddlepaddle.org.cn "paddlepaddle-gpu==3.4.0.dev20260310"
110+
source/install/uv_with_retry.sh pip install --system -v -e .[gpu,test,lmp,cu12,torch,jax] mpi4py --reinstall-package deepmd-kit
111+
# See https://github.com/jax-ml/jax/issues/29042
112+
source/install/uv_with_retry.sh pip install --system -U 'nvidia-cublas-cu12>=12.9.0.13'
113+
env:
114+
DP_VARIANT: cuda
115+
DP_ENABLE_NATIVE_OPTIMIZATION: 1
116+
DP_ENABLE_PYTORCH: 1
117+
- run: dp --version
71118
- name: Convert models
72119
run: source/tests/infer/convert-models.sh
73120
- run: |
@@ -96,12 +143,12 @@ jobs:
96143
CUDA_VISIBLE_DEVICES: 0
97144
pass:
98145
name: Pass testing on CUDA
99-
needs: [test_cuda]
146+
needs: [test_python, test_cc]
100147
runs-on: ubuntu-slim
101148
if: always()
102149
steps:
103150
- name: Decide whether the needed jobs succeeded or failed
104151
uses: re-actors/alls-green@release/v1
105152
with:
106153
jobs: ${{ toJSON(needs) }}
107-
allowed-skips: test_cuda
154+
allowed-skips: test_python, test_cc

.github/workflows/test_python.yml

Lines changed: 32 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ jobs:
2525

2626
steps:
2727
- uses: actions/checkout@v7
28-
- uses: actions/setup-python@v6
28+
- uses: actions/setup-python@v7
2929
with:
3030
python-version: ${{ matrix.python }}
3131
- run: python -m pip install -U uv
@@ -56,41 +56,59 @@ jobs:
5656
# the key must never match, even when restarting workflows, as that
5757
# will cause durations to get out of sync between groups, the
5858
# combined durations will be loaded if available
59-
key: test2-durations-split-${{ github.run_id }}-${{ github.run_number}}-${{ matrix.python }}-${{ matrix.group }}
59+
key: test4-durations-split-${{ github.run_id }}-${{ github.run_number }}-${{ github.run_attempt }}-${{ matrix.python }}-${{ matrix.group }}
6060
restore-keys: |
61-
test2-durations-combined-${{ matrix.python }}-${{ github.sha }}
62-
test2-durations-combined-${{ matrix.python }}
63-
- run: pytest --cov=deepmd source/tests --ignore=source/tests/tf2 --splits 12 --group ${{ matrix.group }} --store-durations --clean-durations --durations-path=.test_durations --splitting-algorithm least_duration
61+
test4-durations-combined-${{ matrix.python }}-${{ github.sha }}
62+
test4-durations-combined-${{ matrix.python }}
63+
- name: Prepare independent duration inputs
64+
run: |
65+
for output in main tf2 jax2tf consistent_tf2; do
66+
if [ -f .test_durations ]; then
67+
cp .test_durations ".test_durations_${output}"
68+
fi
69+
done
70+
# Keep fixture-sharing classes/modules together, then balance those
71+
# indivisible units by their recorded durations.
72+
- run: python -m pytest -p source.tests.ci_split --cov=deepmd source/tests --ignore=source/tests/tf2 --ci-splits 12 --ci-group ${{ matrix.group }} --store-durations --clean-durations --durations-path=.test_durations_main
6473
env:
6574
NUM_WORKERS: 0
6675
DP_CI_IMPORT_PADDLE_BEFORE_TF: 1
6776
FLAGS_use_stride_compute_kernel: 0
6877
- name: Test TF2 eager mode
6978
run: |
7079
run_pytest_allow_no_tests() {
80+
local durations_path=$1
81+
shift
7182
set +e
72-
pytest "$@"
83+
pytest "$@" \
84+
--store-durations \
85+
--clean-durations \
86+
--durations-path="$durations_path"
7387
local status=$?
7488
set -e
7589
if [ "$status" -eq 5 ]; then
7690
# pytest-split may leave an individual shard with no selected
7791
# tests after path/-k filtering. Other shards still cover the
7892
# selected tests, so do not fail the whole matrix for exit 5.
93+
printf '{}\n' > "$durations_path"
7994
return 0
8095
fi
8196
return "$status"
8297
}
8398
84-
run_pytest_allow_no_tests --cov=deepmd --cov-append \
99+
run_pytest_allow_no_tests .test_durations_tf2 \
100+
--cov=deepmd --cov-append \
85101
source/tests/tf2 \
86102
--splits 12 \
87103
--group ${{ matrix.group }}
88-
run_pytest_allow_no_tests --cov=deepmd --cov-append \
104+
run_pytest_allow_no_tests .test_durations_jax2tf \
105+
--cov=deepmd --cov-append \
89106
source/tests/consistent/io/test_io.py \
90107
source/jax2tf_tests \
91108
--splits 12 \
92109
--group ${{ matrix.group }}
93-
run_pytest_allow_no_tests --cov=deepmd --cov-append \
110+
run_pytest_allow_no_tests .test_durations_consistent_tf2 \
111+
--cov=deepmd --cov-append \
94112
source/tests/consistent \
95113
-k tf2 \
96114
--splits 12 \
@@ -100,7 +118,8 @@ jobs:
100118
DP_TEST_TF2_ONLY: 1
101119
DP_DTYPE_PROMOTION_STRICT: 1
102120
DP_CI_IMPORT_PADDLE_BEFORE_TF: 1
103-
- run: mv .test_durations .test_durations_${{ matrix.group }}
121+
- name: Combine shard durations
122+
run: jq -s 'reduce .[] as $durations ({}; . * $durations)' .test_durations_main .test_durations_tf2 .test_durations_jax2tf .test_durations_consistent_tf2 > .test_durations_${{ matrix.group }}
104123
- name: Upload partial durations
105124
uses: actions/upload-artifact@v7
106125
with:
@@ -132,15 +151,15 @@ jobs:
132151
# key won't match during the first run for the given commit, but
133152
# restore-key will if there's a previous stored durations file,
134153
# so cache will both be loaded and stored
135-
key: test2-durations-combined-${{ matrix.python }}-${{ github.sha }}
136-
restore-keys: test2-durations-combined-${{ matrix.python }}
154+
key: test4-durations-combined-${{ matrix.python }}-${{ github.sha }}
155+
restore-keys: test4-durations-combined-${{ matrix.python }}
137156
- name: Download artifacts
138157
uses: actions/download-artifact@v8
139158
with:
140159
pattern: split-${{ matrix.python }}-*
141160
merge-multiple: true
142161
- name: Combine test durations
143-
run: jq -s add .test_durations_* > .test_durations
162+
run: jq -s 'reduce .[] as $durations ({}; . * $durations)' .test_durations_* > .test_durations
144163
pass:
145164
name: Pass testing Python
146165
needs: [testpython, update_durations]

.pre-commit-config.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,14 @@ repos:
2323
- id: check-toml
2424
# Python
2525
- repo: https://github.com/PyCQA/isort
26-
rev: 9.0.0a3
26+
rev: 9.0.0b1
2727
hooks:
2828
- id: isort
2929
files: \.py$
3030
exclude: ^source/3rdparty
3131
- repo: https://github.com/astral-sh/ruff-pre-commit
3232
# Ruff version.
33-
rev: v0.15.18
33+
rev: v0.16.0
3434
hooks:
3535
- id: ruff
3636
args: ["--fix"]
@@ -62,7 +62,7 @@ repos:
6262
- mdformat-gfm-alerts==2.0.0
6363
# C++
6464
- repo: https://github.com/pre-commit/mirrors-clang-format
65-
rev: v22.1.5
65+
rev: v22.1.8
6666
hooks:
6767
- id: clang-format
6868
exclude: ^(source/3rdparty|source/lib/src/gpu/cudart/.+\.inc|.+\.ipynb$|source/tests/infer/.+\.json$)

deepmd/_vendors/ndtensorflow/_namespace.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1650,7 +1650,11 @@ def take(x: Array, indices: Array, /, *, axis: int | None = None) -> Array:
16501650
axis = 0
16511651
axis = _normalize_axis(axis, tensor.shape.rank)
16521652
indices_ = tf.cast(_unwrap(indices), tf.int64)
1653-
dim = tensor.shape[axis]
1653+
# ``TensorShape.__getitem__`` returns either ``None`` or
1654+
# ``Dimension(None)`` depending on TensorFlow's global v2-shape setting.
1655+
# ``as_list`` normalizes both representations, which keeps dynamic-axis
1656+
# indexing valid when another test or caller enables legacy TensorShape.
1657+
dim = tensor.shape.as_list()[axis]
16541658
dim = (
16551659
tf.shape(tensor, out_type=tf.int64)[axis]
16561660
if dim is None
@@ -1664,7 +1668,7 @@ def take_along_axis(x: Array, indices: Array, /, *, axis: int = -1) -> Array:
16641668
tensor = _unwrap(x)
16651669
indices_ = tf.cast(_unwrap(indices), tf.int64)
16661670
axis = _normalize_axis(axis, tensor.shape.rank)
1667-
dim = tensor.shape[axis]
1671+
dim = tensor.shape.as_list()[axis]
16681672
dim = (
16691673
tf.shape(tensor, out_type=tf.int64)[axis]
16701674
if dim is None

0 commit comments

Comments
 (0)