samskalicky commented on a change in pull request #18405: URL: https://github.com/apache/incubator-mxnet/pull/18405#discussion_r448576383
########## File path: python/mxnet/gluon/block.py ########## @@ -1073,8 +1060,35 @@ def _build_cache(self, *args): for name in out.list_auxiliary_states()} # Partition the graph. out = out.optimize_for(self._backend, arg_dict, aux_dict, ctx, **self._backend_opts) + # BFS to delete the delete args/aux from the block Params and its children's Params + input_names = out.list_inputs() + queue = [self] + while len(queue) > 0: + curr_block = queue.pop(0) + curr_params = curr_block.params if isinstance(curr_block.params, dict) else curr_block.params._params + curr_params_names = list(curr_params.keys()) + for k in curr_params_names: + if k not in input_names: + curr_params.pop(k) Review comment: instead of deleting and modifying the Python-level state, consider keeping an internal copy of collect_params and modifying that. Would also need to modify export API to use this internal copy if set. ---------------------------------------------------------------- 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: us...@infra.apache.org