Skip to content

Commit

Permalink
PNNX is an open standard for PyTorch model interoperability (#3262)
Browse files Browse the repository at this point in the history
Co-authored-by: nihui <[email protected]>
Co-authored-by: xiaooquanwu <[email protected]>
  • Loading branch information
3 people authored Nov 22, 2021
1 parent 3644ded commit e4c821a
Show file tree
Hide file tree
Showing 622 changed files with 47,662 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/linux-x64-cpu-clang.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ on:
- 'src/layer/x86/**'
- 'tests/**'
- 'tools/**'
- '!tools/pnnx/**'
- 'examples/**'
pull_request:
branches: [master]
Expand All @@ -25,6 +26,7 @@ on:
- 'src/layer/x86/**'
- 'tests/**'
- 'tools/**'
- '!tools/pnnx/**'
- 'examples/**'
jobs:
linux-clang:
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/linux-x64-cpu-gcc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ on:
- 'src/layer/x86/**'
- 'tests/**'
- 'tools/**'
- '!tools/pnnx/**'
- 'examples/**'
pull_request:
branches: [master]
Expand All @@ -25,6 +26,7 @@ on:
- 'src/layer/x86/**'
- 'tests/**'
- 'tools/**'
- '!tools/pnnx/**'
- 'examples/**'
jobs:
linux-gcc:
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/linux-x64-gpu-clang.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ on:
- 'src/layer/vulkan/**'
- 'tests/**'
- 'tools/**'
- '!tools/pnnx/**'
- 'examples/**'
pull_request:
branches: [master]
Expand All @@ -25,6 +26,7 @@ on:
- 'src/layer/vulkan/**'
- 'tests/**'
- 'tools/**'
- '!tools/pnnx/**'
- 'examples/**'
jobs:
linux-clang-gpu:
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/linux-x64-gpu-gcc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ on:
- 'src/layer/vulkan/**'
- 'tests/**'
- 'tools/**'
- '!tools/pnnx/**'
- 'examples/**'
pull_request:
branches: [master]
Expand All @@ -25,6 +26,7 @@ on:
- 'src/layer/vulkan/**'
- 'tests/**'
- 'tools/**'
- '!tools/pnnx/**'
- 'examples/**'
jobs:
linux-gcc-gpu:
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/macos-x64-cpu.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ on:
- 'src/layer/x86/**'
- 'tests/**'
- 'tools/**'
- '!tools/pnnx/**'
- 'examples/**'
pull_request:
branches: [master]
Expand All @@ -23,6 +24,7 @@ on:
- 'src/layer/x86/**'
- 'tests/**'
- 'tools/**'
- '!tools/pnnx/**'
- 'examples/**'
env:
DEVELOPER_DIR: /Applications/Xcode_12.4.app/Contents/Developer
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/macos-x64-gpu.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ on:
- 'src/layer/vulkan/**'
- 'tests/**'
- 'tools/**'
- '!tools/pnnx/**'
- 'examples/**'
pull_request:
branches: [master]
Expand All @@ -25,6 +26,7 @@ on:
- 'src/layer/vulkan/**'
- 'tests/**'
- 'tools/**'
- '!tools/pnnx/**'
- 'examples/**'
env:
DEVELOPER_DIR: /Applications/Xcode_12.4.app/Contents/Developer
Expand Down
66 changes: 66 additions & 0 deletions .github/workflows/pnnx.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
name: pnnx
on:
push:
branches: [master]
paths:
- '.github/workflows/pnnx.yml'
- 'tools/pnnx/**'
- '!tools/pnnx/README.md'
pull_request:
branches: [master]
paths:
- '.github/workflows/pnnx.yml'
- 'tools/pnnx/**'
- '!tools/pnnx/README.md'
jobs:
ubuntu:
runs-on: ubuntu-20.04

strategy:
fail-fast: false
matrix:
include:
- torch-version: 1.8.1
torchvision-version: 0.9.1

- torch-version: 1.9.1
torchvision-version: 0.10.1

- torch-version: 1.10.0
torchvision-version: 0.11.1

steps:
- name: cancel-previous-runs
uses: styfle/[email protected]
with:
access_token: ${{ secrets.GITHUB_TOKEN }}

- name: setup pytorch-${{ matrix.torch-version }}
run: |
pip install torch==${{ matrix.torch-version }}+cpu torchvision==${{ matrix.torchvision-version }}+cpu -f https://download.pytorch.org/whl/torch_stable.html
- uses: actions/checkout@v2
with:
submodules: true

- name: build-ncnn
run: |
python -m pip install --upgrade pip
pip install pytest setuptools wheel twine
mkdir build && cd build
cmake -DCMAKE_BUILD_TYPE=Release -DNCNN_PYTHON=ON -DNCNN_BUILD_TOOLS=OFF -DNCNN_BUILD_EXAMPLES=OFF ..
cmake --build . -j 2
cd ..
pip install .
- name: build-pnnx
run: |
cd tools/pnnx
mkdir build && cd build
cmake -DTorch_INSTALL_DIR="$HOME/.local/lib/python3.8/site-packages/torch" -DCMAKE_BUILD_TYPE=Release ..
cmake --build . -j 2
- name: test
run: |
cd tools/pnnx
cd build && ctest --output-on-failure
2 changes: 2 additions & 0 deletions .github/workflows/windows-x64-cpu-vs2015.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ on:
- 'src/layer/x86/**'
- 'tests/**'
- 'tools/**'
- '!tools/pnnx/**'
- 'examples/**'
pull_request:
branches: [master]
Expand All @@ -23,6 +24,7 @@ on:
- 'src/layer/x86/**'
- 'tests/**'
- 'tools/**'
- '!tools/pnnx/**'
- 'examples/**'
jobs:
windows-vs2015:
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/windows-x64-cpu-vs2017.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ on:
- 'src/layer/x86/**'
- 'tests/**'
- 'tools/**'
- '!tools/pnnx/**'
- 'examples/**'
pull_request:
branches: [master]
Expand All @@ -23,6 +24,7 @@ on:
- 'src/layer/x86/**'
- 'tests/**'
- 'tools/**'
- '!tools/pnnx/**'
- 'examples/**'
jobs:
windows-vs2017:
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/windows-x64-cpu-vs2019.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ on:
- 'src/layer/x86/**'
- 'tests/**'
- 'tools/**'
- '!tools/pnnx/**'
- 'examples/**'
pull_request:
branches: [master]
Expand All @@ -23,6 +24,7 @@ on:
- 'src/layer/x86/**'
- 'tests/**'
- 'tools/**'
- '!tools/pnnx/**'
- 'examples/**'
jobs:
windows-vs2019:
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/windows-x64-gpu-vs2017.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ on:
- 'src/layer/vulkan/**'
- 'tests/**'
- 'tools/**'
- '!tools/pnnx/**'
- 'examples/**'
pull_request:
branches: [master]
Expand All @@ -25,6 +26,7 @@ on:
- 'src/layer/vulkan/**'
- 'tests/**'
- 'tools/**'
- '!tools/pnnx/**'
- 'examples/**'
jobs:
windows-vs2017-gpu:
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/windows-x64-gpu-vs2019.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ on:
- 'src/layer/vulkan/**'
- 'tests/**'
- 'tools/**'
- '!tools/pnnx/**'
- 'examples/**'
pull_request:
branches: [master]
Expand All @@ -25,6 +26,7 @@ on:
- 'src/layer/vulkan/**'
- 'tests/**'
- 'tools/**'
- '!tools/pnnx/**'
- 'examples/**'
jobs:
windows-vs2019-gpu:
Expand Down
44 changes: 44 additions & 0 deletions tools/pnnx/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
project(pnnx)
cmake_minimum_required(VERSION 3.10)

# c++14 is required for using torch headers
set(CMAKE_CXX_STANDARD 14)

#set(CMAKE_BUILD_TYPE debug)
#set(CMAKE_BUILD_TYPE relwithdebinfo)
#set(CMAKE_BUILD_TYPE release)

option(PNNX_COVERAGE "build for coverage" OFF)

#set(Torch_INSTALL_DIR "/home/nihui/.local/lib/python3.9/site-packages/torch" CACHE STRING "")
#set(Torch_INSTALL_DIR "/home/nihui/osd/pnnx/pytorch-v1.10.0/build/install" CACHE STRING "")
set(Torch_INSTALL_DIR "/home/nihui/osd/pnnx/libtorch" CACHE STRING "")
set(TorchVision_INSTALL_DIR "/home/nihui/osd/vision/build/install" CACHE STRING "")

set(Torch_DIR "${Torch_INSTALL_DIR}/share/cmake/Torch")
set(TorchVision_DIR "${TorchVision_INSTALL_DIR}/share/cmake/TorchVision")

find_package(Torch REQUIRED)
find_package(TorchVision QUIET)

message(STATUS "Torch_VERSION = ${Torch_VERSION}")
message(STATUS "Torch_VERSION_MAJOR = ${Torch_VERSION_MAJOR}")
message(STATUS "Torch_VERSION_MINOR = ${Torch_VERSION_MINOR}")
message(STATUS "Torch_VERSION_PATCH = ${Torch_VERSION_PATCH}")

if(Torch_VERSION VERSION_LESS "1.8")
message(FATAL_ERROR "pnnx only supports PyTorch >= 1.8")
endif()

if(TorchVision_FOUND)
message(STATUS "Building with TorchVision")
else()
message(WARNING "Building without TorchVision")
endif()

include_directories(${TORCH_INCLUDE_DIRS})

add_subdirectory(src)

enable_testing()
add_subdirectory(tests)
Loading

0 comments on commit e4c821a

Please sign in to comment.