Kh4L commented on a change in pull request #18405:
URL: https://github.com/apache/incubator-mxnet/pull/18405#discussion_r434298529



##########
File path: python/mxnet/symbol/symbol.py
##########
@@ -1554,7 +1554,37 @@ def optimize_for(self, backend, args=None, aux=None, 
ctx=None, **kwargs):
                     aux[idx] = NDArray(NDArrayHandle(new_aux_handle[i]))
                 else:
                     aux.append(NDArray(NDArrayHandle(new_aux_handle[i])))
-        return Symbol(out)
+
+        new_sym = Symbol(out)
+
+        if args is not None:
+            new_arg_names = new_sym.list_arguments()
+            deleted_arg_names = set([item for item in arg_names
+                                     if item not in set(new_arg_names)])
+            if isinstance(args, dict):
+                for a_n in deleted_arg_names:
+                    if a_n in args:
+                        args.pop(a_n)
+            elif isinstance(args, list):
+                indices_to_delete = [i for i, name in enumerate(arg_names) if 
name in deleted_arg_names]
+                for idx in reversed(indices_to_delete):

Review comment:
       I thought that using list comprehension to get the indices_to_delete was 
simpler, since the indices list have to be reversed.
   
   ```
   for idx, name  in reversed(list(enumerate(l))):
      if name in deleted_arg_names:
   ```
   
   we could do that, but I am not sure if it is more readable and faster.




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


Reply via email to