Use tvm.transform.Sequential to customize the execution order of the pass, but print the actual pass execution order, and find that relayIR will be executed according to the execution order of the pass I defined, but will continue to execute the rest of the current optimization level RealyIR pass optimization, why is this? I hope that experts and compiler researchers in the community can help me solve this question. This is the execution sequence of the relay IR pass I defined:
@tvm.instrument.pass_instrument class PrintIR:
def __init__(self):
self._info = []
# def extract_info(self,mod,info):
def run_before_pass(self,mod,info):
self._info.append(info)
def getinfo(self):
return self._info
printIR = PrintIR()
seq = tvm.transform.Sequential([
relay.transform.Legalize(),
relay.transform.SimplifyInference(),
relay.transform.EliminateCommonSubexpr(),
relay.transform.FoldConstant(),
relay.transform.FoldScaleAxis(),
relay.transform.SimplifyExpr(),
relay.transform.CanonicalizeOps(),
relay.transform.InferType(),
relay.transform.FoldConstant(),
relay.transform.InferType()
])
with tvm.transform.PassContext(opt_level=4,instruments=[printIR]):
mod = seq(mod)
lib = relay.build(mod, target=target, params=params)
f = open(‘pass.txt’,‘w’)
f.write(‘relay.build---------->\n’ + str(printIR.getinfo()))
f.close()
This is the actual printed execution flow (because I only want to retake the pass flow of relayIR, so the following only shows the pass execution order of relayIR in the actual measurement, and TIR is not given)
relay.build---------->
[The meta data of the pass - pass name: sequential, opt_level: 0, required passes: []
, The meta data of the pass - pass name: InferType, opt_level: 0, required passes: []
, The meta data of the pass - pass name: Legalize, opt_level: 1, required passes: [ InferType, ]
, The meta data of the pass - pass name: InferType, opt_level: 0, required passes: []
, The meta data of the pass - pass name: InferType, opt_level: 0, required passes: []
, The meta data of the pass - pass name: SimplifyInference, opt_level: 0, required passes: [ InferType, ]
, The meta data of the pass - pass name: InferType, opt_level: 0, required passes: []
, The meta data of the pass - pass name: InferType, opt_level: 0, required passes: []
, The meta data of the pass - pass name: EliminateCommonSubexpr, opt_level: 3, required passes: [ InferType, ]
, The meta data of the pass - pass name: InferType, opt_level: 0, required passes: []
, The meta data of the pass - pass name: FoldConstant, opt_level: 2, required passes: []
, The meta data of the pass - pass name: InferType, opt_level: 0, required passes: []
, The meta data of the pass - pass name: FoldScaleAxis, opt_level: 0, required passes: []
, The meta data of the pass - pass name: InferType, opt_level: 0, required passes: []
, The meta data of the pass - pass name: BackwardFoldScaleAxis, opt_level: 3, required passes: [ InferType, ]
, The meta data of the pass - pass name: InferType, opt_level: 0, required passes: []
, The meta data of the pass - pass name: InferType, opt_level: 0, required passes: []
, The meta data of the pass - pass name: ForwardFoldScaleAxis, opt_level: 3, required passes: [ InferType, ]
, The meta data of the pass - pass name: InferType, opt_level: 0, required passes: []
, The meta data of the pass - pass name: FoldConstant, opt_level: 2, required passes: []
, The meta data of the pass - pass name: InferType, opt_level: 0, required passes: []
, The meta data of the pass - pass name: InferType, opt_level: 0, required passes: []
, The meta data of the pass - pass name: SimplifyExpr, opt_level: 0, required passes: [ InferType, ]
, The meta data of the pass - pass name: InferType, opt_level: 0, required passes: []
, The meta data of the pass - pass name: InferType, opt_level: 0, required passes: []
, The meta data of the pass - pass name: InferType, opt_level: 0, required passes: []
, The meta data of the pass - pass name: InferType, opt_level: 0, required passes: []
, The meta data of the pass - pass name: InferType, opt_level: 0, required passes: []
, The meta data of the pass - pass name: InferType, opt_level: 0, required passes: []
, The meta data of the pass - pass name: InferType, opt_level: 0, required passes: []
, The meta data of the pass - pass name: InferType, opt_level: 0, required passes: []
, The meta data of the pass - pass name: InferType, opt_level: 0, required passes: []
, The meta data of the pass - pass name: InferType, opt_level: 0, required passes: []
, The meta data of the pass - pass name: InferType, opt_level: 0, required passes: []
, The meta data of the pass - pass name: InferType, opt_level: 0, required passes: []
, The meta data of the pass - pass name: InferType, opt_level: 0, required passes: []
, The meta data of the pass - pass name: InferType, opt_level: 0, required passes: []
, The meta data of the pass - pass name: InferType, opt_level: 0, required passes: []
, The meta data of the pass - pass name: CanonicalizeOps, opt_level: 3, required passes: [ InferType, ]
, The meta data of the pass - pass name: InferType, opt_level: 0, required passes: []
, The meta data of the pass - pass name: InferType, opt_level: 0, required passes: []
, The meta data of the pass - pass name: FoldConstant, opt_level: 2, required passes: []
, The meta data of the pass - pass name: InferType, opt_level: 0, required passes: []
, The meta data of the pass - pass name: InferType, opt_level: 0, required passes: []
, The meta data of the pass - pass name: sequential, opt_level: 0, required passes: []
, The meta data of the pass - pass name: RemoveUnusedFunctions, opt_level: 1, required passes: []
, The meta data of the pass - pass name: ToBasicBlockNormalForm, opt_level: 1, required passes: []
, The meta data of the pass - pass name: sequential, opt_level: 0, required passes: []
, The meta data of the pass - pass name: InferType, opt_level: 0, required passes: []
, The meta data of the pass - pass name: Legalize, opt_level: 1, required passes: [ InferType, ]
, The meta data of the pass - pass name: InferType, opt_level: 0, required passes: []
, The meta data of the pass - pass name: InferType, opt_level: 0, required passes: []
, The meta data of the pass - pass name: Legalize, opt_level: 1, required passes: [ InferType, ]
, The meta data of the pass - pass name: InferType, opt_level: 0, required passes: []
, The meta data of the pass - pass name: InferType, opt_level: 0, required passes: []
, The meta data of the pass - pass name: Legalize, opt_level: 1, required passes: [ InferType, ]
, The meta data of the pass - pass name: InferType, opt_level: 0, required passes: []
, The meta data of the pass - pass name: InferType, opt_level: 0, required passes: []
, The meta data of the pass - pass name: SimplifyInference, opt_level: 0, required passes: [ InferType, ]
, The meta data of the pass - pass name: InferType, opt_level: 0, required passes: []
, The meta data of the pass - pass name: InferType, opt_level: 0, required passes: []
, The meta data of the pass - pass name: EliminateCommonSubexpr, opt_level: 3, required passes: [ InferType, ]
, The meta data of the pass - pass name: InferType, opt_level: 0, required passes: []
, The meta data of the pass - pass name: InferType, opt_level: 0, required passes: []
, The meta data of the pass - pass name: CombineParallelConv2d, opt_level: 4, required passes: [ InferType, ]
, The meta data of the pass - pass name: InferType, opt_level: 0, required passes: []
, The meta data of the pass - pass name: InferType, opt_level: 0, required passes: []
, The meta data of the pass - pass name: CombineParallelDense, opt_level: 4, required passes: [ InferType, ]
, The meta data of the pass - pass name: InferType, opt_level: 0, required passes: []
, The meta data of the pass - pass name: InferType, opt_level: 0, required passes: []
, The meta data of the pass - pass name: CombineParallelBatchMatmul, opt_level: 4, required passes:[InferType, ]
, The meta data of the pass - pass name: InferType, opt_level: 0, required passes: []
, The meta data of the pass - pass name: FoldConstant, opt_level: 2, required passes: []
, The meta data of the pass - pass name: InferType, opt_level: 0, required passes: []
, The meta data of the pass - pass name: FoldScaleAxis, opt_level: 0, required passes: []
, The meta data of the pass - pass name: InferType, opt_level: 0, required passes: []
, The meta data of the pass - pass name: BackwardFoldScaleAxis, opt_level: 3, required passes: [ InferType, ]
, The meta data of the pass - pass name: InferType, opt_level: 0, required passes: []
, The meta data of the pass - pass name: InferType, opt_level: 0, required passes: []
, The meta data of the pass - pass name: ForwardFoldScaleAxis, opt_level: 3, required passes: [ InferType, ]
, The meta data of the pass - pass name: InferType, opt_level: 0, required passes: []
, The meta data of the pass - pass name: FoldConstant, opt_level: 2, required passes: []
, The meta data of the pass - pass name: InferType, opt_level: 0, required passes: []
, The meta data of the pass - pass name: InferType, opt_level: 0, required passes: []
, The meta data of the pass - pass name: SimplifyExpr, opt_level: 0, required passes: [ InferType, ]
, The meta data of the pass - pass name: InferType, opt_level: 0, required passes: []
, The meta data of the pass - pass name: InferType, opt_level: 0, required passes: []
, The meta data of the pass - pass name: InferType, opt_level: 0, required passes: []
, The meta data of the pass - pass name: InferType, opt_level: 0, required passes: []
, The meta data of the pass - pass name: InferType, opt_level: 0, required passes: []
, The meta data of the pass - pass name: InferType, opt_level: 0, required passes: []
, The meta data of the pass - pass name: InferType, opt_level: 0, required passes: []
, The meta data of the pass - pass name: InferType, opt_level: 0, required passes: []
, The meta data of the pass - pass name: InferType, opt_level: 0, required passes: []
, The meta data of the pass - pass name: InferType, opt_level: 0, required passes: []
, The meta data of the pass - pass name: InferType, opt_level: 0, required passes: []
, The meta data of the pass - pass name: InferType, opt_level: 0, required passes: []
, The meta data of the pass - pass name: InferType, opt_level: 0, required passes: []
, The meta data of the pass - pass name: InferType, opt_level: 0, required passes: []
, The meta data of the pass - pass name: InferType, opt_level: 0, required passes: []
, The meta data of the pass - pass name: CanonicalizeCast, opt_level: 3, required passes: [ InferType, ]
, The meta data of the pass - pass name: InferType, opt_level: 0, required passes: []
, The meta data of the pass - pass name: InferType, opt_level: 0, required passes: []
, The meta data of the pass - pass name: CanonicalizeOps, opt_level: 3, required passes: [ InferType, ]
, The meta data of the pass - pass name: InferType, opt_level: 0, required passes: []
, The meta data of the pass - pass name: InferType, opt_level: 0, required passes: []
, The meta data of the pass - pass name: InferType, opt_level: 0, required passes: []
, The meta data of the pass - pass name: AlterOpLayout, opt_level: 3, required passes: [ InferType, ]
, The meta data of the pass - pass name: InferType, opt_level: 0, required passes: []
, The meta data of the pass - pass name: InferType, opt_level: 0, required passes: []
, The meta data of the pass - pass name: FastMath, opt_level: 4, required passes: [ InferType, ]
, The meta data of the pass - pass name: InferType, opt_level: 0, required passes: []
, The meta data of the pass - pass name: FoldConstant, opt_level: 2, required passes: []
, The meta data of the pass - pass name: InferType, opt_level: 0, required passes: []
, The meta data of the pass - pass name: InferType, opt_level: 0, required passes: []
, The meta data of the pass - pass name: SplitArgs, opt_level: 1, required passes: [ InferType, ]
, The meta data of the pass - pass name: InferType, opt_level: 0, required passes: []
, The meta data of the pass - pass name: PlanDevices, opt_level: 0, required passes: []
, The meta data of the pass - pass name: PlanDevicesRewrite, opt_level: 0, required passes: []
, The meta data of the pass - pass name: InferType, opt_level: 0, required passes: []
, The meta data of the pass - pass name: PlanDevicesCore, opt_level: 0, required passes: []
, The meta data of the pass - pass name: InferType, opt_level: 0, required passes: []
, The meta data of the pass - pass name: FuseOps, opt_level: 0, required passes: [ InferType, ]
, The meta data of the pass - pass name: InferType, opt_level: 0, required passes: []
, The meta data of the pass - pass name: InferType, opt_level: 0, required passes: []
, The meta data of the pass - pass name: InlineGlobals, opt_level: 1, required passes: []
, The meta data of the pass - pass name: InferType, opt_level: 0, required passes: []
, The meta data of the pass - pass name: LabelOps, opt_level: 1, required passes: []
, The meta data of the pass - pass name: InferType, opt_level: 0, required passes: []
, The meta data of the pass - pass name: sequential, opt_level: 0, required passes: []
, The meta data of the pass - pass name: RelayToTIRTargetHook, opt_level: 0, required passes: []
, The meta data of the pass - pass name: sequential, opt_level: 0, required passes: []
, The meta data of the pass - pass name: InferType, opt_level: 0, required passes: []
, The meta data of the pass - pass name: LowerTE, opt_level: 0, required passes: [ InferType, ]
, The meta data of the pass - pass name: LowerTensorExpr, opt_level: 0, required passes: []
, The meta data of the pass - pass name: sequential, opt_level: 0, required passes: []
, The meta data of the pass - pass name: tir.InjectPrefetch, opt_level: 0, required passes: []
, The meta data of the pass - pass name: tir.TextureFlatten, opt_level: 0, required passes: []
, The meta data of the pass - pass name: tir.StorageFlatten, opt_level: 0, required passes: []
, The meta data of the pass - pass name: tir.StorageFlatten_impl, opt_level: 0, required passes: []