-chlo-legalize-to-stablehlo

CHLO オペレーション フローから StableHLO オペレーションと Shape オペレーションに正当化

-shape-legalize-to-stablehlo

シェイプ関連のオペレーションを StableHLO に正当化。

シェイプ関連のオペレーションを StableHLO オペレーションに合法化する試験運用版のパス。

オプションのパスを使用してシェイプとデータの計算を 1 つにまとめると、 StableHLO エコシステムで StableHLO オペレーションを使用してダイナミズムをモデル化するコンパイル パイプライン。

-stablehlo-aggressive-folder

StableHLO のオペレーションを折りたたみ

オプション

-fold-float : Allow for potentially lossy computations using float type.

-stablehlo-aggressive-simplification

StableHLO のオペレーションを正規化

-stablehlo-canonicalize-dynamism

動的な StableHLO 演算を静的演算に正規化。

DynamicReshapeOp などの動的 StableHLO オペレーションを対応する これらの op のすべての動的要素が 実は定数です

たとえば、DynamicReshapeOp の output_shape オペランドが定数の場合、 その演算を ReshapeOp に変換できます。

-stablehlo-convert-to-signless

IR を符号なし整数に変換する場合に渡します。

-stablehlo-legalize-composite-to-call

複合演算をその分解の呼び出しに置き換える

複合演算を分解の呼び出しに置き換えます。たとえば、次のとおりです。

stablehlo.composite "my_namespace.my_op" %arg0, %arg1 {
  decomposition = @bar,
  version = 1,
  composite_attributes = {
    "my_attribute": "my_value"
  }
}

次のようになります。

func.call @bar(%arg0, %arg1)

複合のサブセットをこの変換から除外するには、 「除く」次に例を示します。

stablehlo-opt --stablehlo-legalize-composite-to-call=except='foo.baz,foo.qux'

オプション

-except : Names of composites that should not be replaced with calls.

-stablehlo-legalize-deprecated-ops

非推奨のオペレーションを、適切にサポートされているオペレーションに合法化します。

