Commit ea80517
fix(pd): preserve fparam/aparam inputs when freezing models (#5713)
## Problem
The Paddle freeze entrypoint
(`deepmd/pd/utils/serialization.py::deserialize_to_file`) converts
`model.forward` and `model.forward_lower` to static graphs with `fparam`
and `aparam` hardcoded to `None` in the `input_spec`. For models trained
with required frame parameters (`get_dim_fparam() > 0`) or atomic
parameters (`get_dim_aparam() > 0`), the exported static signature
therefore bakes both values as `None`, so inference through the frozen
Paddle model cannot supply the required `fparam`/`aparam`.
## Fix
Build the `fparam`/`aparam` `InputSpec` from the model's
`get_dim_fparam()`/`get_dim_aparam()` — a spec with shape `[-1,
dim_fparam]` / `[-1, -1, dim_aparam]` when the dim is nonzero, and
`None` otherwise — and use it in both the `forward` and `forward_lower`
static signatures. Models that do not use these inputs keep the `None`
placeholders as before.
## Test
`source/tests/pd/model/test_serialization_fparam.py` covers the spec
builder for the unused case (both `None`), the used case (correct shapes
and names), and the fparam-only case.
## Note on verification
Verified locally with `paddlepaddle==3.3.1`. The spec-builder test is
version-independent; the end-to-end `paddle.jit.save` export (heavier
and sensitive to the exact Paddle build) remains covered by CI's pinned
nightly (`paddlepaddle==3.4.0.dev20260310`).
Fix #5687
<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit
* **Bug Fixes**
* Improved static export so optional input parameters are included only
when a model actually uses them.
* Reduced export issues by avoiding unnecessary placeholder inputs when
these parameters are not needed.
* **Tests**
* Added coverage for export input signatures to confirm optional
parameters are omitted, included, or partially included as expected
based on model settings.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
Co-authored-by: Han Wang <wang_han@iapcm.ac.cn>1 parent 2b6cd22 commit ea80517
2 files changed
Lines changed: 74 additions & 4 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
23 | 23 | | |
24 | 24 | | |
25 | 25 | | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
26 | 52 | | |
27 | 53 | | |
28 | 54 | | |
| |||
57 | 83 | | |
58 | 84 | | |
59 | 85 | | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
60 | 89 | | |
61 | 90 | | |
62 | 91 | | |
| |||
72 | 101 | | |
73 | 102 | | |
74 | 103 | | |
75 | | - | |
76 | | - | |
| 104 | + | |
| 105 | + | |
77 | 106 | | |
78 | 107 | | |
79 | 108 | | |
| |||
92 | 121 | | |
93 | 122 | | |
94 | 123 | | |
95 | | - | |
96 | | - | |
| 124 | + | |
| 125 | + | |
97 | 126 | | |
98 | 127 | | |
99 | 128 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
0 commit comments