Lunderberg commented on code in PR #16602:
URL: https://github.com/apache/tvm/pull/16602#discussion_r1497777937
##########
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
+ ]
+ new_body = relax.SeqExpr(
+ [*new_body.blocks, relax.BindingBlock(new_bindings)],
new_body.body
+ )
+
new_body = LazyOutputMutator(self, self.mod).visit_expr(new_body)
# Step 4. Add parameters of get_item and set_item (except index) to
the function.
- params = [*self.extra_get_item_params, *self.extra_set_item_params]
+ params = [
+ *func.params[:num_input],
+ *self.extra_get_item_params,
+ *self.extra_set_item_params,
+ ]
# Step 5. Find all shape parameters that should be retained as
# parameters.
symbolic_vars = relax.analysis.defined_symbolic_vars(func)
if symbolic_vars:
+
+ def unpack_sinfo(sinfo):
+ if isinstance(sinfo, relax.TupleStructInfo):
+ for field in sinfo.fields:
+ yield from unpack_sinfo(field)
Review Comment:
Thank you, and I really like using `yield from` for providing flattened
results from a graph structures. This way, the result of
`unpack_sinfo(top_level.struct_info)` can be collected into a list, but there
aren't any temporary lists made along the way.
--
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]