MLIR 編譯器基礎架構中 ONNX 模型的表示法和參考降低
此專案由 onnx 維護
託管於 GitHub Pages — 主題由 orderedlist 提供
儀器化在 onnx-mlir 中進行原型設計,可用於偵錯執行階段問題。
預設情況下,儀器化已關閉。您需要使用以下命令列選項將其開啟。儀器化的 pass 會使用 --instrument-stage
選項插入在某些階段。例如,當您指定 Onnx
時,儀器化會在 onnx 到 onnx 轉換後插入,以取得 onnx 層級的效能分析。--instrument-ops
選項是用於指定要儀器化的操作的選項。例如,您可以對 onnx Conv 操作使用 onnx.Conv
。此外,您可以對所有 onnx 操作使用星號,例如 onnx.*
,並使用 ,
指定兩個表達式,例如 onnx.Conv,onnx.Add
以同時表示 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
此處說明時間測量的輸出。
PERF-REPORT
。onnx_node_name
屬性時,會顯示此名稱。before
或 after
。此處說明記憶體測量的輸出。
MEM-REPORT
。NNPA 的其他範例
onnx-mlir --mcpu=z16 --maccel=NNPA --instrument-stage=Onnx --instrument-ops=onnx.* --InstrumentBeforeOp --InstrumentAfterOp --InstrumentReportTime mymodel.onnx
onnx-mlir --mcpu=z16 --maccel=NNPA --instrument-stage=ZHigh --instrument-ops=onnx.*,zhigh.* --InstrumentBeforeOp --InstrumentAfterOp --InstrumentReportTime mymodel.onnx
onnx-mlir --mcpu=z16 --maccel=NNPA --instrument-stage=ZLow --instrument-ops=zlow.* --InstrumentBeforeOp --InstrumentAfterOp --InstrumentReportTime mymodel.onnx
透過在執行階段提供某些環境變數,您可以停用儀器函式庫的報告。
ONNX_MLIR_NO_INSTRUMENT
,則完全沒有報告ONNX_MLIR_NO_INSTRUMENT_TIME
,則時間使用量的報告將停用ONNX_MLIR_NO_INSTRUMENT_MEMORY
,則記憶體使用量的報告將停用ONNX_MLIR_INSTRUMENT_FILE
,則此變數提供儲存儀器化的檔案名稱。請注意,啟用儀器化的唯一方法是在編譯時要求。如果在執行階段未開啟任何詳細報告 (例如到目前為止的時間和記憶體),仍會印出儀器點的進度。此功能被認為可作為進度指示器很有用。若要完全停用編譯時要求的任何輸出,您必須設定 ONNX_MLIR_NO_INSTRUMENT
。
儀器點的函式稱為 OMInstrumentPoint
。可以在此函式內設定中斷點,以便逐步執行 onnx 操作。