Lunderberg commented on code in PR #16602:
URL: https://github.com/apache/tvm/pull/16602#discussion_r1497780489
##########
python/tvm/relax/transform/lazy_transform_params.py:
##########
@@ -157,24 +159,60 @@ def transform(self, func: relax.Function) ->
relax.Function:
self.memory_free_insertion = liveness.var_liveness_end
# Step 3. rewrite get item and set item
- new_body = func.body
if self.fget_item is not None:
- new_body = LazyInputMutator(self, self.mod).visit_expr(new_body)
+ new_func = LazyInputMutator(self, self.mod).visit_expr(func)
+ new_body = new_func.body
if self.fset_item is not None:
+ leaf_outputs = {
+ expr: indices
+ for expr, indices in self.out_tuple_map.items()
+ if not isinstance(expr, relax.Var)
+ }
+ if leaf_outputs:
+ new_bindings = [
+ relax.VarBinding(
+ relax.Var("_", relax.ObjectStructInfo()),
+ relax.Call(
+ relax.ExternFunc(self.fset_item),
+ [*self.extra_set_item_params, index, expr],
+ None,
+ [relax.ObjectStructInfo()],
+ ),
+ )
+ for expr, indices in leaf_outputs.items()
+ for index in indices
Review Comment:
Absolutely. I think I prefer the chained iterators used in Rust or C#, but
Pythons list/dict/set comprehensions are a close second.
--
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]