StableHLO v1.0 Opset Deprecations RFC(#2283)では、 冗長なオペレーションが発生します。このパスは、これらのオペレーションの影響を評価するのに役立ちます。 コンパイルパイプラインでの削除を 対して、長期サポート契約の条件を満たすものでなければなりません。

オプション

-fail-on-unused : Fail on (mostly) unused ops that are deprecated without any fallback.

-stablehlo-legalize-qdq-to-quantized-op

(非量子化、浮動小数点演算、量子化)パターンを StableHLO の量子化演算に融合する

(非量子化、浮動小数点演算、量子化)パターンを StableHLO の量子化演算に融合する 注: このパスによって既存の op は削除されません。 たとえば、次のプログラムでは、

func.func @add(%arg0: tensor<16x16x!quant.uniform<ui8:f32, 34.0:16>>) -> tensor<16x16x!quant.uniform<ui8:f32, 34.0:16>> {
  %0 = stablehlo.uniform_dequantize %arg0 : (tensor<16x16x!quant.uniform<ui8:f32, 34.0:16>>) -> tensor<16x16xf32>
  %1 = stablehlo.abs %0 : tensor<16x16xf32>
  %2 = stablehlo.uniform_quantize %1 : (tensor<16x16xf32>) -> tensor<16x16x!quant.uniform<ui8:f32, 34.0:16>>
  func.return %2 : tensor<16x16x!quant.uniform<ui8:f32, 34.0:16>>
}

次のようになります。

func.func @add(%arg0: tensor<16x16x!quant.uniform<u8:f32, 3.400000e+01:16>>) -> tensor<16x16x!quant.uniform<u8:f32, 3.400000e+01:16>> {
  %0 = stablehlo.uniform_dequantize %arg0 : (tensor<16x16x!quant.uniform<u8:f32, 3.400000e+01:16>>) -> tensor<16x16xf32>
  %1 = stablehlo.abs %0 : tensor<16x16xf32>
  %2 = stablehlo.abs %arg0 : tensor<16x16x!quant.uniform<u8:f32, 3.400000e+01:16>>
  %3 = stablehlo.uniform_quantize %1 : (tensor<16x16xf32>) -> tensor<16x16x!quant.uniform<u8:f32, 3.400000e+01:16>>
  return %2 : tensor<16x16x!quant.uniform<u8:f32, 3.400000e+01:16>>
}

-stablehlo-legalize-quant-to-math

StableHLO の量子化演算を StableHLO プリミティブな数学演算に変換します。

UniformQuantized 型を使用して StableHLO プログラムを意味的に変換する 同等の整数数学演算について説明します。

func.func @add(%arg0: tensor<!quant.uniform<i8:f32,1.0:0>>, %arg1: tensor<!quant.uniform<i8:f32,2.0:1>>) ->  tensor<!quant.uniform<i8:f32,3.0:2>> {
  %0 = "stablehlo.add"(%arg0, %arg1) : (tensor<!quant.uniform<i8:f32,1.0:0>>, tensor<!quant.uniform<i8:f32,2.0:1>>) -> tensor<!quant.uniform<i8:f32,3.0:2>>
  func.return %0 : tensor<!quant.uniform<i8:f32,3.0:2>>
}

次のようになります。

func.func @add(%arg0: tensor<i8>, %arg1: tensor<i8>) -> tensor<i8> {
  %0 = stablehlo.convert %arg0 : (tensor<i8>) -> tensor<f32>
  %cst = stablehlo.constant dense<0.333333343> : tensor<f32>
  %1 = chlo.broadcast_multiply %0, %cst : (tensor<f32>, tensor<f32>) -> tensor<f32>
  %cst_0 = stablehlo.constant dense<2.000000e+00> : tensor<f32>
  %2 = chlo.broadcast_add %1, %cst_0 : (tensor<f32>, tensor<f32>) -> tensor<f32>
  %3 = stablehlo.round_nearest_even %2 : tensor<f32>
  %4 = stablehlo.convert %3 : (tensor<f32>) -> tensor<i32>
  %5 = stablehlo.convert %arg1 : (tensor<i8>) -> tensor<f32>
  %cst_1 = stablehlo.constant dense<0.666666686> : tensor<f32>
  %6 = chlo.broadcast_multiply %5, %cst_1 : (tensor<f32>, tensor<f32>) -> tensor<f32>
  %cst_2 = stablehlo.constant dense<1.33333337> : tensor<f32>
  %7 = chlo.broadcast_add %6, %cst_2 : (tensor<f32>, tensor<f32>) -> tensor<f32>
  %8 = stablehlo.round_nearest_even %7 : tensor<f32>
  %9 = stablehlo.convert %8 : (tensor<f32>) -> tensor<i32>
  %c = stablehlo.constant dense<2> : tensor<i32>
  %10 = chlo.broadcast_add %4, %9 : (tensor<i32>, tensor<i32>) -> tensor<i32>
  %11 = chlo.broadcast_subtract %10, %c : (tensor<i32>, tensor<i32>) -> tensor<i32>
  %c_3 = stablehlo.constant dense<-128> : tensor<i32>
  %c_4 = stablehlo.constant dense<127> : tensor<i32>
  %12 = stablehlo.clamp %c_3, %11, %c_4 : tensor<i32>
  %13 = stablehlo.convert %12 : (tensor<i32>) -> tensor<i8>
  return %13 : tensor<i8>
}

-stablehlo-legalize-quantized-op-to-qdq

量子化された StableHLO 演算を(非量子化、浮動小数点演算、量子化)パターンに分解する。

均一な量子化/逆量子化を使用して StableHLO 量子化プログラムを分解する 必要があります。たとえば、次のプログラムでは、

func.func @add(%arg0: tensor<!quant.uniform<i8:f32,1.0:0>>, %arg1: tensor<!quant.uniform<i8:f32,2.0:1>>) ->  tensor<!quant.uniform<i8:f32,3.0:2>> {
  %0 = "stablehlo.add"(%arg0, %arg1) : (tensor<!quant.uniform<i8:f32,1.0:0>>, tensor<!quant.uniform<i8:f32,2.0:1>>) -> tensor<!quant.uniform<i8:f32,3.0:2>>
  func.return %0 : tensor<!quant.uniform<i8:f32,3.0:2>>
}

次のようになります。

func.func @add(%arg0: tensor<!quant.uniform<i8:f32, 1.000000e+00>>, %arg1: tensor<!quant.uniform<i8:f32, 2.000000e+00:1>>) -> tensor<!quant.uniform<i8:f32, 3.000000e+00:2>> {
  %0 = stablehlo.uniform_dequantize %arg0 : (tensor<!quant.uniform<i8:f32, 1.000000e+00>>) -> tensor<f32>
  %1 = stablehlo.uniform_dequantize %arg1 : (tensor<!quant.uniform<i8:f32, 2.000000e+00:1>>) -> tensor<f32>
  %2 = stablehlo.add %0, %1 : tensor<f32>
  %3 = stablehlo.uniform_quantize %2 : (tensor<f32>) -> tensor<!quant.uniform<i8:f32, 3.000000e+00:2>>
  return %3 : tensor<!quant.uniform<i8:f32, 3.000000e+00:2>>
}

-stablehlo-legalize-to-vhlo

StableHLO を VHLO に合法化。

-stablehlo-refine-arguments

main 関数の引数の形状を絞り込みます。

入力型のシグネチャを使用して、main 関数の引数を変更します。 custom_call @stablehlo.shape_refinement_operand_wrapper で引数をラップします を使用して IR を有効のまま維持します。

refinedTypesOption を使用して、絞り込まれたタイプのリストを指定できます。 これは、MLIR で --types='tensor<...>,tensor<...>' を使用して指定できます。または、 pass create メソッドに渡されます。絞り込みタイプリストでは、 絞り込む main メソッドに対するすべての引数の型。

オプション

-types : The new types to be used for the main function's arguments, specified as an MLIR TypeRange 'tensor<1x2xf32>, ...'

-stablehlo-refine-shapes

StableHLO プログラム全体のシェイプを改良。

オペレーション内のシェイプを改良する StableHLO プログラムについて説明します。

このパスの主力のユースケースは、 静的シェイプに変換できます。動的に形成される StableHLO プログラムに 引数の型を動的なシェイプから 実行され、このパスを実行すると、静的シェイプが 説明します。

-vhlo-legalize-to-stablehlo

VHLO を StableHLO に正当化する。

-vhlo-to-version

VHLO のバージョンを変換する。

オプション

-target : The target version. Must be a version of the form #.#.# or 'current'.