Commit 6ec59ef
style(tf): add type annotations (#4945)
Addressed review feedback to replace remaining `Any` type annotations
with specific types across training, fitting, and model modules.
## Changes
### Learning Rate Types
- `EnerFitting.get_loss()` and `StandardModel.get_loss()`: `lr: Any` →
`lr: LearningRateExp`
### Trainer Method Signatures
- `build()`: `data: dict` → `data: DeepmdDataSystem | None`
- `_build_loss()`: `-> Any` → `-> tuple[None, None] | tuple[tf.Tensor,
dict[str, tf.Tensor]]`
- `_build_network()`: `data: dict` → `data: DeepmdDataSystem`
- `get_global_step()`: `-> Any` → `-> int`
### Example
```python
# Before
def get_loss(self, loss: dict, lr: Any) -> Loss:
...
# After
def get_loss(self, loss: dict, lr: LearningRateExp) -> Loss:
...
```
The `_build_loss()` return type now accurately reflects that it returns
either `(None, None)` when `stop_batch == 0`, or `(tf.Tensor, dict[str,
tf.Tensor])` from the loss build.
<!-- 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.
---------
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: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>1 parent 8787b45 commit 6ec59ef
File tree
92 files changed
+1364
-784
lines changed- deepmd/tf
- cluster
- descriptor
- entrypoints
- fit
- infer
- loss
- model
- modifier
- nvnmd
- descriptor
- entrypoints
- utils
- op
- train
- utils
Some content is hidden
Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
92 files changed
+1364
-784
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
14 | 14 | | |
15 | 15 | | |
16 | 16 | | |
17 | | - | |
| 17 | + | |
18 | 18 | | |
19 | 19 | | |
20 | 20 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
14 | 14 | | |
15 | 15 | | |
16 | 16 | | |
| 17 | + | |
17 | 18 | | |
18 | 19 | | |
19 | 20 | | |
| |||
118 | 119 | | |
119 | 120 | | |
120 | 121 | | |
121 | | - | |
| 122 | + | |
122 | 123 | | |
123 | 124 | | |
124 | 125 | | |
| |||
146 | 147 | | |
147 | 148 | | |
148 | 149 | | |
149 | | - | |
150 | | - | |
151 | | - | |
152 | | - | |
| 150 | + | |
| 151 | + | |
153 | 152 | | |
154 | 153 | | |
155 | | - | |
| 154 | + | |
156 | 155 | | |
157 | 156 | | |
158 | | - | |
| 157 | + | |
159 | 158 | | |
160 | 159 | | |
161 | 160 | | |
| |||
233 | 232 | | |
234 | 233 | | |
235 | 234 | | |
236 | | - | |
| 235 | + | |
237 | 236 | | |
238 | 237 | | |
239 | 238 | | |
| |||
319 | 318 | | |
320 | 319 | | |
321 | 320 | | |
322 | | - | |
| 321 | + | |
323 | 322 | | |
324 | 323 | | |
325 | 324 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3 | 3 | | |
4 | 4 | | |
5 | 5 | | |
| 6 | + | |
6 | 7 | | |
7 | 8 | | |
8 | 9 | | |
9 | 10 | | |
10 | 11 | | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
11 | 17 | | |
12 | 18 | | |
13 | 19 | | |
| |||
48 | 54 | | |
49 | 55 | | |
50 | 56 | | |
51 | | - | |
| 57 | + | |
52 | 58 | | |
53 | 59 | | |
54 | 60 | | |
| |||
132 | 138 | | |
133 | 139 | | |
134 | 140 | | |
135 | | - | |
| 141 | + | |
136 | 142 | | |
137 | 143 | | |
138 | 144 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
46 | 46 | | |
47 | 47 | | |
48 | 48 | | |
49 | | - | |
| 49 | + | |
50 | 50 | | |
51 | 51 | | |
52 | 52 | | |
| |||
142 | 142 | | |
143 | 143 | | |
144 | 144 | | |
145 | | - | |
| 145 | + | |
146 | 146 | | |
147 | 147 | | |
148 | 148 | | |
| |||
182 | 182 | | |
183 | 183 | | |
184 | 184 | | |
185 | | - | |
| 185 | + | |
186 | 186 | | |
187 | 187 | | |
188 | 188 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
2 | 5 | | |
3 | 6 | | |
4 | 7 | | |
| |||
58 | 61 | | |
59 | 62 | | |
60 | 63 | | |
61 | | - | |
| 64 | + | |
62 | 65 | | |
63 | 66 | | |
64 | 67 | | |
| |||
159 | 162 | | |
160 | 163 | | |
161 | 164 | | |
162 | | - | |
| 165 | + | |
163 | 166 | | |
164 | 167 | | |
165 | 168 | | |
| |||
372 | 375 | | |
373 | 376 | | |
374 | 377 | | |
375 | | - | |
376 | | - | |
| 378 | + | |
| 379 | + | |
| 380 | + | |
| 381 | + | |
| 382 | + | |
| 383 | + | |
| 384 | + | |
377 | 385 | | |
378 | 386 | | |
379 | 387 | | |
| |||
405 | 413 | | |
406 | 414 | | |
407 | 415 | | |
408 | | - | |
| 416 | + | |
409 | 417 | | |
410 | 418 | | |
411 | 419 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
3 | 10 | | |
4 | 11 | | |
5 | 12 | | |
| |||
180 | 187 | | |
181 | 188 | | |
182 | 189 | | |
183 | | - | |
| 190 | + | |
184 | 191 | | |
185 | 192 | | |
186 | 193 | | |
| |||
346 | 353 | | |
347 | 354 | | |
348 | 355 | | |
349 | | - | |
| 356 | + | |
350 | 357 | | |
351 | 358 | | |
352 | 359 | | |
| |||
393 | 400 | | |
394 | 401 | | |
395 | 402 | | |
396 | | - | |
| 403 | + | |
397 | 404 | | |
398 | 405 | | |
399 | 406 | | |
| |||
747 | 754 | | |
748 | 755 | | |
749 | 756 | | |
750 | | - | |
751 | | - | |
| 757 | + | |
| 758 | + | |
| 759 | + | |
| 760 | + | |
| 761 | + | |
| 762 | + | |
| 763 | + | |
| 764 | + | |
| 765 | + | |
752 | 766 | | |
753 | 767 | | |
754 | 768 | | |
| |||
834 | 848 | | |
835 | 849 | | |
836 | 850 | | |
837 | | - | |
838 | | - | |
| 851 | + | |
| 852 | + | |
| 853 | + | |
| 854 | + | |
| 855 | + | |
| 856 | + | |
| 857 | + | |
839 | 858 | | |
840 | 859 | | |
841 | 860 | | |
| |||
876 | 895 | | |
877 | 896 | | |
878 | 897 | | |
879 | | - | |
| 898 | + | |
880 | 899 | | |
881 | 900 | | |
882 | 901 | | |
| |||
886 | 905 | | |
887 | 906 | | |
888 | 907 | | |
889 | | - | |
890 | | - | |
891 | | - | |
892 | | - | |
893 | | - | |
| 908 | + | |
| 909 | + | |
| 910 | + | |
| 911 | + | |
| 912 | + | |
894 | 913 | | |
895 | 914 | | |
896 | 915 | | |
| |||
939 | 958 | | |
940 | 959 | | |
941 | 960 | | |
942 | | - | |
943 | | - | |
944 | | - | |
945 | | - | |
946 | | - | |
947 | | - | |
948 | | - | |
949 | | - | |
950 | | - | |
951 | | - | |
952 | | - | |
953 | | - | |
954 | | - | |
955 | | - | |
956 | | - | |
| 961 | + | |
| 962 | + | |
| 963 | + | |
| 964 | + | |
| 965 | + | |
| 966 | + | |
| 967 | + | |
| 968 | + | |
| 969 | + | |
| 970 | + | |
| 971 | + | |
| 972 | + | |
| 973 | + | |
| 974 | + | |
| 975 | + | |
957 | 976 | | |
958 | 977 | | |
959 | 978 | | |
| |||
1159 | 1178 | | |
1160 | 1179 | | |
1161 | 1180 | | |
1162 | | - | |
1163 | | - | |
1164 | | - | |
1165 | | - | |
1166 | | - | |
1167 | | - | |
1168 | | - | |
1169 | | - | |
1170 | | - | |
1171 | | - | |
1172 | | - | |
| 1181 | + | |
| 1182 | + | |
| 1183 | + | |
| 1184 | + | |
| 1185 | + | |
| 1186 | + | |
| 1187 | + | |
| 1188 | + | |
| 1189 | + | |
| 1190 | + | |
| 1191 | + | |
1173 | 1192 | | |
1174 | 1193 | | |
1175 | 1194 | | |
| |||
1363 | 1382 | | |
1364 | 1383 | | |
1365 | 1384 | | |
1366 | | - | |
| 1385 | + | |
1367 | 1386 | | |
1368 | 1387 | | |
1369 | 1388 | | |
| |||
0 commit comments