junrushao1994 commented on issue #4432: [Relay][Pass] Fix lambda lift pass for recursive call URL: https://github.com/apache/incubator-tvm/pull/4432#issuecomment-559210724 @MarisaKirisame Thank you for your reply! I am very ignorant in this field, and super interested in learning more. Would you mind suggesting better ideas if you have time? **Definition(?).** I was thinking, lambda lifting should be a pass that eliminates free variables and lifting lambdas to global scope. Like what is described in [Wikipedia](https://en.wikipedia.org/wiki/Lambda_lifting). **Simplest case.** If a lambda can be converted is only used inside relay.call, then it is safe to lift it to a tuple (global_var_lifted, captured_0, captured_1, ...). Mutual recursion works in this case as well. **More complicated case.** However, in the general case, when lambda is first-class supported (like relay), it could be hard to lift them, because when adjusting call sites, type mismatch could happen (consider conditionally bind 2 lambdas to a variable, which might capture different things). **Your suggestion.** As you suggested, in this case, make a "global function returning that closure can be used to implement returning closure." This is one of the solution that I was thinking before. It works, but I am not sure if it really helps (because closure still exists). **What Wikipedia says.** In the section "algorithm", it says: > If the language has closures as first-class objects that can be passed as arguments or returned from other functions, the closure will need to be represented by a data structure that captures the bindings of the free variables. **Why I ask this** If we are able to eliminate those lambdas, to "some data structure", then we are able to do autodiff without reference...
---------------------------------------------------------------- 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] With regards, Apache Git Services
