-chlo-legalize-to-stablehlo

從 CHLO 作業流程到 StableHLO 和形狀運算

-shape-legalize-to-stablehlo

將形狀相關運算合法化為 StableHLO。

將形狀相關運算合法化為 StableHLO 運算的實驗性通行證。

透過選擇性傳遞傳遞將形狀和資料運算整合在一起 以便 StableHLO 生態系統可能利用 以及使用 StableHLO 作業來模擬命運的編譯管道。

-stablehlo-aggressive-folder

Folds StableHLO 運算

選項

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

-stablehlo-aggressive-simplification

將 StableHLO 作業標準化

-stablehlo-canonicalize-dynamism

將動態 StableHLO 運算標準化為靜態作業。

將動態 StableHLO 運算 (例如 DynamicReshapeOp) 替換為相應的 或是 ReshapeOp 等靜態對應元素 實際上是常數

例如,如果 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 作業淘汰 RFC (#2283) 建議移除 以部署 Kubernetes 叢集這個通過道有助於評估這些運算的影響 以合法方式移除各個編譯管道 以及長期支援的容器版本

選項

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

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

將模式 (去量化、浮點運算和量化) 模式融入 StableHLO 量化運算

將模式 (去量化、浮點運算和量化) 模式融入 StableHLO 量化運算 注意:傳遞不會刪除任何既有的運算。 例如,下列程式

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 合法化。

-stablehlo-refine-arguments

修正主函式的引數形狀。

使用輸入類型簽章修改主函式的引數。 包裝 custom_call @stablehlo.shape_refinement_operand_wrapper 中的引數 ,在執行形狀修正之前,確保 IR 有效。

refinedTypesOption 可用於指定修正類型的清單。 這可在 MLIR 中使用 --types='tensor<...>,tensor<...>' 或 傳遞到票證建立方法修正類型清單必須指定 我們要修正 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'.