You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tvm.apache.org by GitBox <gi...@apache.org> on 2022/01/27 01:00:08 UTC

[GitHub] [tvm] mbs-octoml commented on a change in pull request #10078: [Relay] fix incorrect binding of Lets in ANF conversion

mbs-octoml commented on a change in pull request #10078:
URL: https://github.com/apache/tvm/pull/10078#discussion_r793171137



##########
File path: src/relay/transforms/to_a_normal_form.cc
##########
@@ -223,6 +223,17 @@ class Fill : ExprFunctor<Expr(const Expr&, const Var&)>, private transform::Lexi
     bool not_included = include_set_ && include_set_->find(orig) == include_set_->end();
     if (!v.defined() && not_included) {
       return annotated_expr;
+    } else if (const LetNode* let = AsIgnoringOnDevice<LetNode>(now)) {
+      // Instead of making a nested binding "let var = (let x = ...; bindings...; body)", we push
+      // the inner bindings into the outer scope and bind body to var, giving
+      // "let x = ...; bindings...; let var = body;" as the resulting bindings.
+      Expr e = GetRef<Expr>(let);
+      while (const LetNode* inner_let = AsIgnoringOnDevice<LetNode>(e)) {
+        GetScope(orig)->let_list->Push(inner_let->var, inner_let->value);

Review comment:
       I believe (and again, sorry this is awkward -- this is why Lily is chipping away at virtual_device_) you'll need a MaybeOnDevice on the inner_let->value. Basically, we have to preserve any device information on the let-bound values, you can't unwrap then ignore.
   
   I'd not be at all surprised if no tests pick this up. In an ideal world every device aware pass would have unit tests exercising it's handling of devices.

##########
File path: tests/python/relay/test_pass_to_a_normal_form.py
##########
@@ -198,12 +218,4 @@ def test_gradient_if():
 
 
 if __name__ == "__main__":
-    test_explicit_bound()
-    test_order()
-    test_if()
-    test_recursion()
-    test_ref()
-    test_let()
-    test_nat_add()
-    test_function()
-    test_gradient_if()
+    pytest.main([__file__])

Review comment:
       since you're there can you indulge my OCD and write:
       import sys
       import pytest
   
       sys.exit(pytest.main([__file__] + sys.argv[1:]))
   

##########
File path: tests/python/relay/test_pass_to_a_normal_form.py
##########
@@ -94,6 +95,25 @@ def test_if():
     assert tvm.ir.structural_equal(anf, expected_output)
 
 
+def test_let_as_subexpr():

Review comment:
       Here's where you could throw an on_device annotation in.
     on_device(expr, virtual_device=..., constrain_result=True)
    




-- 
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-unsubscribe@tvm.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org