mirror of
https://github.com/saymrwulf/onnxruntime.git
synced 2026-07-03 03:58:54 +00:00
Auto deploy API docs (#15088)
This commit is contained in:
parent
44ba23e0f5
commit
28f64066de
7 changed files with 204 additions and 190 deletions
42
.github/workflows/publish-c-apidocs.yml
vendored
42
.github/workflows/publish-c-apidocs.yml
vendored
|
|
@ -1,15 +1,25 @@
|
|||
name: Update C/C++ API Docs
|
||||
|
||||
# Run when the C API changes or every month so that the artifact does not expire
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- main
|
||||
paths:
|
||||
- include/onnxruntime/core/session
|
||||
|
||||
schedule:
|
||||
- cron: '0 0 1 * *'
|
||||
workflow_dispatch:
|
||||
|
||||
concurrency:
|
||||
group: "apidocs-c"
|
||||
cancel-in-progress: false
|
||||
|
||||
permissions:
|
||||
contents: write
|
||||
|
||||
jobs:
|
||||
publish:
|
||||
build:
|
||||
name: Generate C/C++ API docs
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
|
|
@ -21,27 +31,21 @@ jobs:
|
|||
sudo apt-get install libclang-cpp14
|
||||
wget https://www.doxygen.nl/files/doxygen-1.9.6.linux.bin.tar.gz
|
||||
tar xvzf doxygen-1.9.6.linux.bin.tar.gz
|
||||
- name: Set commit ID
|
||||
id: vars
|
||||
run: echo "::set-output name=sha_short::$(git rev-parse --short HEAD)"
|
||||
- name: Run doxygen
|
||||
run: |
|
||||
mkdir -p build/doxygen
|
||||
cd docs/c_cxx
|
||||
../../doxygen-1.9.6/bin/doxygen
|
||||
- uses: actions/checkout@v2
|
||||
with:
|
||||
ref: gh-pages
|
||||
clean: false
|
||||
- name: Move API docs into target area
|
||||
- name: Log source commit
|
||||
run: git rev-parse --short HEAD > build/doxygen/html/source-version.txt
|
||||
- name: Move C/C++ docs into site
|
||||
run: |
|
||||
rm -rf docs/api/c
|
||||
mv build/doxygen/html docs/api/c
|
||||
- name: Create Pull Request
|
||||
uses: peter-evans/create-pull-request@v3
|
||||
mkdir -p _site/docs/api
|
||||
rm -rf site/docs/api/c
|
||||
mv build/doxygen/html _site/docs/api/c
|
||||
- name: Upload new site
|
||||
uses: actions/upload-artifact@v3
|
||||
with:
|
||||
branch: gh-pages-pr-c-docs
|
||||
base: gh-pages
|
||||
title: '[Automated]: Update C/C++ API docs'
|
||||
commit-message: 'Update C/C++ API docs to commit ${{ steps.vars.outputs.sha_short }}'
|
||||
add-paths: docs/api/c
|
||||
name: onnxruntime-c-apidocs
|
||||
path: _site
|
||||
retention-days: 60
|
||||
|
|
|
|||
65
.github/workflows/publish-csharp-apidocs.yml
vendored
65
.github/workflows/publish-csharp-apidocs.yml
vendored
|
|
@ -1,11 +1,28 @@
|
|||
name: Update C# API Docs
|
||||
|
||||
# Run when the C# API changes or every month so that the artifact does not expire
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- main
|
||||
paths:
|
||||
- csharp
|
||||
schedule:
|
||||
- cron: '0 0 1 * *'
|
||||
workflow_dispatch:
|
||||
|
||||
concurrency:
|
||||
group: "apidocs-csharp"
|
||||
cancel-in-progress: false
|
||||
|
||||
permissions:
|
||||
contents: write
|
||||
|
||||
jobs:
|
||||
publish:
|
||||
runs-on: windows-latest
|
||||
build:
|
||||
runs-on: ubuntu-latest
|
||||
env:
|
||||
DOCFXVERSION: 2.62.2
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- name: Setup .NET
|
||||
|
|
@ -17,39 +34,25 @@ jobs:
|
|||
- name: Download DocFX
|
||||
run: |
|
||||
mkdir -p build/docfx
|
||||
Invoke-WebRequest -Uri "https://github.com/dotnet/docfx/releases/download/v${env:DOCFXVERSION}/docfx.zip" -OutFile "build/docfx/docfx.zip"
|
||||
[System.IO.Compression.ZipFile]::ExtractToDirectory("build/docfx/docfx.zip", "build/docfx" )
|
||||
cd build/docfx
|
||||
ls
|
||||
env:
|
||||
DOCFXVERSION: 2.59.3
|
||||
wget https://github.com/dotnet/docfx/releases/download/v${DOCFXVERSION}/docfx-linux-x64-v${DOCFXVERSION}.zip -O build/docfx/docfx.zip
|
||||
unzip build/docfx/docfx.zip -d build/docfx
|
||||
- name: Install NuGet
|
||||
uses: nuget/setup-nuget@v1
|
||||
- name: Build Documentation
|
||||
run: |
|
||||
ls
|
||||
build/docfx/docfx.exe metadata csharp/ApiDocs/docfx.json
|
||||
build/docfx/docfx metadata csharp/ApiDocs/docfx.json
|
||||
dotnet build csharp/ApiDocs/ApiDocs.csproj --no-restore
|
||||
build/docfx/docfx.exe build csharp/ApiDocs/docfx.json
|
||||
- name: Set commit ID
|
||||
id: vars
|
||||
run: echo "::set-output name=sha_short::$(git rev-parse --short HEAD)"
|
||||
- uses: actions/checkout@v2
|
||||
with:
|
||||
ref: gh-pages
|
||||
clean: false
|
||||
- name: Move API docs into target area
|
||||
build/docfx/docfx build csharp/ApiDocs/docfx.json
|
||||
- name: Log source commit
|
||||
run: git rev-parse --short HEAD > csharp/ApiDocs/csharp/source-version.txt
|
||||
- name: Move C# docs into site
|
||||
run: |
|
||||
if (Test-Path -Path docs/api/csharp) {rm -r -fo docs/api/csharp}
|
||||
MOVE csharp/ApiDocs/csharp docs/api
|
||||
rm -r -fo csharp/ApiDocs
|
||||
rm -r -fo csharp/src
|
||||
- name: Git Checkin
|
||||
run: git add .
|
||||
- name: Create Pull Request
|
||||
uses: peter-evans/create-pull-request@v3
|
||||
mkdir -p _site/docs/api
|
||||
rm -rf _site/docs/api/csharp
|
||||
mv csharp/ApiDocs/csharp _site/docs/api/csharp
|
||||
- name: Upload docs artifact
|
||||
uses: actions/upload-artifact@v3
|
||||
with:
|
||||
branch: gh-pages-pr-csharp-docs
|
||||
base: gh-pages
|
||||
title: '[Automated]: Update C# API docs'
|
||||
commit-message: 'Update C# API docs to commit ${{ steps.vars.outputs.sha_short }}'
|
||||
name: onnxruntime-csharp-apidocs
|
||||
path: _site
|
||||
retention-days: 60
|
||||
|
|
|
|||
101
.github/workflows/publish-gh-pages.yml
vendored
Normal file
101
.github/workflows/publish-gh-pages.yml
vendored
Normal file
|
|
@ -0,0 +1,101 @@
|
|||
# Sample workflow for building and deploying a Jekyll site to GitHub Pages
|
||||
name: Publish site
|
||||
|
||||
on:
|
||||
# Runs on pushes targeting the branch where the website sources live
|
||||
push:
|
||||
branches: ["gh-pages"]
|
||||
|
||||
# Allows you to run this workflow manually from the Actions tab
|
||||
workflow_dispatch:
|
||||
|
||||
# Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages
|
||||
permissions:
|
||||
contents: read
|
||||
pages: write
|
||||
id-token: write
|
||||
|
||||
# Allow only one concurrent deployment, skipping runs queued between the run in-progress and latest queued.
|
||||
# However, do NOT cancel in-progress runs as we want to allow these production deployments to complete.
|
||||
concurrency:
|
||||
group: "pages"
|
||||
cancel-in-progress: false
|
||||
|
||||
jobs:
|
||||
# Build job
|
||||
build:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v3
|
||||
with:
|
||||
ref: gh-pages
|
||||
|
||||
- name: Setup Pages
|
||||
uses: actions/configure-pages@v3
|
||||
|
||||
- name: Build with Jekyll
|
||||
uses: actions/jekyll-build-pages@v1
|
||||
with:
|
||||
source: ./
|
||||
destination: ./_site
|
||||
|
||||
- name: Download C apidocs artifact
|
||||
uses: dawidd6/action-download-artifact@v2
|
||||
with:
|
||||
name: onnxruntime-c-apidocs
|
||||
workflow: publish-c-apidocs.yml
|
||||
branch: main
|
||||
path: apidocs
|
||||
|
||||
- name: Download C# apidocs artifact
|
||||
uses: dawidd6/action-download-artifact@v2
|
||||
with:
|
||||
name: onnxruntime-csharp-apidocs
|
||||
workflow: publish-csharp-apidocs.yml
|
||||
branch: main
|
||||
path: apidocs
|
||||
|
||||
- name: Download Java apidocs artifact
|
||||
uses: dawidd6/action-download-artifact@v2
|
||||
with:
|
||||
name: onnxruntime-java-apidocs
|
||||
workflow: publish-java-apidocs.yml
|
||||
branch: main
|
||||
path: apidocs
|
||||
|
||||
- name: Download Python apidocs artifact
|
||||
uses: dawidd6/action-download-artifact@v2
|
||||
with:
|
||||
name: onnxruntime-python-apidocs
|
||||
workflow: publish-python-apidocs.yml
|
||||
branch: main
|
||||
path: apidocs
|
||||
|
||||
- name: Move apidocs folder into place
|
||||
run: |
|
||||
sudo rm -rf _site/docs/api/c
|
||||
sudo mv apidocs/docs/api/c _site/docs/api
|
||||
sudo rm -rf _site/docs/api/csharp
|
||||
sudo mv apidocs/docs/api/csharp _site/docs/api
|
||||
sudo rm -rf _site/docs/api/java
|
||||
sudo mv apidocs/docs/api/java _site/docs/api
|
||||
sudo rm -rf _site/docs/api/python
|
||||
sudo mv apidocs/docs/api/python _site/docs/api
|
||||
|
||||
- name: Upload site
|
||||
uses: actions/upload-pages-artifact@v1
|
||||
with:
|
||||
retention-days: 21
|
||||
|
||||
# Deployment job
|
||||
deploy:
|
||||
environment:
|
||||
name: github-pages
|
||||
url: ${{ steps.deployment.outputs.page_url }}
|
||||
runs-on: ubuntu-latest
|
||||
needs: build
|
||||
steps:
|
||||
- name: Deploy to GitHub Pages
|
||||
id: deployment
|
||||
uses: actions/deploy-pages@v1
|
||||
29
.github/workflows/publish-java-apidocs.yml
vendored
29
.github/workflows/publish-java-apidocs.yml
vendored
|
|
@ -1,21 +1,25 @@
|
|||
name: Update Java API Docs
|
||||
|
||||
# Run when the Java API changes or every month so that the artifact does not expire
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- main
|
||||
paths:
|
||||
- java
|
||||
schedule:
|
||||
- cron: '0 0 1 * *'
|
||||
workflow_dispatch:
|
||||
|
||||
concurrency:
|
||||
group: "apidocs-java"
|
||||
cancel-in-progress: true
|
||||
cancel-in-progress: false
|
||||
|
||||
permissions:
|
||||
contents: write
|
||||
|
||||
jobs:
|
||||
publish:
|
||||
build:
|
||||
name: Generate Java docs
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
|
|
@ -31,15 +35,16 @@ jobs:
|
|||
build-root-directory: java
|
||||
gradle-executable: java/gradlew
|
||||
arguments: javadoc
|
||||
- name: Get source commit
|
||||
id: vars
|
||||
run: echo "::set-output name=sha_short::$(git rev-parse --short HEAD)"
|
||||
- name: Log source commit
|
||||
run: echo $(git rev-parse --short HEAD) > java/build/docs/javadoc/version.txt
|
||||
- name: Deploy
|
||||
uses: JamesIves/github-pages-deploy-action@v4
|
||||
run: git rev-parse --short HEAD > java/build/docs/javadoc/source-version.txt
|
||||
- name: Move Java docs into site
|
||||
run: |
|
||||
rm -rf _site/docs/api/java
|
||||
mkdir -p _site/docs/api
|
||||
mv java/build/docs/javadoc _site/docs/api/java
|
||||
- name: Upload new site
|
||||
uses: actions/upload-artifact@v3
|
||||
with:
|
||||
branch: gh-pages
|
||||
folder: java/build/docs/javadoc
|
||||
target-folder: docs/api/java
|
||||
clean: true
|
||||
name: onnxruntime-java-apidocs
|
||||
path: _site
|
||||
retention-days: 60
|
||||
|
|
|
|||
44
.github/workflows/publish-python-apidocs.yml
vendored
44
.github/workflows/publish-python-apidocs.yml
vendored
|
|
@ -1,12 +1,25 @@
|
|||
name: Update Python API Docs
|
||||
|
||||
# Run when the Python API changes or every month so that the artifact does not expire
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- main
|
||||
paths:
|
||||
- onnxruntime/python
|
||||
schedule:
|
||||
- cron: '0 0 1 * *'
|
||||
workflow_dispatch:
|
||||
|
||||
concurrency:
|
||||
group: "apidocs-python"
|
||||
cancel-in-progress: true
|
||||
|
||||
permissions:
|
||||
contents: write
|
||||
|
||||
jobs:
|
||||
publish:
|
||||
build:
|
||||
name: Generate Python API docs
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
|
|
@ -27,23 +40,16 @@ jobs:
|
|||
run: |
|
||||
cd tools/doc
|
||||
./builddoc.sh /usr/bin ../.. ../../build
|
||||
- name: Set vars
|
||||
id: vars
|
||||
run: echo "::set-output name=sha_short::$(git rev-parse --short HEAD)"
|
||||
- uses: actions/checkout@v2
|
||||
with:
|
||||
ref: gh-pages
|
||||
clean: false
|
||||
- name: Move API docs into target area
|
||||
- name: Log source commit
|
||||
run: git rev-parse --short HEAD > build/docs/inference/html/source-version.txt
|
||||
- name: Move Python docs into site
|
||||
run: |
|
||||
ls docs/api
|
||||
rm -rf docs/api/python
|
||||
mv build/docs/inference/html docs/api/python
|
||||
- name: Create Pull Request
|
||||
uses: peter-evans/create-pull-request@v3
|
||||
rm -rf _site/docs/api/python
|
||||
mkdir -p _site/docs/api
|
||||
mv build/docs/inference/html _site/docs/api/python
|
||||
- name: Upload docs artifact
|
||||
uses: actions/upload-artifact@v3
|
||||
with:
|
||||
branch: gh-pages-pr-python-docs
|
||||
base: gh-pages
|
||||
title: '[Automated]: Update Python API docs'
|
||||
commit-message: 'Update Python API docs to commit ${{ steps.vars.outputs.sha_short }}'
|
||||
add-paths: docs/api/python
|
||||
name: onnxruntime-python-apidocs
|
||||
path: _site
|
||||
retention-days: 60
|
||||
|
|
|
|||
|
|
@ -1,104 +0,0 @@
|
|||
# Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
# Licensed under the MIT License.
|
||||
|
||||
"""
|
||||
Train, convert and predict with ONNX Runtime
|
||||
============================================
|
||||
|
||||
This example demonstrates an end to end scenario
|
||||
starting with the training of a scikit-learn pipeline
|
||||
which takes as inputs not a regular vector but a
|
||||
dictionary ``{ int: float }`` as its first step is a
|
||||
`DictVectorizer <http://scikit-learn.org/stable/modules/generated/sklearn.feature_extraction.DictVectorizer.html>`_.
|
||||
|
||||
.. contents::
|
||||
:local:
|
||||
|
||||
Train a pipeline
|
||||
++++++++++++++++
|
||||
|
||||
The first step consists in retrieving the boston datset.
|
||||
"""
|
||||
import pandas
|
||||
from sklearn.datasets import load_boston
|
||||
|
||||
boston = load_boston()
|
||||
X, y = boston.data, boston.target
|
||||
|
||||
from sklearn.model_selection import train_test_split
|
||||
|
||||
X_train, X_test, y_train, y_test = train_test_split(X, y)
|
||||
X_train_dict = pandas.DataFrame(X_train[:, 1:]).T.to_dict().values()
|
||||
X_test_dict = pandas.DataFrame(X_test[:, 1:]).T.to_dict().values()
|
||||
|
||||
####################################
|
||||
# We create a pipeline.
|
||||
|
||||
from sklearn.ensemble import GradientBoostingRegressor
|
||||
from sklearn.feature_extraction import DictVectorizer
|
||||
from sklearn.pipeline import make_pipeline
|
||||
|
||||
pipe = make_pipeline(DictVectorizer(sparse=False), GradientBoostingRegressor())
|
||||
|
||||
pipe.fit(X_train_dict, y_train)
|
||||
|
||||
####################################
|
||||
# We compute the prediction on the test set
|
||||
# and we show the confusion matrix.
|
||||
from sklearn.metrics import r2_score
|
||||
|
||||
pred = pipe.predict(X_test_dict)
|
||||
print(r2_score(y_test, pred))
|
||||
|
||||
####################################
|
||||
# Conversion to ONNX format
|
||||
# +++++++++++++++++++++++++
|
||||
#
|
||||
# We use module
|
||||
# `sklearn-onnx <https://github.com/onnx/sklearn-onnx>`_
|
||||
# to convert the model into ONNX format.
|
||||
|
||||
from skl2onnx import convert_sklearn
|
||||
from skl2onnx.common.data_types import DictionaryType, FloatTensorType, Int64TensorType, SequenceType
|
||||
|
||||
# initial_type = [('float_input', DictionaryType(Int64TensorType([1]), FloatTensorType([])))]
|
||||
initial_type = [("float_input", DictionaryType(Int64TensorType([1]), FloatTensorType([])))]
|
||||
onx = convert_sklearn(pipe, initial_types=initial_type)
|
||||
with open("pipeline_vectorize.onnx", "wb") as f:
|
||||
f.write(onx.SerializeToString())
|
||||
|
||||
##################################
|
||||
# We load the model with ONNX Runtime and look at
|
||||
# its input and output.
|
||||
import onnxruntime as rt
|
||||
from onnxruntime.capi.onnxruntime_pybind11_state import InvalidArgument
|
||||
|
||||
sess = rt.InferenceSession("pipeline_vectorize.onnx", providers=rt.get_available_providers())
|
||||
|
||||
import numpy
|
||||
|
||||
inp, out = sess.get_inputs()[0], sess.get_outputs()[0]
|
||||
print("input name='{}' and shape={} and type={}".format(inp.name, inp.shape, inp.type))
|
||||
print("output name='{}' and shape={} and type={}".format(out.name, out.shape, out.type))
|
||||
|
||||
##################################
|
||||
# We compute the predictions.
|
||||
# We could do that in one call:
|
||||
|
||||
try:
|
||||
pred_onx = sess.run([out.name], {inp.name: X_test_dict})[0]
|
||||
except (RuntimeError, InvalidArgument) as e:
|
||||
print(e)
|
||||
|
||||
#############################
|
||||
# But it fails because, in case of a DictVectorizer,
|
||||
# ONNX Runtime expects one observation at a time.
|
||||
pred_onx = [sess.run([out.name], {inp.name: row})[0][0, 0] for row in X_test_dict]
|
||||
|
||||
###############################
|
||||
# We compare them to the model's ones.
|
||||
print(r2_score(pred, pred_onx))
|
||||
|
||||
#########################
|
||||
# Very similar. *ONNX Runtime* uses floats instead of doubles,
|
||||
# that explains the small discrepencies.
|
||||
|
|
@ -4,21 +4,20 @@
|
|||
|
||||
Gallery of examples
|
||||
===================
|
||||
|
||||
|
||||
This series of examples briefly goes into the main
|
||||
feature *ONNX Runtime* implements. Each of them run in a
|
||||
feature *ONNX Runtime* implements. Each of them run in a
|
||||
few seconds and relies on machine learned models
|
||||
trained with `scikit-learn <http://scikit-learn.org/stable/>`_.
|
||||
|
||||
|
||||
.. toctree::
|
||||
:maxdepth: 1
|
||||
:caption: Contents:
|
||||
|
||||
|
||||
auto_examples/plot_load_and_predict
|
||||
auto_examples/plot_common_errors
|
||||
auto_examples/plot_train_convert_predict
|
||||
auto_examples/plot_pipeline
|
||||
auto_examples/plot_backend
|
||||
auto_examples/plot_convert_pipeline_vectorizer
|
||||
auto_examples/plot_metadata
|
||||
auto_examples/plot_profiling
|
||||
|
|
|
|||
Loading…
Reference in a new issue