Commit 6122d97
feat(pt_expt): add dp compress support for pt_expt backend (#5323)
## Summary
- Add model compression (embedding net tabulation) for the pt_expt
backend, matching the existing pt backend capability
- Compressed models replace embedding net forward passes with polynomial
lookup tables via C++ custom ops (`tabulate_fusion_se_*`), significantly
speeding up inference
- Support all compressible descriptors: `se_e2_a`, `se_r`, `se_t`,
`se_t_tebd`, `dpa1`, `se_atten_v2`, `dpa2` (hybrid delegates
automatically)
### Key changes
**Infrastructure:**
- `deepmd/pt_expt/utils/tabulate_ops.py` — Register
`torch.library.register_fake` for all 5 custom ops to enable
`torch.export`/`make_fx` tracing through compressed forward paths
- `deepmd/pt_expt/utils/tabulate.py` — `DPTabulate` subclass that
detects descriptor type via serialized data (avoids `isinstance` checks
against pt-specific classes)
- `deepmd/pt_expt/entrypoints/compress.py` — Entry point: load `.pte` →
deserialize → `enable_compression()` → re-export `.pte`
**Descriptors:** Each gets `enable_compression()` + `@cast_precision`
`call()` override with compressed branch using the appropriate custom
op.
**dpmodel — compression state serialization (breaking version bumps):**
The pt_expt backend persists models via `serialize()` → `model.json` →
`deserialize()` (the `.pte` format), unlike pt/tf which use native
framework save mechanisms (torch.jit.save / tf.saved_model) that capture
the full runtime state. This means compression state (tabulated
polynomial coefficients, precomputed type embeddings) must survive the
serialize/deserialize round-trip for compressed `.pte` models to work.
Each compressible descriptor's serialization version is bumped when the
model is compressed. **Uncompressed models continue to use the old
version**, so there is no breakage for existing uncompressed model
files. All backends (pt, pd, tf) accept the new version in
`deserialize()` and simply ignore the `"compress"` key.
| Descriptor | Version bump | Added fields |
|---|---|---|
| `se_e2_a` | 2 → 3 | `compress_data`, `compress_info` |
| `se_r` | 2 → 3 | `compress_data`, `compress_info` |
| `se_t` | 2 → 3 | `compress_data`, `compress_info` |
| `se_t_tebd` | 1 → 2 | `compress_data`, `compress_info`,
`type_embd_data` |
| `dpa1` | 2 → 3 | `type_embd_data`, `geo_compress`,
`compress_data`/`info` (if geo) |
| `se_atten_v2` | 2 → 3 | `type_embd_data`, `geo_compress`,
`compress_data`/`info` (if geo) |
| `dpa2` | 3 → 4 | compress dict inside `repinit_variable` |
**dpmodel:** Initialize `self.compress = False` in all descriptor
`__init__` methods.
## Test plan
- [x] `source/tests/pt_expt/model/test_model_compression.py` —
end-to-end compress → serialize → deserialize → eval
- [x] `source/tests/pt_expt/descriptor/` — compressed forward,
consistency, exportable, make_fx tests for all descriptors
- [x] `source/tests/consistent/descriptor/` — cross-backend consistency
tests pass with bumped versions
<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit
* **New Features**
* Added descriptor compression functionality to reduce model size and
optimize memory usage during inference.
* Introduced `compress` CLI command to enable tabulated embedding
optimization on frozen trained models.
* Enhanced descriptor serialization with improved version compatibility
across multiple backends.
* **Tests**
* Added comprehensive test coverage for compressed descriptor forward
passes and model compression workflows.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
---------
Co-authored-by: Han Wang <wang_han@iapcm.ac.cn>1 parent b97ad98 commit 6122d97
46 files changed
Lines changed: 2706 additions & 35 deletions
File tree
- deepmd
- dpmodel/descriptor
- pd/model/descriptor
- pt_expt
- descriptor
- entrypoints
- model
- utils
- pt/model/descriptor
- tf/descriptor
- source/tests/pt_expt
- descriptor
- model
Some content is hidden
Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
344 | 344 | | |
345 | 345 | | |
346 | 346 | | |
| 347 | + | |
347 | 348 | | |
348 | 349 | | |
349 | 350 | | |
| |||
557 | 558 | | |
558 | 559 | | |
559 | 560 | | |
560 | | - | |
| 561 | + | |
561 | 562 | | |
562 | 563 | | |
563 | 564 | | |
| |||
602 | 603 | | |
603 | 604 | | |
604 | 605 | | |
| 606 | + | |
| 607 | + | |
| 608 | + | |
| 609 | + | |
| 610 | + | |
| 611 | + | |
| 612 | + | |
| 613 | + | |
| 614 | + | |
| 615 | + | |
| 616 | + | |
| 617 | + | |
| 618 | + | |
| 619 | + | |
| 620 | + | |
605 | 621 | | |
606 | 622 | | |
607 | 623 | | |
608 | 624 | | |
609 | 625 | | |
610 | 626 | | |
611 | | - | |
| 627 | + | |
612 | 628 | | |
613 | 629 | | |
614 | 630 | | |
615 | 631 | | |
616 | 632 | | |
617 | 633 | | |
618 | 634 | | |
| 635 | + | |
619 | 636 | | |
620 | 637 | | |
621 | 638 | | |
| |||
637 | 654 | | |
638 | 655 | | |
639 | 656 | | |
| 657 | + | |
| 658 | + | |
640 | 659 | | |
641 | 660 | | |
| 661 | + | |
| 662 | + | |
| 663 | + | |
| 664 | + | |
| 665 | + | |
| 666 | + | |
| 667 | + | |
| 668 | + | |
| 669 | + | |
| 670 | + | |
642 | 671 | | |
643 | 672 | | |
644 | 673 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
596 | 596 | | |
597 | 597 | | |
598 | 598 | | |
| 599 | + | |
599 | 600 | | |
600 | 601 | | |
601 | 602 | | |
| |||
938 | 939 | | |
939 | 940 | | |
940 | 941 | | |
941 | | - | |
| 942 | + | |
942 | 943 | | |
943 | 944 | | |
944 | 945 | | |
| |||
973 | 974 | | |
974 | 975 | | |
975 | 976 | | |
| 977 | + | |
| 978 | + | |
| 979 | + | |
| 980 | + | |
| 981 | + | |
| 982 | + | |
| 983 | + | |
| 984 | + | |
| 985 | + | |
| 986 | + | |
| 987 | + | |
| 988 | + | |
| 989 | + | |
| 990 | + | |
| 991 | + | |
976 | 992 | | |
977 | 993 | | |
978 | 994 | | |
| |||
1016 | 1032 | | |
1017 | 1033 | | |
1018 | 1034 | | |
1019 | | - | |
| 1035 | + | |
1020 | 1036 | | |
1021 | 1037 | | |
1022 | 1038 | | |
| |||
1040 | 1056 | | |
1041 | 1057 | | |
1042 | 1058 | | |
| 1059 | + | |
1043 | 1060 | | |
1044 | 1061 | | |
1045 | 1062 | | |
| |||
1089 | 1106 | | |
1090 | 1107 | | |
1091 | 1108 | | |
| 1109 | + | |
| 1110 | + | |
1092 | 1111 | | |
1093 | 1112 | | |
| 1113 | + | |
| 1114 | + | |
| 1115 | + | |
| 1116 | + | |
| 1117 | + | |
| 1118 | + | |
| 1119 | + | |
| 1120 | + | |
| 1121 | + | |
| 1122 | + | |
1094 | 1123 | | |
1095 | 1124 | | |
1096 | 1125 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
196 | 196 | | |
197 | 197 | | |
198 | 198 | | |
| 199 | + | |
199 | 200 | | |
200 | 201 | | |
201 | 202 | | |
202 | 203 | | |
203 | 204 | | |
204 | 205 | | |
205 | 206 | | |
206 | | - | |
| 207 | + | |
207 | 208 | | |
208 | 209 | | |
209 | 210 | | |
| |||
245 | 246 | | |
246 | 247 | | |
247 | 248 | | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
248 | 264 | | |
249 | 265 | | |
250 | 266 | | |
251 | 267 | | |
252 | 268 | | |
253 | 269 | | |
254 | | - | |
| 270 | + | |
255 | 271 | | |
256 | 272 | | |
257 | 273 | | |
| |||
260 | 276 | | |
261 | 277 | | |
262 | 278 | | |
| 279 | + | |
263 | 280 | | |
264 | 281 | | |
265 | 282 | | |
| |||
273 | 290 | | |
274 | 291 | | |
275 | 292 | | |
| 293 | + | |
| 294 | + | |
276 | 295 | | |
| 296 | + | |
| 297 | + | |
| 298 | + | |
| 299 | + | |
| 300 | + | |
| 301 | + | |
| 302 | + | |
| 303 | + | |
| 304 | + | |
| 305 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
192 | 192 | | |
193 | 193 | | |
194 | 194 | | |
| 195 | + | |
195 | 196 | | |
196 | 197 | | |
197 | 198 | | |
| |||
514 | 515 | | |
515 | 516 | | |
516 | 517 | | |
517 | | - | |
| 518 | + | |
| 519 | + | |
| 520 | + | |
| 521 | + | |
| 522 | + | |
| 523 | + | |
| 524 | + | |
| 525 | + | |
| 526 | + | |
| 527 | + | |
| 528 | + | |
| 529 | + | |
| 530 | + | |
| 531 | + | |
| 532 | + | |
518 | 533 | | |
519 | 534 | | |
520 | | - | |
| 535 | + | |
521 | 536 | | |
522 | 537 | | |
523 | 538 | | |
| |||
541 | 556 | | |
542 | 557 | | |
543 | 558 | | |
| 559 | + | |
| 560 | + | |
| 561 | + | |
| 562 | + | |
| 563 | + | |
| 564 | + | |
| 565 | + | |
| 566 | + | |
544 | 567 | | |
545 | 568 | | |
546 | 569 | | |
547 | 570 | | |
548 | 571 | | |
549 | | - | |
| 572 | + | |
550 | 573 | | |
551 | 574 | | |
552 | 575 | | |
553 | 576 | | |
554 | 577 | | |
| 578 | + | |
555 | 579 | | |
556 | 580 | | |
557 | 581 | | |
558 | 582 | | |
559 | 583 | | |
| 584 | + | |
| 585 | + | |
560 | 586 | | |
561 | 587 | | |
| 588 | + | |
| 589 | + | |
| 590 | + | |
| 591 | + | |
| 592 | + | |
| 593 | + | |
| 594 | + | |
| 595 | + | |
| 596 | + | |
| 597 | + | |
| 598 | + | |
| 599 | + | |
| 600 | + | |
| 601 | + | |
| 602 | + | |
562 | 603 | | |
563 | 604 | | |
564 | 605 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
173 | 173 | | |
174 | 174 | | |
175 | 175 | | |
| 176 | + | |
176 | 177 | | |
177 | 178 | | |
178 | 179 | | |
| |||
438 | 439 | | |
439 | 440 | | |
440 | 441 | | |
441 | | - | |
| 442 | + | |
442 | 443 | | |
443 | 444 | | |
444 | | - | |
| 445 | + | |
445 | 446 | | |
446 | 447 | | |
447 | 448 | | |
| |||
464 | 465 | | |
465 | 466 | | |
466 | 467 | | |
| 468 | + | |
| 469 | + | |
| 470 | + | |
| 471 | + | |
| 472 | + | |
| 473 | + | |
| 474 | + | |
| 475 | + | |
467 | 476 | | |
468 | 477 | | |
469 | 478 | | |
470 | 479 | | |
471 | 480 | | |
472 | | - | |
| 481 | + | |
473 | 482 | | |
474 | 483 | | |
475 | 484 | | |
476 | 485 | | |
477 | 486 | | |
| 487 | + | |
478 | 488 | | |
479 | 489 | | |
480 | 490 | | |
481 | 491 | | |
482 | 492 | | |
| 493 | + | |
| 494 | + | |
483 | 495 | | |
484 | 496 | | |
| 497 | + | |
| 498 | + | |
| 499 | + | |
| 500 | + | |
| 501 | + | |
| 502 | + | |
| 503 | + | |
485 | 504 | | |
486 | 505 | | |
487 | 506 | | |
| |||
0 commit comments