You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This PR fixes critical PyTorch JIT compilation errors that were
preventing model serialization and deployment. The main issue was that
PyTorch JIT cannot handle certain type annotations, specifically
`Union[np.ndarray, Any]` (the `Array` type) and `KeysView[str]` return
types.
## Problem
PyTorch JIT compilation was failing with errors like:
```
AssertionError: Unsupported annotation typing.Union[numpy.ndarray, typing.Any] could not be resolved because None could not be resolved.
```
This prevented users from using `torch.jit.script()` on trained models,
blocking deployment scenarios.
## Solution
- **Removed incompatible type annotations** from methods used by PyTorch
JIT compilation
- **Added `# noqa:ANNxxx` comments** to suppress ruff linting warnings
for missing type annotations
- **Fixed `KeysView[str]` return types** that caused JIT compilation
failures
- **Maintained type safety** elsewhere in the codebase where JIT
compatibility isn't required
## Files Changed
- `deepmd/dpmodel/utils/network.py`: Removed `Array` type annotations
from `call` methods and activation functions
- `deepmd/dpmodel/output_def.py`: Removed `KeysView[str]` return type
annotations from `keys` methods
## Validation
All PyTorch JIT tests now pass:
- ✅ TestEnergyModelSeA.test_jit
- ✅ TestDOSModelSeA.test_jit
- ✅ TestEnergyModelDPA1.test_jit
- ✅ TestEnergyModelDPA2.test_jit
- ✅ TestEnergyModelHybrid.test_jit
- ✅ TestEnergyModelHybrid2.test_jit
- ✅ TestEnergyModelDPA2IntRcut.test_jit
Models can now be successfully JIT compiled for deployment while
maintaining full functionality and backward compatibility.
<!-- START COPILOT CODING AGENT TIPS -->
---
✨ Let Copilot coding agent [set things up for
you](https://github.com/deepmodeling/deepmd-kit/issues/new?title=✨+Set+up+Copilot+instructions&body=Configure%20instructions%20for%20this%20repository%20as%20documented%20in%20%5BBest%20practices%20for%20Copilot%20coding%20agent%20in%20your%20repository%5D%28https://gh.io/copilot-coding-agent-tips%29%2E%0A%0A%3COnboard%20this%20repo%3E&assignees=copilot)
— coding agent works faster and does higher quality work when set up for
your repo.
---------
Signed-off-by: Jinzhe Zeng <njzjz@qq.com>
Signed-off-by: Jinzhe Zeng <jinzhe.zeng@ustc.edu.cn>
Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: njzjz <9496702+njzjz@users.noreply.github.com>
Co-authored-by: Jinzhe Zeng <jinzhe.zeng@ustc.edu.cn>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
0 commit comments