Lunderberg commented on code in PR #15507:
URL: https://github.com/apache/tvm/pull/15507#discussion_r1289473732


##########
tests/python/relax/test_analysis.py:
##########
@@ -117,6 +117,53 @@ def main(x: R.Tensor((32, 32), "float32")) -> R.Tensor:
     tvm.ir.assert_structural_equal(optimized, GroundTruth["main"])
 
 
+def test_binding_block_remove_all_unused_without_dataflow():
+    @tvm.script.ir_module
+    class IdentityUnused:
+        @R.function
+        def main(x: R.Tensor((32, 32), "float32")) -> R.Tensor:
+            lv0 = x
+            unused0 = R.call_dps_packed("my_sigmoid", (x,), R.Tensor((32, 32), 
dtype="float32"))
+            unused1 = R.call_dps_packed(
+                "my_dps_func", (unused0,), R.Tensor((32, 32), dtype="float32")
+            )
+            z = R.call_packed("vm.builtin.copy", lv0, 
sinfo_args=(R.Tensor((32, 32), "float32")))
+            return z
+
+    optimized = remove_all_unused(IdentityUnused["main"])
+
+    GroundTruth = IdentityUnused

Review Comment:
   For this specific change, because (to my understanding), the 
`call_dps_packed` doesn't guarantee that it has no side effects.  Within a 
`R.dataflow()` environment, the expression may not have side effects, so it is 
safe to remove.
   
   For newly-unused objects, I believe that is handled by the `GetUnusedVars` 
function, called during construction.  It iteratively walks from the function 
outputs to the predecessors required to generate those outputs, finding the set 
of all variables required to generate the output.  Anything not within that set 
is considered unused and can be removed, even it occurs within another 
expression (because that expression is also going to be removed).



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

Reply via email to