Commit efc27cf
authored
refactor: use Array API-compatible tabulate math (#5366)
## Summary
- port `deepmd/utils/tabulate_math.py` helpers from NumPy-only operators
to Array API-compatible operators
- let the PT / pt_expt tabulation wrappers choose a torch sample backend
so the shared math path can execute on torch devices
- add a regression test that verifies the helper functions use the
provided Array API namespace rather than silently falling back to NumPy
## Testing
- `. .venv/bin/activate && PYTHONPATH=. pytest -q
source/tests/common/test_tabulate_math_array_api.py`
- `python3 -m py_compile deepmd/utils/tabulate_math.py
deepmd/pt/utils/tabulate.py deepmd/pt_expt/utils/tabulate.py
source/tests/common/test_tabulate_math_array_api.py`
Closes #5352
Authored by OpenClaw (model: gpt-5.4)
<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit
* **New Features**
* Device-aware sampling so tabulation math runs on the active compute
device.
* **Refactor**
* Tabulation math migrated to Array API–compatible implementation with
unified backend selection, device-aware tensor handling, and updated
derivative propagation.
* **Tests**
* Added tests validating gradient/chain-rule computations and numerical
stability versus NumPy under the Array API backend.
* **Documentation**
* Module docs updated to reflect Array API compatibility.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->1 parent b02fd91 commit efc27cf
File tree
4 files changed
+277
-156
lines changed- deepmd
- pt_expt/utils
- pt/utils
- utils
- source/tests/common
4 files changed
+277
-156
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | 3 | | |
4 | | - | |
5 | | - | |
6 | | - | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
7 | 7 | | |
8 | 8 | | |
9 | 9 | | |
| |||
31 | 31 | | |
32 | 32 | | |
33 | 33 | | |
34 | | - | |
35 | | - | |
| 34 | + | |
| 35 | + | |
36 | 36 | | |
37 | 37 | | |
38 | 38 | | |
| |||
91 | 91 | | |
92 | 92 | | |
93 | 93 | | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
94 | 98 | | |
95 | 99 | | |
96 | 100 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | 3 | | |
4 | | - | |
5 | | - | |
6 | | - | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
7 | 7 | | |
8 | 8 | | |
9 | 9 | | |
| |||
70 | 70 | | |
71 | 71 | | |
72 | 72 | | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
73 | 83 | | |
74 | 84 | | |
75 | 85 | | |
| |||
0 commit comments