Commit 5902263
authored
fix(jax): materialize default fparam in cxx api (deepmodeling#5849)
Closes deepmodeling#5658.
## Summary
- load and validate `get_default_fparam` when initializing a JAX
SavedModel in the C++ API
- materialize either caller-provided or stored frame parameters,
including one-frame-to-multiframe broadcasting, in both direct and
neighbor-list paths
- reject inconsistent tensor data/shape combinations, cast tensor rank
explicitly, and report TensorFlow C API allocation failure before
accessing tensor storage
- generate a JAX default-fparam fixture and extend the shared C++
regression matrix with default, distinct explicit override,
float/double, neighbor-list, multiframe, and invalid-size coverage
## Why existing tests missed this
The shared C++ default-fparam suite only included TorchScript and PT2
artifacts. Existing JAX C++ fixtures either had `dim_fparam == 0` or
supplied frame parameters explicitly, while Python JAX inference
materializes the saved default before invoking the model. Serialization
coverage therefore proved that the flag/getter were exported, but never
exercised C++ consumption of an omitted JAX `fparam`.
The explicit regression now uses `fparam=[0.5]`, distinct from the
stored default `[0.25852028]`, so it also detects an implementation that
ignores caller overrides.
## Validation
- `ruff format .`
- `ruff check .`
- `clang-format --dry-run --Werror` on all changed C++ files
- TensorFlow/JAX-only C++ build of `runUnitTests_cc` and
`deepmd_backend_jax`; both targets rebuilt successfully after the
allocation-safety follow-up
- 11 focused `DefaultFParamDeepPotTest` JAX SavedModel cases passed,
covering direct and neighbor-list inference, float/double, stored
defaults, distinct explicit overrides, two-frame broadcasting, metadata,
and invalid sizes
Coding agent: Codex
Codex version: codex-cli 0.144.4
Model: gpt-5.6-sol
Reasoning effort: xhigh
<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit
* **Bug Fixes**
* Hardened tensor creation with shape validation, overflow checks, and
safer zero-byte handling.
* Improved JAX frame-parameter behavior, including embedded model
defaults, stricter validation, and clear warnings when defaults are
unavailable.
* Added support for supplying per-frame or full-length frame-parameter
inputs, with broadcasting across frames.
* Ensures invalid frame-parameter sizes are rejected with better error
reporting.
* **Tests**
* Expanded JAX SavedModel test coverage for overrides, broadcasting, and
invalid input sizes.
* Updated/added generated JAX SavedModel artifacts and corresponding
expected reference outputs.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
---------
Co-authored-by: njzjz-bot <njzjz.bot@gmail.com>
Co-authored-by: njzjz-bot <njzjz-bot@users.noreply.github.com>1 parent 033a5ca commit 5902263
5 files changed
Lines changed: 249 additions & 10 deletions
File tree
- source
- api_cc
- include
- src
- tests
- tests/infer
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
276 | 276 | | |
277 | 277 | | |
278 | 278 | | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
279 | 283 | | |
280 | 284 | | |
281 | 285 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
12 | 12 | | |
13 | 13 | | |
14 | 14 | | |
| 15 | + | |
15 | 16 | | |
16 | 17 | | |
17 | 18 | | |
| |||
439 | 440 | | |
440 | 441 | | |
441 | 442 | | |
| 443 | + | |
| 444 | + | |
| 445 | + | |
| 446 | + | |
| 447 | + | |
| 448 | + | |
| 449 | + | |
| 450 | + | |
| 451 | + | |
| 452 | + | |
| 453 | + | |
| 454 | + | |
| 455 | + | |
| 456 | + | |
| 457 | + | |
| 458 | + | |
| 459 | + | |
| 460 | + | |
| 461 | + | |
| 462 | + | |
| 463 | + | |
| 464 | + | |
442 | 465 | | |
443 | | - | |
444 | | - | |
445 | | - | |
| 466 | + | |
| 467 | + | |
| 468 | + | |
| 469 | + | |
| 470 | + | |
| 471 | + | |
| 472 | + | |
| 473 | + | |
| 474 | + | |
446 | 475 | | |
447 | 476 | | |
448 | 477 | | |
| |||
509 | 538 | | |
510 | 539 | | |
511 | 540 | | |
| 541 | + | |
| 542 | + | |
| 543 | + | |
| 544 | + | |
| 545 | + | |
| 546 | + | |
| 547 | + | |
| 548 | + | |
| 549 | + | |
| 550 | + | |
| 551 | + | |
| 552 | + | |
| 553 | + | |
| 554 | + | |
| 555 | + | |
| 556 | + | |
| 557 | + | |
| 558 | + | |
| 559 | + | |
| 560 | + | |
| 561 | + | |
| 562 | + | |
| 563 | + | |
| 564 | + | |
| 565 | + | |
| 566 | + | |
| 567 | + | |
| 568 | + | |
| 569 | + | |
| 570 | + | |
| 571 | + | |
| 572 | + | |
| 573 | + | |
| 574 | + | |
| 575 | + | |
| 576 | + | |
| 577 | + | |
| 578 | + | |
| 579 | + | |
| 580 | + | |
| 581 | + | |
| 582 | + | |
| 583 | + | |
| 584 | + | |
| 585 | + | |
| 586 | + | |
| 587 | + | |
| 588 | + | |
| 589 | + | |
| 590 | + | |
| 591 | + | |
| 592 | + | |
| 593 | + | |
| 594 | + | |
512 | 595 | | |
513 | 596 | | |
514 | 597 | | |
| |||
675 | 758 | | |
676 | 759 | | |
677 | 760 | | |
| 761 | + | |
| 762 | + | |
| 763 | + | |
| 764 | + | |
| 765 | + | |
| 766 | + | |
| 767 | + | |
| 768 | + | |
| 769 | + | |
| 770 | + | |
| 771 | + | |
| 772 | + | |
| 773 | + | |
| 774 | + | |
| 775 | + | |
| 776 | + | |
| 777 | + | |
| 778 | + | |
| 779 | + | |
| 780 | + | |
| 781 | + | |
678 | 782 | | |
679 | 783 | | |
680 | 784 | | |
| |||
779 | 883 | | |
780 | 884 | | |
781 | 885 | | |
| 886 | + | |
| 887 | + | |
782 | 888 | | |
783 | 889 | | |
784 | 890 | | |
| |||
942 | 1048 | | |
943 | 1049 | | |
944 | 1050 | | |
| 1051 | + | |
| 1052 | + | |
945 | 1053 | | |
946 | 1054 | | |
947 | 1055 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
148 | 148 | | |
149 | 149 | | |
150 | 150 | | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
151 | 156 | | |
152 | 157 | | |
153 | 158 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
7 | 7 | | |
8 | 8 | | |
9 | 9 | | |
| 10 | + | |
10 | 11 | | |
11 | 12 | | |
12 | 13 | | |
| |||
359 | 360 | | |
360 | 361 | | |
361 | 362 | | |
| 363 | + | |
| 364 | + | |
| 365 | + | |
| 366 | + | |
362 | 367 | | |
363 | 368 | | |
364 | 369 | | |
| |||
532 | 537 | | |
533 | 538 | | |
534 | 539 | | |
| 540 | + | |
| 541 | + | |
535 | 542 | | |
536 | 543 | | |
537 | 544 | | |
| |||
543 | 550 | | |
544 | 551 | | |
545 | 552 | | |
| 553 | + | |
546 | 554 | | |
547 | 555 | | |
548 | 556 | | |
| |||
1918 | 1926 | | |
1919 | 1927 | | |
1920 | 1928 | | |
| 1929 | + | |
| 1930 | + | |
| 1931 | + | |
| 1932 | + | |
| 1933 | + | |
| 1934 | + | |
| 1935 | + | |
| 1936 | + | |
| 1937 | + | |
| 1938 | + | |
| 1939 | + | |
| 1940 | + | |
| 1941 | + | |
| 1942 | + | |
| 1943 | + | |
| 1944 | + | |
1921 | 1945 | | |
1922 | 1946 | | |
1923 | 1947 | | |
| |||
2007 | 2031 | | |
2008 | 2032 | | |
2009 | 2033 | | |
2010 | | - | |
2011 | | - | |
| 2034 | + | |
| 2035 | + | |
2012 | 2036 | | |
2013 | 2037 | | |
2014 | 2038 | | |
2015 | 2039 | | |
2016 | 2040 | | |
2017 | 2041 | | |
2018 | 2042 | | |
2019 | | - | |
2020 | | - | |
| 2043 | + | |
| 2044 | + | |
2021 | 2045 | | |
2022 | 2046 | | |
2023 | 2047 | | |
| |||
2034 | 2058 | | |
2035 | 2059 | | |
2036 | 2060 | | |
| 2061 | + | |
| 2062 | + | |
| 2063 | + | |
| 2064 | + | |
| 2065 | + | |
| 2066 | + | |
| 2067 | + | |
| 2068 | + | |
| 2069 | + | |
| 2070 | + | |
| 2071 | + | |
| 2072 | + | |
| 2073 | + | |
| 2074 | + | |
| 2075 | + | |
| 2076 | + | |
| 2077 | + | |
| 2078 | + | |
| 2079 | + | |
| 2080 | + | |
| 2081 | + | |
| 2082 | + | |
| 2083 | + | |
| 2084 | + | |
| 2085 | + | |
| 2086 | + | |
| 2087 | + | |
| 2088 | + | |
| 2089 | + | |
| 2090 | + | |
| 2091 | + | |
| 2092 | + | |
| 2093 | + | |
| 2094 | + | |
| 2095 | + | |
| 2096 | + | |
| 2097 | + | |
| 2098 | + | |
| 2099 | + | |
| 2100 | + | |
| 2101 | + | |
| 2102 | + | |
| 2103 | + | |
| 2104 | + | |
| 2105 | + | |
| 2106 | + | |
| 2107 | + | |
| 2108 | + | |
| 2109 | + | |
| 2110 | + | |
| 2111 | + | |
| 2112 | + | |
| 2113 | + | |
| 2114 | + | |
| 2115 | + | |
| 2116 | + | |
| 2117 | + | |
| 2118 | + | |
| 2119 | + | |
| 2120 | + | |
| 2121 | + | |
| 2122 | + | |
| 2123 | + | |
| 2124 | + | |
| 2125 | + | |
| 2126 | + | |
| 2127 | + | |
| 2128 | + | |
| 2129 | + | |
| 2130 | + | |
| 2131 | + | |
| 2132 | + | |
2037 | 2133 | | |
2038 | 2134 | | |
2039 | 2135 | | |
| |||
0 commit comments