pnnx: support npy input tensors - #6700
Conversation
|
|
There was a problem hiding this comment.
Pull request overview
This PR adds first-class support for providing .npy files as example input tensors to pnnx, enabling conversions/tests to run with real tensor values (including non-native endianness and Fortran-ordered arrays) instead of synthetic/random inputs.
Changes:
- Add a
.npyloader (load_numpy_file) and plumbinput=/input2=CLI args through model loading and code generation. - Update TorchScript/TNN loading paths to accept inferred input shapes/types from
.npyand (for TorchScript) construct input tensors from the loaded payload. - Add new unit tests (TorchScript/ONNX/TNN) and register them in CMake.
Reviewed changes
Copilot reviewed 18 out of 18 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| tools/pnnx/tests/test_pnnx_input_npy.py | New TorchScript test covering .npy inputs (incl. endian + Fortran order) for multi-output model. |
| tools/pnnx/tests/test_pnnx_input_npy_input2.py | New TorchScript test covering input + input2 with two example input sets. |
| tools/pnnx/tests/test_pnnx_input_npy_int64.py | New TorchScript test covering int64 .npy inputs (e.g., gather indices). |
| tools/pnnx/tests/test_pnnx_input_npy_tnn.py | New TNN test covering .npy input for a minimal ReLU network. |
| tools/pnnx/tests/onnx/test_pnnx_input_npy.py | New ONNX test covering .npy inputs (incl. endian + Fortran order). |
| tools/pnnx/tests/onnx/CMakeLists.txt | Registers the new ONNX .npy input test. |
| tools/pnnx/tests/CMakeLists.txt | Registers new .npy input tests (including conditional TNN test). |
| tools/pnnx/src/utils.h | Introduces NumpyArray + load_numpy_file() declaration. |
| tools/pnnx/src/utils.cpp | Implements .npy parsing, dtype/shape handling, endian swap, and Fortran→C reordering. |
| tools/pnnx/src/save_ncnn.h | Extends save_ncnn() signature to accept input .npy paths. |
| tools/pnnx/src/save_ncnn.cpp | Emits Python that can load provided .npy inputs for generated ncnn inference wrappers. |
| tools/pnnx/src/main.cpp | Adds input/input2 CLI params, parses .npy inputs, and wires paths/contents into downstream stages. |
| tools/pnnx/src/load_torchscript.h | Extends load_torchscript() signature to accept raw input payloads. |
| tools/pnnx/src/load_torchscript.cpp | Creates Torch tensors from .npy payload bytes (with validation) and adds bool handling. |
| tools/pnnx/src/load_tnn.h | Extends load_tnn() signature to accept user-provided input shapes/types. |
| tools/pnnx/src/load_tnn.cpp | Validates/overrides TNN input shape/type based on provided .npy/inputshape. |
| tools/pnnx/src/ir.h | Extends Graph::python() signature to accept input .npy paths. |
| tools/pnnx/src/ir.cpp | Emits Python that can load provided .npy inputs for generated pnnx inference wrappers. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
15d9d13 to
2a79f50
Compare
|
@codex review |
|
Codex Review: Didn't find any major issues. Swish! ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
Co-authored-by: lovedream-ms <209071654+lovedream-ms@users.noreply.github.com> Co-authored-by: lancerstadium <57707690+lancerstadium@users.noreply.github.com> Co-authored-by: AtomAlpaca <66774326+AtomAlpaca@users.noreply.github.com>
No description provided.