merrymercy commented on a change in pull request #7635:
URL: https://github.com/apache/tvm/pull/7635#discussion_r601993137



##########
File path: tutorials/auto_scheduler/tune_network_arm.py
##########
@@ -127,6 +132,23 @@ def get_network(name, batch_size, layout="NHWC", 
dtype="float32"):
             net.params, relay.nn.softmax(net.body), None, net.type_params, 
net.attrs
         )
         mod = tvm.IRModule.from_expr(net)
+    elif name == "mlp":
+        mod, params = relay.testing.mlp.get_workload(
+            batch_size=batch_size, dtype=dtype, image_shape=image_shape, 
num_classes=1000
+        )
+    else:
+        raise ValueError("Network not found.")
+
+    if use_sparse:
+        bs_r = 1
+        bs_c = 1
+        sparsity = 0.85
+        mod, params = ddo.simplify_fc_transpose.convert(mod["main"], params)
+        # This is a test workload that manually transforms a dense model to 
sparse
+        params = random_sparse_dense_params(mod, params, bs_r=bs_r, bs_c=bs_c, 
density=1 - sparsity)
+        # Currently we only support to conver dense matmul to sparse dense 
matmul
+        mod, params = ddo.bsr_dense.convert(mod, params, (bs_r, bs_c), 
sparsity_threshold=0.8)
+        mod = tvm.IRModule.from_expr(mod)

Review comment:
       Because `use_sparse` only works for MLP, we should not expose it as a 
top-level argument of `get_network`. We can move all sparse-related code into a 
single branch. In this way, readers who are not interested in sparse-related 
stuff only need to ignore this branch instead of ignoring code in multiple 
places.
   
   ```suggestion
       elif name == "sparse-mlp":
           from tvm.relay import data_dep_optimization as do
           from tvm.topi.sparse.utils import random_sparse_dense_params
   
           mod, params = relay.testing.mlp.get_workload(
               batch_size=batch_size, dtype=dtype, image_shape=image_shape, 
num_classes=1000
           )    
           bs_r = 1
           bs_c = 1
           sparsity = 0.85
           mod, params = ddo.simplify_fc_transpose.convert(mod["main"], params)
           # This is a test workload that manually transforms a dense model to 
sparse
           params = random_sparse_dense_params(mod, params, bs_r=bs_r, 
bs_c=bs_c, density=1 - sparsity)
           # Currently we only support to conver dense matmul to sparse dense 
matmul
           mod, params = ddo.bsr_dense.convert(mod, params, (bs_r, bs_c), 
sparsity_threshold=0.8)
           mod = tvm.IRModule.from_expr(mod)
       else:
           raise ValueError("Network not found.")
   ```




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

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to