MLIRコンパイラインフラストラクチャにおけるONNXモデルの表現と参照の低減
GitHubでプロジェクトを見る onnx/onnx-mlir
このプロジェクトはonnxによって管理されています
GitHub Pagesでホストされています — テーマはorderedlistによるものです
計測はonnx-mlirでプロトタイプされており、ランタイムの問題をデバッグするために使用できます。
デフォルトでは、計測は無効になっています。有効にするには、以下のコマンドラインオプションを使用する必要があります。計測のためのパスは、`--instrument-stage`オプションを使用して、いくつかのステージに挿入されます。たとえば、`Onnx`を指定すると、onnxレベルのプロファイリングを取得するために、onnx-to-onnx変換後に計測が挿入されます。`--instrument-ops`オプションは、計測する操作を指定するためのオプションです。たとえば、onnx Conv操作には`onnx.Conv`を使用できます。また、すべてのonnx操作には`onnx.*`のようなアスタリスクを使用でき、`onnx.Conv,onnx.Add`のように`,`で2つの式を指定して、ConvとAddの両方の操作を指定できます。`--InstrumentBeforeOp`と`--InstrumentAfterOp`は、指定された操作の前または後、あるいはその両方に計測を挿入するためのオプションです。`--instrument-ops=onnx.* --InstrumentBeforeOp --InstrumentAfterOp`を使用すると、すべてのonnx操作の前後に計測が挿入されます。NNPAの場合、`ZHigh`と`ZLow`に追加のステージが提供されています。`--instrument-stage=ZHigh`と`--instrument-ops=onnx.*,zhigh.*`を使用してonnxとzhigh操作のプロファイルを取得でき、`--instrument-stage=ZLow`と`--instrument-ops=zlow.*`を使用してzlow操作のプロファイルを取得できます。
--instrument-stage=<value> - Specify stage to be instrumented:
=Onnx - Profile for onnx ops. For NNPA, profile onnx ops before lowering to zhigh.
=ZHigh - NNPA profiling for onnx and zhigh ops.
=ZLow - NNPA profiling for zlow ops.
--instrument-ops=<string> - Specify operations operations to be instrumented:
"NONE" or "" for no instrument,
"ops1,ops2, ..." for the multiple ops.
e.g. "onnx.Conv,onnx.Add" for Conv and Add ops.
Asterisk is also available.
e.g. "onnx.*" for all onnx operations.
Specify what instrumentation actions at runtime:
--InstrumentBeforeOp - insert instrument before op,
--InstrumentAfterOp - insert instrument after op,
--InstrumentReportTime - instrument runtime reports time usage,
--InstrumentReportMemory - instrument runtime reports memory usage.
現在、初期化の呼び出しであるOMInstrumentInitは、動的ライブラリをロードする前に追加する必要があります。コンパイラによってmain_graphの先頭に追加することを検討しています。
通常と同じ方法でモデルを実行します。計測ライブラリは、各計測ポイントで時間とメモリ使用量を出力します。たとえば、モデル`mymodel.onnx`は、`onnx-mlir --instrument-stage=Onnx --instrument-ops=onnx.* --InstrumentAfterOp --InstrumentReportMemory --InstrumentReportTime mymodel.onnx`でコンパイルされます。そのランタイム出力は以下のとおりです。
==PERF-REPORT==, onnx.Cast, bert/encoder/Reshape__27, before, 0.000001, 1692654182.738546
==PERF-REPORT==, onnx.Cast, bert/encoder/Reshape__27, after, 0.000001, 1692654182.738547
==PERF-REPORT==, onnx.Concat, bert/encoder/Reshape__27, before, 0.000000, 1692654182.738547
==PERF-REPORT==, onnx.Concat, bert/encoder/Reshape__27, after, 0.000001, 1692654182.738548
==PERF-REPORT==, onnx.Reshape, bert/encoder/Reshape, before, 0.000001, 1692654182.738549
==PERF-REPORT==, onnx.Reshape, bert/encoder/Reshape, after, 0.000001, 1692654182.738550
時間測定の出力について説明します。
メモリ測定の出力について説明します。
NNPAのその他の例
実行時に特定の環境変数を指定することで、計測ライブラリからのレポートを無効にできます。
計測を有効にする唯一の方法は、コンパイル時にそれを要求することです。実行時に詳細なレポート(これまでの時間やメモリなど)が有効になっていない場合でも、計測ポイントの進行状況は出力されます。この機能は、進捗インジケータとして役立つと考えられています。コンパイル時に要求された出力を完全に無効にするには、`ONNX_MLIR_NO_INSTRUMENT`を設定する必要があります。
計測ポイントの関数は`OMInstrumentPoint`と呼ばれます。この関数内にブレークポイントを設定して、onnx操作をステップ実行できます。