leezu commented on a change in pull request #20262:
URL: https://github.com/apache/incubator-mxnet/pull/20262#discussion_r647239991



##########
File path: python/mxnet/gluon/block.py
##########
@@ -1064,41 +1065,13 @@ def __setattr__(self, name, value):
                 self._active = False
             self._clear_cached_op()
 
-    def _get_graph_v1(self, *args):
-        if not self._cached_graph:
-            flatten_args, self._in_format = _flatten(args, "input")
-            flatten_inputs = []
-            symbol_inputs = []
-            cnt = 0
-            real_arg_num = sum([ele is not None for ele in flatten_args])
-            if real_arg_num == 0:
-                raise ValueError('All args are None and we do not support such 
a case.'
-                                 ' Received args={}'.format(args))
-            for arg in flatten_args:
-                if arg is not None:
-                    if real_arg_num > 1:
-                        arg_sym = symbol.var('data{}'.format(cnt))
-                    else:
-                        arg_sym = symbol.var('data')
-                    if isinstance(arg, _mx_np.ndarray):
-                        arg_sym = arg_sym.as_np_ndarray()
-                    cnt += 1
-                    flatten_inputs.append(arg_sym)
-                    symbol_inputs.append(arg_sym)
-                else:
-                    flatten_inputs.append(None)
-            grouped_inputs = _regroup(flatten_inputs, self._in_format)
+    def __del__(self):
+        """Destructor"""
+        if self._cached_graph and not isinstance(self, SymbolBlock):
+            dc.clear(self._cached_graph[1])
+            dc.clear(self._cached_graph[0])

Review comment:
       Ok. The problem with the destructor is that it only takes effect upon 
destruction of the HybridBlock. However, the input ndarrays should already be 
released as soon as the deferred compute graph goes out of scope (which 
normally would happen after the first call to `forward` completed). To do that, 
I think you can update
   
   
https://github.com/apache/incubator-mxnet/blob/5722f8b38af58c5a296e46ca695bfaf7cff85040/src/imperative/imperative.cc#L344-L354
   
   to do a deep copy, and remove the DCInfo states (which reference the input 
ndarray) from the copy.




-- 
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]


Reply via email to