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
style: complete type annotation enforcement for deepmd.pt (#4943)
This PR implements comprehensive type annotation coverage for the
deepmd.pt PyTorch backend and resolves critical TorchScript compilation
errors that prevented model deployment.
## Type Annotation Enforcement
Added complete type annotations to all deepmd.pt module functions,
eliminating 7,030+ ANN violations across 107 Python files. This
provides:
- Better IDE support and code maintainability
- Consistent typing standards throughout the PyTorch backend
- Enhanced developer experience with clear function signatures
## TorchScript Compilation Fixes
Resolved multiple TorchScript compilation errors that prevented model
deployment:
```python
# Before: TorchScript compilation failed
sw.to(dtype=env.GLOBAL_PT_FLOAT_PRECISION) # Error on Optional[Tensor]
# After: Proper None handling
sw.to(dtype=env.GLOBAL_PT_FLOAT_PRECISION) if sw is not None else None
```
Key fixes include:
- Added proper None checks before `.to()` calls on
`Optional[torch.Tensor]` values
- Resolved issues across all descriptor types (SE-A, SE-T, SE-T-TEBD,
DPA1, DPA2, DPA3)
- Fixed abstract method patterns that conflicted with TorchScript
compilation
- Corrected return type annotations in SpinModel to accurately reflect
Optional types
## Pre-commit Compliance
- Fixed deprecated type annotation imports (Dict→dict, Tuple→tuple)
- Resolved import ordering and undefined name issues
- Removed unnecessary imports and improved code consistency
- All pre-commit checks now pass with zero violations
The PyTorch backend now has complete type coverage and full TorchScript
deployment compatibility, enabling production model serving scenarios.
<!-- 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 <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>
0 commit comments