onnxruntime/js/web/script/generate-operator-md.ts
Xueyun Zhu a54716e5a9
cherry pick outstanding commits (#7871)
* Fix bug in Transpose CUDA kernel (#7329)

* Fix permission error for ORTModule lock file (#7814)

* fix topo sort in quant tool (#7833)

* fix topo sort in quant tool

* add unit test and make the topo sort stable

* Relax tol for Conv1D fp16 test (#7844)

* Relax tol for Conv1D fp16 test

Co-authored-by: Sherlock Huang <bahuang@OrtTrainingDev3.af05slrtruoetgaxwwjv5nsq5e.px.internal.cloudapp.net>

* Resolve issue with wrapped ORTModule load_state_dict (#7847)

* Encapsulate children modules inside a ModuleAccessor object to prevent erroneuos iteration over children while loading the state dictionary

* Add named_models, models, apply methods, change ModuleAccessor to ModuleMetadata and modify unit tests

* Change ModuleMetadata module getter logic, raise NotImplementedError for add_modules

* Add comment explaining why overriding _load_from_state_dict method is needed

* fixed bugs in packed mode and enable pack mode tests in ci (#7848)

* fixed bugs in packed mode and enable pack mode tests in ci

* removed unnecessary space

* pr comments

* pr comments

* disable an average pool test

* try disabling another avg pool

* disable more avg pool tests

* disable maxpool tests

* add environment variable to control default training package's local version (#7849)

* [js] update documents (#7852)

* [js] update documents

* escape double quotes

* update operators.md

* resolve comments

* Support bool type for Pad CPU (#7856)

* Initial commit

* update

* nit

* Include ORT C/C++ API headers in the ORT Mobile AAR package (#7858)

* Add header files of ort c/c++ api to aar package

* Move header file selection to cmake based on EP choice

* fix duplicated node name (#7865)

* Clean up CPU kernel definition for opset 13 Pad (#7867)

Co-authored-by: Hariharan Seshadri <shariharan91@gmail.com>
Co-authored-by: Thiago Crepaldi <thiago.crepaldi@microsoft.com>
Co-authored-by: Yufeng Li <liyufeng1987@gmail.com>
Co-authored-by: Sherlock <baihan.huang@gmail.com>
Co-authored-by: Sherlock Huang <bahuang@OrtTrainingDev3.af05slrtruoetgaxwwjv5nsq5e.px.internal.cloudapp.net>
Co-authored-by: baijumeswani <bmeswani@microsoft.com>
Co-authored-by: Tixxx <tix@microsoft.com>
Co-authored-by: liqunfu <liqfu@microsoft.com>
Co-authored-by: Yulong Wang <yulongw@microsoft.com>
Co-authored-by: Guoyu Wang <62914304+gwang-msft@users.noreply.github.com>
Co-authored-by: Tianlei Wu <tlwu@microsoft.com>
2021-05-28 09:10:40 -07:00

105 lines
4 KiB
TypeScript

// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
import * as assert from 'assert';
import * as fs from 'fs';
import {EOL} from 'os';
import * as path from 'path';
import {Attribute} from '../lib/onnxjs/attribute';
import {WEBGL_OP_RESOLVE_RULES} from '../lib/onnxjs/backends/webgl/op-resolve-rules';
import {Operator} from '../lib/onnxjs/operators';
import {OpSet, resolveOperator} from '../lib/onnxjs/opset';
function checkSupport(type: string, range: [number, number], rules: readonly OpSet.ResolveRule[]) {
const node = {name: '', opType: type, inputs: [], outputs: [], attributes: new Attribute(undefined)};
for (let i = range[0]; i <= range[1]; i++) {
try {
resolveOperator(node, [{domain: '', version: i}], rules);
} catch (_e) {
return false;
}
}
return true;
}
function formatDesc(opType: string, range: [number, number], support: boolean, last: boolean) {
let versionDesc = '';
if (support) {
versionDesc = last ? `${range[0]}+` : range[0] === range[1] ? `${range[0]}` : `${range[0]}-${range[1]}`;
versionDesc = `[${versionDesc}](https://github.com/onnx/onnx/blob/master/docs/Changelog.md#${opType}-${range[0]})`;
}
return versionDesc;
}
function dummyOpConstructor(): Operator {
return {} as any as Operator;
}
const ops = new Map<string, Map<string, number[]>>();
const webglCheckOnlyRules =
WEBGL_OP_RESOLVE_RULES.map(rule => [rule[0], rule[1], rule[2], dummyOpConstructor] as OpSet.ResolveRule);
fs.readFileSync(path.join(__dirname, '../../../cmake/external/onnx/onnx/defs/operator_sets.h'), 'utf8')
.split(/\r?\n/)
.forEach(line => {
const matcher = /class ONNX_OPERATOR_SET_SCHEMA_CLASS_NAME\(\s*(\w+),\s*(\d+),\s*(\w+)\)/;
const matches = matcher.exec(line);
if (matches) {
const opset = matches[1];
const version = Number.parseInt(matches[2], 10);
const opType = matches[3];
let currentSet = ops.get(opset);
if (currentSet === undefined) {
currentSet = new Map<string, number[]>();
ops.set(opset, currentSet);
}
let currentOp = currentSet.get(opType);
if (currentOp === undefined) {
currentOp = [];
currentSet.set(opType, currentOp);
}
currentOp.push(version);
}
});
const opsets = Array.from(ops.keys());
assert.ok(opsets.length === 1 && opsets[0] === 'Onnx');
const onnxOpset = ops.get(opsets[0])!;
const opTypes = Array.from(onnxOpset.keys()).sort();
const doc = fs.createWriteStream(path.join(__dirname, '../docs/operators.md'));
doc.write(`## Operators Support Table${EOL}${EOL}`);
doc.write(`The following table shows [ai.onnx](https://github.com/onnx/onnx/blob/master/docs/Operators.md)\
operators from which onnx opset version are currently supported by onnxjs. For example, \`4-6, 8+\` means\
ONNX Runtime Web currently support opset version 4 to 6, 8 and above.${EOL}${EOL}`);
doc.write(`See [Compatibility](../README.md#Compatibility) for a list of the supported platforms.${EOL}${EOL}`);
doc.write(`*This file is automatically generated from the\
def files via [this script](../script/generate-operator-md.ts).\
Do not modify directly.*${EOL}${EOL}`);
doc.write(`| Operator | WebGl Backend |${EOL}`);
doc.write(`|:--------:|:-------------:|${EOL}`);
let VERSION_MAX = 0;
onnxOpset.forEach(versions => {
versions.forEach(version => VERSION_MAX = Math.max(VERSION_MAX, version));
});
for (const type of opTypes) {
const versions = onnxOpset.get(type)!.sort((a, b) => a - b);
const webgl: string[] = [];
for (let i = 0; i < versions.length; i++) {
const last = i === versions.length - 1;
const versionRange: [number, number] = [versions[i], last ? VERSION_MAX : versions[i + 1] - 1];
webgl.push(formatDesc(type, versionRange, checkSupport(type, versionRange, webglCheckOnlyRules), last));
}
doc.write(`| [${type}](https://github.com/onnx/onnx/blob/master/docs/Operators.md#${type}) | ${
webgl.filter(d => d.length > 0).join(', ')} |${EOL}`);
}
doc.end();