masahi opened a new pull request #9721: URL: https://github.com/apache/tvm/pull/9721
As discussed in https://discuss.tvm.apache.org/t/byoc-cutlass-dealing-with-constants-in-c-source-gen-based-byoc/11362, constant binding in C-source based BYOC is a common problem. So far, I've been avoiding this problem by **not** running `bind_params` and `FoldConstant` before partitioning. However, to convert `conv2d -> batch_norm -> relu` into `conv2d -> bias_add -> relu`, constant folding is necessary. This PR is my proposal to allow batch norm fusion while avoiding constants binding. The change is simple and works perfectly for my use case. Before `PartitionGraph`: ``` %26 = annotation.compiler_begin(%input0, compiler="cutlass") /* ty=Tensor[(8, 3, 224, 224), float32] */; %27 = annotation.compiler_begin(meta[relay.Constant][0] /* ty=Tensor[(64, 3, 7, 7), float32] */, compiler="cutlass") /* ty=Tensor[(64, 3, 7, 7), float32] */; %28 = annotation.compiler_begin(meta[relay.Constant][1] /* ty=Tensor[(64, 1, 1), float32] */, compiler="cutlass") /* ty=Tensor[(64, 1, 1), float32] */; %29 = fn (%FunctionVar_8_01: Tensor[(8, 3, 224, 224), float32], %FunctionVar_8_11: Tensor[(64, 3, 7, 7), float32], %FunctionVar_8_21: Tensor[(64, 1, 1), float32], PartitionedFromPattern="nn.conv2d_add_nn.relu_", Composite="cutlass.conv2d_bias_relu") -> Tensor[(8, 64, 112, 112), float32] { ... }; %30 = %29(%26, %27, %28) /* ty=Tensor[(8, 64, 112, 112), float32] */; ``` After `PartitionGraph` with `bind_constants = False`: ``` def @main(%input0: Tensor[(8, 3, 224, 224), float32]) -> Tensor[(8, 1000), float32] { %0 = @tvmgen_default_cutlass_main_0(%input0, meta[relay.Constant][0] /* ty=Tensor[(64, 3, 7, 7), float32] */, meta[relay.Constant][1] /* ty=Tensor[(64, 1, 1), float32] */) /* ty=Tensor[(8, 64, 112, 112), float32] */; ... } def @tvmgen_default_cutlass_main_0(%cutlass_0_i0: Tensor[(8, 3, 224, 224), float32], %cutlass_0_i1: Tensor[(64, 3, 7, 7), float32], %cutlass_0_i2: Tensor[(64, 1, 1), float32], Inline=1, Compiler="cutlass", global_symbol="tvmgen_default_cutlass_main_0", Primitive=1) -> Tensor[(8, 64, 112, 112), float32] { %43 = fn (%FunctionVar_8_0: Tensor[(8, 3, 224, 224), float32], %FunctionVar_8_1: Tensor[(64, 3, 7, 7), float32], %FunctionVar_8_2: Tensor[(64, 1, 1), float32], PartitionedFromPattern="nn.conv2d_add_nn.relu_", Composite="cutlass.conv2d_bias_relu") -> Tensor[(8, 64, 112, 112), float32] { ... }; %43(%cutlass_0_i0, %cutlass_0_i1, %cutlass_0_i2) /* ty=Tensor[(8, 64, 112, 112), float32] */ } ``` -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: commits-unsubscr...@tvm.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org