Open Neural Network Exchange
![]() | |
開発元 | Facebook, Microsoft |
---|---|
初版 | 2017年9月 |
リポジトリ |
github |
種別 | 人工知能 機械学習 |
公式サイト |
onnx |
Open Neural Network Exchange(略称:ONNX)は、オープンソースで開発されており、機械学習や人工知能のモデルを表現する為の代表的なフォーマットである[1]。
概要[編集]
機械学習、特にニューラルネットワークモデルは様々なフレームワーク上で学習され、また様々なハードウェア上で実行(推論)される。各環境に特化したモデルは他のフレームワーク・ハードウェアで利用できず相互運用性を欠いてしまう。また実装者は環境ごとにサポートをおこなう必要があり大きな労力を必要とする。
ONNXはモデルを記述する統一インターフェース(フォーマット)を提供し、これらの問題を解決する。各フレームワークは学習したモデルをONNX形式で出力する。各ハードウェアはONNX実行環境を提供することで、どのフレームワークで学習されたかを問わずモデル推論を実行する。このように相互運用可能なモデルフォーマットとしてONNXは開発されている。
2017年に開発が開始された。
開発背景[編集]
以下の特性を補完する意図にて開発が進められた。
フレームワークの相互運用性[編集]
開発工程や機械学習の高速処理、ネットワークの基本設計における柔軟性やモバイルデバイスでの推論などの特定の段階において、開発者が複数のフレームワークでのデータのやり取りを簡単に行えるようにする[2]。
最適化の共有[編集]
ハードウェアベンダーなどは、ONNXを対象に調整を行うことで、複数のフレームワークにおけるニューラルネットワークのパフォーマンスを一度に改善することができる[2]。
内容[編集]
ONNXは、推論(評価)に焦点を当て、拡張可能な計算グラフモデル、組み込み演算子、および標準データ型の定義を提供する[2]。
それぞれのデータフローグラフは、非循環グラフを形成するノードのリストになっている。ノードには入力と出力があり、各ノードが処理を呼び出すようになっている。メタデータはグラフを文書化する。組み込み演算子は、ONNXをサポートする各フレームワークで利用可能である[2]。
ONNX仕様は2つのサブ仕様、IRとOperatorからなる。この2つの仕様はそれぞれバージョニングされており、ONNX仕様のバージョンはこの2つのサブ仕様の特定版を指定したものとなっている。2021-12-22現在の最新バージョンは version 1.10.2 であり、これはIR v8とOperator v15-v2-v1 から成る[3]。
ONNX IR[編集]
Open Neural Network Exchange Intermediate Representation (ONNX IR) はONNXの基本データ型と計算グラフを定義するサブ仕様である[4]。ONNX IRは計算グラフを構成する Model
, Graph
, Node
等の要素、入出力 Tensor
, Sequence
, Map
およびデータ FLOAT
, INT8
, BFLOAT16
等の基本データ型を定義する。2021-12-22現在の最新バージョンは version 8 である[3]。
ONNX IRが定義する要素として以下が挙げられる。
Graph
: 計算グラフを表現する要素。Graph入出力を指定するinput
/initializer
[5][6]/output
、計算ノード群を指定するnode
、メタデータを収納するname
/doc_string
/value_info
、の属性をもつ。Node
: 計算ノードを表現する要素。Node入出力を指定するinput
/output
、演算子とそのパラメータを指定するdomain
/op_type
/attribute
、メタデータを収納するname
/doc_string
/value_info
、の属性をもつ。
すなわちGraph
に収納された各Node
が入出力をもった演算 (例: Conv) になっており、Node/Graph入出力名に基づいてNode群がグラフ構造を取っている。
拡張演算子[編集]
ONNX IRはONNX Operatorで定義される標準演算子に追加して、独自の拡張演算子を受け入れられるように設計されている[7]。これによりONNXの "Extensible/拡張可能" 特性を実現している[8]。拡張演算子セットを Model
の opset_import
属性に指定することで実行エンジン側へ拡張演算子の利用を通知する仕組みである[9]。ONNXを受け取った実行エンジンは opset_import
を確認し、指定された演算子セット全てをサポートしていれば受け入れ、そうでなければ Model
全体を拒絶する[10]。
ONNX Operator[編集]
ONNXのビルトイン演算子はサブ仕様 Operator specifications により定義される[11]。3種類の演算子セット(Opset)ai.onnx
, ai.onnx.ml
, ai.onnx.training
が定義されており、ai.onnx
がデフォルトである。2021-12-22現在、ai.onnx
の最新バージョンは version 15 である[3]。
例えばOpset ai.onnx
v15ではRNN系演算子として RNN
、LSTM
、GRU
が定義されている。
量子化[編集]
ONNXは入出力の量子化やそれに対する操作を演算子として持つ。QuantizeLinear
はスケール・シフトパラメータに基づく線形量子化をおこなう[12]。DynamicQuantizeLinear
は入力ベクトルのmin/maxに基づく動的uint8量子化をおこなう[13]。int8入力に対する演算にはMatMulInteger
、QLinearMatMul
、ConvInteger
、QLinearConv
などがある。
ONNX Runtime[編集]
ONNX Runtime (略称: ORT[14]) は様々な環境におけるONNXモデルの推論・学習高速化を目的としたオープンソースプロジェクトである[15]。フレームワーク・OS・ハードウェアを問わず単一のRuntime APIを介してONNXモデルを利用できる[16]。またデプロイ環境に合わせた最適化を自動でおこなう[17]。ONNX Runtimeは設計方針としてアクセラレータ・ランタイム抽象化とパフォーマンス最適化の両立を掲げており、ONNXモデルの自動分割と最適アクセラレータによるサブモデル実行によりこれを実現している[18]。
ONNX Runtimeがサポートする最適化には以下が挙げられる。
- モデル量子化: 8-bit Model Quantization[19]
- グラフ最適化[20]: Basic (不要ノード除去・一部のop fusions[21]), Extended (op fusions[22]), Layout (NCHWc Optimizer[23]) の三段階
対応するアクセラレータは最大10以上である[24]。x64 CPU向けには Default CPU (by MLAS[25])、oneDNN・OpenVINO[26] (Intelに最適化)、TVM が存在する。
歴史[編集]
2017年9月に、FacebookとMicrosoftは、PyTorchやCaffe2などの機械学習フレームワーク間において相互運用を可能にする為の取り組みとして、このプロジェクトを始動した。その後、IBM、Huawei、Intel、AMD、ARM、Qualcommがこの取り組みに対して積極的な支援を表明した[1]。
2017年10月に、MicrosoftはCognitive ToolkitおよびProject Brainwaveプラットフォームにおいて、ONNXのサポートを発表した[1]。
2019年11月、ONNXはLinux Foundation AIの卒業生プロジェクトとして承認された。
脚注[編集]
出典[編集]
- ^ a b c “Microsoft and Facebook's open AI ecosystem gains more support” (英語). Engadget 2017年10月11日閲覧。
- ^ a b c d “Microsoft and Facebook create open ecosystem for AI model interoperability - Microsoft Cognitive Toolkit” (英語). Microsoft Cognitive Toolkit. (2017年9月7日) 2017年10月11日閲覧。
- ^ a b c ONNX Versioning. onnx/onnx.
- ^ " 1. A definition of an extensible computation graph model. 2. Definitions of standard data types. #1 and #2 together make up the ONNX Intermediate Representation, or 'IR', specification" Open Neural Network Exchange Intermediate Representation (ONNX IR) Specification. onnx/onnx
- ^ 同名のGraph入力デフォルト値、あるいは定数Graph入力扱い "When an initializer has the same name as a graph input, it specifies a default value for that input. When an initializer has a name different from all graph inputs, it specifies a constant value." Open Neural Network Exchange Intermediate Representation (ONNX IR) Specification. onnx/onnx. 2022-06-09閲覧.
- ^ "When an initializer has the same name as a graph input, it specifies a default value for that input." Open Neural Network Exchange Intermediate Representation (ONNX IR) Specification. onnx/onnx. 2022-06-09閲覧.
- ^ "An implementation MAY extend ONNX by adding operators expressing semantics beyond the standard set of operators" Open Neural Network Exchange Intermediate Representation (ONNX IR) Specification. onnx/onnx
- ^ "Extensible computation graph model ... expressing semantics beyond the standard set of operators" Open Neural Network Exchange Intermediate Representation (ONNX IR) Specification. onnx/onnx
- ^ "The mechanism for this is adding operator sets to the
opset_import
property in a model that depends on the extension operators." Open Neural Network Exchange Intermediate Representation (ONNX IR) Specification. onnx/onnx - ^ "An implementation must support all operators in the set or reject the model." Open Neural Network Exchange Intermediate Representation (ONNX IR) Specification. onnx/onnx
- ^ "Operator specifications that may be referenced by a given ONNX graph." ONNX Versioning. onnx/onnx.
- ^ "QuantizeLinear The linear quantization operator. It consumes a high precision tensor, a scale, and a zero point ... The quantization formula is y = saturate ((x / y_scale) + y_zero_point). ... For (x / y_scale), it's rounding to nearest ties to even." Operator Schemas. ONNX. 2022-03-13閲覧.
- ^ "DynamicQuantizeLinear for Scale, Zero Point and FP32->8Bit convertion of FP32 Input data" Operator Schemas. ONNX. 2022-03-13閲覧.
- ^ "ONNX Runtime (ORT)" Welcome to ONNX Runtime (ORT). ONNX Runtime.
- ^ "ONNX Runtime is an open source project that is designed to accelerate machine learning across a wide range of frameworks, operating systems, and hardware platforms." About. ONNX Runtime.
- ^ "It enables acceleration of machine learning inferencing across all of your deployment targets using a single set of API." About. ONNX Runtime.
- ^ "ONNX Runtime automatically parses through your model to identify optimization opportunities and provides access to the best hardware acceleration available." About. ONNX Runtime.
- ^ "Design principles ONNX Runtime abstracts custom accelerators and runtimes to maximize their benefits across an ONNX model. ... ONNX Runtime partitions the ONNX model graph into subgraphs that align with available custom accelerators and runtimes." About. ONNX Runtime.
- ^ Quantize ONNX Models. ONNX Runtime.
- ^ Graph Optimizations in ONNX Runtime. ONNX Runtime.
- ^ "Redundant node eliminations ... Semantics-preserving node fusions" Graph Optimizations in ONNX Runtime. ONNX Runtime.
- ^ "These optimizations include complex node fusions." Graph Optimizations in ONNX Runtime. ONNX Runtime.
- ^ "These optimizations change the data layout ... Optimizes the graph by using NCHWc layout instead of NCHW layout." Graph Optimizations in ONNX Runtime. ONNX Runtime.
- ^ "Hardware Acceleration Default CPU, Core ML, CUDA ..." Get Started Easily. ONNX Runtime.
- ^ Microsoft Machine Learning algebra subprogram library
- ^ 実装はOneDNN/MKL-DNN "The CPU plugin was developed ... using the Intel® Math Kernel Library for Deep Neural Networks (Intel® MKL-DNN)" CPU Plugin. OpenVINO Toolkit.
関連項目[編集]
外部リンク[編集]
- Boyd, Eric (2017年9月7日). “Microsoft and Facebook create open ecosystem for AI model interoperability - Microsoft Cognitive Toolkit” (英語). Microsoft Cognitive Toolkit 2017年10月11日閲覧。