-chlo-legalize-to-stablehlo

CHLO 작업 흐름에서 StableHLO 및 Shape 작업으로 합법화

-shape-legalize-to-stablehlo

도형 관련 작업을 StableHLO로 합법화합니다.

형태 관련 작업을 StableHLO 작업으로 합법화하는 실험용 패스입니다.

선택적 패스를 통해 형태와 데이터 계산을 결합하면 StableHLO 생태계에서 이 기능을 활용하여 StableHLO 작업을 사용하여 역동성을 모델링하는 컴파일 파이프라인입니다.

-stablehlo-aggressive-folder

SableHLO 작업을 접습니다.

옵션

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

-stablehlo-aggressive-simplification

SableHLO 작업을 표준화

-stablehlo-canonicalize-dynamism

동적 StableHLO 작업을 정적 작업으로 표준화합니다.

DynamicReshapeOp와 같은 동적 StableHLO 작업을 상응하는 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 Opset 지원 중단 RFC (#2283)는 발생했다고 합니다 이 패스는 이러한 작업의 영향을 평가하는 데 도움이 됩니다. 다양한 컴파일 파이프라인의 자체 검사에 합법화해 장기적 지원이 필요한 대안도 살펴보겠습니다

옵션

-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

SableHLO 양자화 작업을 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

SableHLO를 VHLO로 합법화합니다.

-stablehlo-refine-arguments

main 함수의 인수 형태를 미세 조정합니다.

입력 유형 서명을 사용하여 main 함수의 인수를 수정합니다. 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

SableHLO 프로그램에서 형태를 미세 조정합니다.

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'.