Tantalus13A98B5F commented on a change in pull request #8605:
URL: https://github.com/apache/tvm/pull/8605#discussion_r681675196
##########
File path: src/relay/transforms/convert_sparse_conv2d.cc
##########
@@ -155,6 +316,18 @@ Pass Conv2dToSparse(const Array<ObjectRef>& weight_name,
const Array<Array<PrimE
TVM_REGISTER_GLOBAL("relay._transform.Conv2dToSparse").set_body_typed(Conv2dToSparse);
+
+Pass Conv2dToSparse2(const String& layout, int kernel_size, int blockH, int
blockW, double sparse_thresh) {
+ runtime::TypedPackedFunc<Function(Function, IRModule, PassContext)>
pass_func =
+ [=](Function f, IRModule m, PassContext pc) {
+ auto f0 = Downcast<Function>(Conv2dToSparse2(f, layout, kernel_size,
blockH, blockW, sparse_thresh));
+ return f0;
+ };
+ return CreateFunctionPass(pass_func, 5, "Conv2dToSparse2",
{"DeadCodeElimination"});
+}
+
+TVM_REGISTER_GLOBAL("relay._transform.Conv2dToSparse2").set_body_typed(Conv2dToSparse2);
Review comment:
Sorry for the confusion. The difference lies in
1. whether the model to convert is freezed, and
2. whether transforming the weight into sparse format is included in the
pass.
The original pass aims to transform models whose params are not binded, so
that they still have names. Params are transformed to sparse formats prior to
running the pass, and then pass is executed to replace convolutions with sparse
counterparts, with the knowledge of names and shapes of sparse data.
The new pass aims to transform models with params binded. We find it useful
when working with onnx, where specifying `freeze_params=True` is often desired.
Data are inlined as `ConstantNode`s and have no names, thus param
transformation and op replacement are both conducted in the new pass.
Due to the fundamentally different requirements to serve, I don't think the
two passes can be easily merged. However, if one single pass is desired, I
think the new pass would offer greater flexibility, as models can be easily
freezed, but not vice versa.
More documentation comments will be added in a later commit. Besides,
suggestions on merging, naming, and placement are definitely welcomed.
--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]