Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
22 changes: 22 additions & 0 deletions .ai-rulez/config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
$schema: https://raw.githubusercontent.com/Goldziher/ai-rulez/main/schema/ai-rules-v3.schema.json
description: Convert PaddlePaddle models to ONNX format
gitignore: true
name: Paddle2ONNX

builtins:
- python
- security
- git-workflow
- code-quality
- testing
- token-efficiency
- default-commands

presets:
- claude
- gemini
- codex

compression:
level: moderate
version: "3.0"
104 changes: 21 additions & 83 deletions .github/workflows/build_and_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,13 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: [ '3.8']
architecture: [ 'x86_64']
python-version: [ '3.13' ]
steps:
# Checkout the latest branch of Paddle2ONNX.
- name: Checkout Paddle2ONNX
uses: actions/checkout@v4
with:
submodules: true
fetch-depth: 1000
# Merge base branch

- name: Merge base branch
if: ${{ github.event_name == 'pull_request' }}
run: |
Expand All @@ -38,38 +35,30 @@ jobs:
entrypoint: bash
args: .github/workflows/scripts/entrypoint.sh ${{ matrix.python-version }}

- name: Setup Python 3.8
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: '3.8'
python-version: ${{ matrix.python-version }}

# Install Paddle2ONNX
- name: Install Paddle2ONNX
run: |
python -m pip install dist/*.whl
run: python -m pip install dist/*.whl

# Install Test
- name: Run Test
working-directory: ./tests
run: |
bash run.sh python
run: bash run.sh python

build_on_windows:
runs-on: windows-2019
runs-on: windows-2022
strategy:
matrix:
python-version: [ '3.10' ]
python-version: [ '3.13' ]
architecture: [ 'x64' ]

steps:
# Checkout the latest branch of Paddle2ONNX.
- name: Checkout Paddle2ONNX
uses: actions/checkout@v4
with:
submodules: true
fetch-depth: 1000

# Merge base branch
- name: Merge base branch
if: ${{ github.event_name == 'pull_request' }}
run: |
Expand All @@ -78,71 +67,44 @@ jobs:
git fetch origin ${{ github.event.pull_request.base.ref }}
git merge origin/${{ github.event.pull_request.base.ref }}

# Clone protobuf repository and checkout to v21.12
- name: Clone protobuf
- name: Install C++ dependencies via vcpkg
run: |
git clone https://github.com/protocolbuffers/protobuf.git
cd protobuf
git checkout v21.12
vcpkg install protobuf:x64-windows pybind11:x64-windows glog:x64-windows
echo "CMAKE_TOOLCHAIN_FILE=$env:VCPKG_INSTALLATION_ROOT\scripts\buildsystems\vcpkg.cmake" >> $env:GITHUB_ENV

# Build and install protobuf
- name: Build and install protobuf
run: |
cd protobuf
git submodule update --init --recursive
mkdir build
cd build
cmake -G "Visual Studio 16 2019" -DCMAKE_INSTALL_PREFIX=${{ github.workspace }}\protobuf\protobuf_install\ -Dprotobuf_MSVC_STATIC_RUNTIME=OFF -Dprotobuf_BUILD_SHARED_LIBS=OFF -Dprotobuf_BUILD_TESTS=OFF -Dprotobuf_BUILD_EXAMPLES=OFF ..
cmake --build . --config Release --target install

# Setup Python
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}

# Install Python dependencies
- name: Install Python dependencies
run: |
python -m pip install -q --upgrade pip
python -m pip install setuptools wheel auditwheel auditwheel-symbols build
run: python -m pip install -q --upgrade pip setuptools wheel build

# Build package
- name: Build package
run: |
$Env:PATH = "${{ github.workspace }}\protobuf\protobuf_install\bin;" + $Env:PATH
$Env:PIP_EXTRA_INDEX_URL="https://www.paddlepaddle.org.cn/packages/nightly/cpu/"
python -m build --wheel

# Install Paddle2ONNX
- name: Install Paddle2ONNX
run: |
Get-ChildItem -Path dist/*.whl | foreach {python -m pip install --upgrade $_.fullname}
run: Get-ChildItem -Path dist/*.whl | foreach {python -m pip install --upgrade $_.fullname}

# Install Test
- name: Run Test
working-directory: ./tests
run: |
.\run.bat python
run: .\run.bat python

build_on_macos:
# Use MACOSX_DEPLOYMENT_TARGET=12.0 to produce compatible wheel
env:
MACOSX_DEPLOYMENT_TARGET: "12.0"
runs-on: macos-latest
strategy:
matrix:
python-version: [ '3.8']
architecture: [ 'arm64' ]
python-version: [ '3.13' ]
steps:
# Checkout the latest branch of Paddle2ONNX.
- name: Checkout Paddle2ONNX
uses: actions/checkout@v4
with:
submodules: true
fetch-depth: 1000

# Merge base branch
- name: Merge base branch
if: ${{ github.event_name == 'pull_request' }}
run: |
Expand All @@ -151,49 +113,25 @@ jobs:
git fetch origin ${{ github.event.pull_request.base.ref }}
git merge origin/${{ github.event.pull_request.base.ref }}

# Setup Python
- name: Install system dependencies
run: brew install protobuf glog pybind11

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}

# Clone protobuf repository and checkout to v21.12
- name: Clone protobuf
run: |
git clone https://github.com/protocolbuffers/protobuf.git
cd protobuf
git checkout v21.12

# Build and install protobuf
- name: Build and install protobuf
run: |
cd protobuf
git submodule update --init --recursive
mkdir build
cd build
cmake ../cmake -DCMAKE_INSTALL_PREFIX=${{ github.workspace }}/installed_protobuf -Dprotobuf_BUILD_SHARED_LIBS=OFF -DCMAKE_POSITION_INDEPENDENT_CODE=ON -Dprotobuf_BUILD_TESTS=OFF -DCMAKE_BUILD_TYPE=Release -DCMAKE_CXX_STANDARD=14
cmake --build . --target install

# Install Python dependencies
- name: Install Python dependencies
run: |
python -m pip install -q --upgrade pip
python -m pip install setuptools wheel build
run: python -m pip install -q --upgrade pip setuptools wheel build

# Build package
- name: Build package
run: |
export PATH="${{ github.workspace }}/installed_protobuf/bin:$PATH"
export PIP_EXTRA_INDEX_URL="https://www.paddlepaddle.org.cn/packages/nightly/cpu/"
python -m build --wheel

# Install Paddle2ONNX
- name: Install Paddle2ONNX
run: |
python -m pip install dist/*.whl
run: python -m pip install dist/*.whl

# Install Test
- name: Run Test
working-directory: ./tests
run: |
bash run.sh python
run: bash run.sh python
34 changes: 5 additions & 29 deletions .github/workflows/code_style_check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,38 +8,14 @@ jobs:
pre-commit:
name: pre-commit
runs-on: ubuntu-latest
env:
PR_ID: ${{ github.event.pull_request.number }}
BRANCH: develop

steps:
- name: Checkout Base Branch
- name: Checkout
uses: actions/checkout@v4
with:
ref: ${{ github.event.pull_request.base.ref }}
fetch-depth: 1000

- name: Merge PR
run: |
git config --global user.name "Paddle2onnxCI"
git config --global user.email "Paddle2onnxCI@example.com"
git fetch origin pull/${PR_ID}/merge
git checkout -b test FETCH_HEAD

- name: Setup Python3.12
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.12'
cache: 'pip'

- name: Install Dependencies
run: |
pip install pre-commit==2.17.0 cpplint==1.6.0 clang-format==13.0.0
python-version: '3.13'

- name: Run Pre-commit
env:
SKIP_CLANG_TIDY_CHECK: "ON"
run: |
set +e
bash -x tools/codestyle/pre_commit.sh;EXCODE=$?
exit $EXCODE
- name: Run pre-commit
uses: pre-commit/action@v3.0.1
49 changes: 22 additions & 27 deletions .github/workflows/scripts/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,52 +14,47 @@
# See the License for the specific language governing permissions and
# limitations under the License.

# Copyright (c) ONNX Project Contributors
#
# SPDX-License-Identifier: Apache-2.0

set -e -x

# CLI arguments
PY_VERSION=$1
PLAT=$2
SYSTEM_NAME=$3

export LD_LIBRARY_PATH=${LD_LIBRARY_PATH}:/usr/local/lib

# Compile wheels
# Need to be updated if there is a new Python Version
declare -A python_map=( ["3.8"]="cp38-cp38" ["3.9"]="cp39-cp39" ["3.10"]="cp310-cp310" ["3.11"]="cp311-cp311" ["3.12"]="cp312-cp312")
# Map Python version to manylinux path
declare -A python_map=( ["3.10"]="cp310-cp310" ["3.11"]="cp311-cp311" ["3.12"]="cp312-cp312" ["3.13"]="cp313-cp313" ["3.14"]="cp314-cp314")
PY_VER=${python_map[$PY_VERSION]}
PIP_INSTALL_COMMAND="/opt/python/${PY_VER}/bin/pip install --no-cache-dir -q"
PYTHON_COMMAND="/opt/python/${PY_VER}/bin/python"

# Update pip and install cmake
# Update pip and install build tools
$PIP_INSTALL_COMMAND --upgrade pip
$PIP_INSTALL_COMMAND cmake
$PIP_INSTALL_COMMAND cmake setuptools wheel build pybind11

# Build and install protobuf
original_dir=$(pwd)
git clone https://github.com/protocolbuffers/protobuf.git
cd protobuf
git checkout v21.12
git submodule update --init
mkdir build_source && cd build_source
cmake ../cmake -DCMAKE_INSTALL_PREFIX=`pwd`/installed_protobuf_lib -Dprotobuf_BUILD_SHARED_LIBS=OFF -DCMAKE_POSITION_INDEPENDENT_CODE=ON -Dprotobuf_BUILD_TESTS=OFF -DCMAKE_BUILD_TYPE=Release
cmake --build . --target install
export PATH=`pwd`/installed_protobuf_lib/bin:${PATH}
cd $original_dir
# Install system protobuf (CONFIG mode compatible)
yum install -y protobuf-devel protobuf-compiler glog-devel 2>/dev/null || {
# Fallback: build protobuf from source if yum packages unavailable
original_dir=$(pwd)
git clone --depth 1 --branch v28.3 https://github.com/protocolbuffers/protobuf.git /tmp/protobuf
cd /tmp/protobuf
git submodule update --init --recursive
mkdir build && cd build
cmake .. -DCMAKE_INSTALL_PREFIX=/usr/local \
-Dprotobuf_BUILD_SHARED_LIBS=OFF \
-DCMAKE_POSITION_INDEPENDENT_CODE=ON \
-Dprotobuf_BUILD_TESTS=OFF \
-DCMAKE_BUILD_TYPE=Release \
-Dprotobuf_ABSL_PROVIDER=module
cmake --build . --target install -j$(nproc)
cd $original_dir
}

export PIP_EXTRA_INDEX_URL="https://www.paddlepaddle.org.cn/packages/nightly/cpu/"

# Build Paddle2ONNX wheels
$PYTHON_COMMAND -m build --wheel || { echo "Building wheels failed."; exit 1; }

# ============================================================================
# Due to libpaddle’s limitations, it can only maintain a restricted platform tag of ‘linux_x86_64’.
# ============================================================================
# Bundle external shared libraries into the wheels
# find -exec does not preserve failed exit codes, so use an output file for failures
failed_wheels=$PWD/failed-wheels
rm -f "$failed_wheels"
find . -type f -iname "*-linux*.whl" -exec sh -c "auditwheel repair '{}' -w \$(dirname '{}') --exclude libpaddle.so || { echo 'Repairing wheels failed.'; auditwheel show '{}' >> '$failed_wheels'; }" \;
Expand All @@ -73,5 +68,5 @@ fi
# Remove useless *-linux*.whl; only keep manylinux*.whl
rm -f dist/*-linux*.whl

echo "Successfully build wheels:"
echo "Successfully built wheels:"
find . -type f -iname "*manylinux*.whl"
7 changes: 7 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,13 @@ paddle2onnx/*.so
paddle2onnx/__pycache_*
protobuf-*

# Python / uv
.venv
__pycache__/
*.egg-info/
.hypothesis/
/paddle

# Temporary files automatically generated when executing Paddle2ONNX unit tests
*.pdmodel
*.pdiparams
Expand Down
15 changes: 0 additions & 15 deletions .gitmodules

This file was deleted.

Loading