Skip to content

Standalone PIR parser — decouple from libpaddle.so - #1651

Open
PlumBlossomMaid wants to merge 12 commits into
PaddlePaddle:developfrom
PlumBlossomMaid:standalone-pir-decouple-v3
Open

Standalone PIR parser — decouple from libpaddle.so#1651
PlumBlossomMaid wants to merge 12 commits into
PaddlePaddle:developfrom
PlumBlossomMaid:standalone-pir-decouple-v3

Conversation

@PlumBlossomMaid

Copy link
Copy Markdown

Summary

Decouple PaddlePaddle PIR model parser from libpaddle.so. PIR JSON format is entirely self-describing, so there is no need to link against the full framework.

Changes

New: paddle2onnx/pir/

  • Standalone JSON-backed PIR IR types (pir_program.h/cc) — Operation/Value/Attribute/Type/Program, zero paddle dependency
  • YAML-based op info tables (pir_op_info.h/cc + auto-generated pir_op_info_generated.h) — 529 ops with full input/output name-to-index mapping
  • Script gen_op_info.py to regenerate from versioned YAML data
  • Versioned ops.yaml + op_compat.yaml (v2.6, v3.0~v3.4)

Modified: paddle2onnx/parser/pir_parser.h/cc

  • Replaced all 19 #include "paddle/" with standalone types
  • Uses nlohmann/json for model deserialization instead of pir::ReadModule
  • Uses OpYamlInfoParser + OpNameNormalizer from generated YAML tables

Modified: 6 mapper files

  • exporter.cc, while.cc, builtin_combine.cc, builtin_split.cc, set_value.h
  • Removed all #include "paddle/" and PADDLE_ENFORCE macros

Build

  • CMakeLists.txt: removed libpaddle.so link, added nlohmann/json third_party
  • Verified: [100%] Built target paddle2onnx
  • Tested: PIR to ONNX conversion (conv2d+relu) produces valid ONNX model

- New standalone PIR IR types (paddle2onnx/pir/):
  - pir_program.h/cc: JSON-backed Operation, Value, Attribute, Type, Program
  - No dependency on libpaddle.so or any Paddle framework headers
  - DialectIdMap with version-aware op name decompression
  - Full value graph resolution (defining_op back-references)

- Modified pir_parser.h/cc to use standalone PIR types:
  - Removed #include "paddle/" dependencies
  - Replaced pi::ReadModule() with JSON parser
  - Replaced OpNameNormalizer/OpYamlInfoParser with simplified lookups
  - Replaced phi::DataType with local pir::DataType
  - Simplified GetOpAttr with Attribute::isa/dyn_cast

- CMakeLists.txt: removed libpaddle.so link, added nlohmann/json

- YAML files: extracted ops.yaml + op_compat.yaml for v2.6, v3.0-v3.4
  - Ready for version-aware op info lookup
  - Pre-generated C++ mappings can replace runtime YAML parsing

- third_party/nlohmann/json.hpp: header-only JSON parser

Tested via Python simulation - all PIR JSON parsing,
value graph resolution, attribute extraction verified.
- Remove #include "paddle/" from exporter.cc, builtin_combine.cc, while.cc
- Replace PADDLE_ENFORCE with std::runtime_error in set_value.h
- Replace op->dyn_cast<paddle::dialect::WhileOp>() with name-based access
- Replace op->dyn_cast<paddle::dialect::IfOp>() with name-based access
- Replace pir::SplitOp / pir::CombineOp with name checks + num_operands()
- All 6 mapper files now free of paddle framework symbols
- Add GetWhileInputValuesAndArgsMappings for standalone PIR types
- Remove protobuf from git tracking (build artifact)

Paddle2ONNX now has ZERO direct dependency on libpaddle.so for PIR parsing.
- Type::Parse: guard j["#"] and j["TT"] with is_string() before get<std::string>()
- ParseOp: guard op_j["#"] and op_j["op_type"] with is_string()
- Also apply clang-format to all touched files
- Remove paddlepaddle from pyproject.toml build-system requires
- Add conditional BUILD_PADDLE2ONNX_PYTHON in setup.py (ON if paddle importable)
- Fix manylinux entrypoint: use system protobuf (yum/dnf), remove paddle PIP_EXTRA_INDEX_URL
- Remove auditwheel --exclude libpaddle.so (no longer needed)
- Update manylinux Python version from 3.8 (unsupported) to 3.10
…/PADDLE_LIB refs

- CMakeLists.txt: remove pir_patch target, PADDLE_INCLUDE_DIR include path,
  PADDLE_LIB/COMMON_LIB link deps from cpp2py_export
- setup.py: revert to unconditional BUILD_PADDLE2ONNX_PYTHON=ON (no paddle
  needed at build time)
- pyproject.toml: no paddle build dependency (already done)
- entrypoint.sh: no paddle install, system protobuf, rm auditwheel exclude
- build_and_test.yml: Python 3.8 → 3.10 for manylinux_2_28 compat
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant