You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mxnet.apache.org by GitBox <gi...@apache.org> on 2019/06/07 21:48:44 UTC

[GitHub] [incubator-mxnet] jermainewang opened a new issue #15183: [Bug] Temporary autograd.Function object causes key deletion error

jermainewang opened a new issue #15183: [Bug] Temporary autograd.Function object causes key deletion error
URL: https://github.com/apache/incubator-mxnet/issues/15183
 
 
   ## Description
   When using `autograd.Function` to create custom operator, if the object is created in a local scope, and the input is not on the gradient chain, key error will be raised.
   
   ## Environment info (Required)
   
   ```
   Architecture:        x86_64
   CPU op-mode(s):      32-bit, 64-bit
   Byte Order:          Little Endian
   Address sizes:       46 bits physical, 48 bits virtual
   CPU(s):              8
   On-line CPU(s) list: 0-7
   Thread(s) per core:  2
   Core(s) per socket:  4
   Socket(s):           1
   NUMA node(s):        1
   Vendor ID:           GenuineIntel
   CPU family:          6
   Model:               62
   Model name:          Intel(R) Xeon(R) CPU E5-1620 v2 @ 3.70GHz
   Stepping:            4
   CPU MHz:             3691.009
   CPU max MHz:         3900.0000
   CPU min MHz:         1200.0000
   BogoMIPS:            7384.58
   Virtualization:      VT-x
   L1d cache:           32K
   L1i cache:           32K
   L2 cache:            256K
   L3 cache:            10240K
   NUMA node0 CPU(s):   0-7
   Flags:               fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx pdpe1gb rdtscp lm constant_tsc arch_perfmon pebs bts rep_good nopl xtopology nonstop_tsc cpuid aperfmperf pni pclmulqdq dtes64 monitor ds_cpl vmx smx est tm2 ssse3 cx16 xtpr pdcm pcid dca sse4_1 sse4_2 x2apic popcnt tsc_deadline_timer aes xsave avx f16c rdrand lahf_lm cpuid_fault epb pti ssbd ibrs ibpb stibp tpr_shadow vnmi flexpriority ept vpid fsgsbase smep erms xsaveopt dtherm ida arat pln pts flush_l1d
   ----------Python Info----------
   Version      : 3.7.2
   Compiler     : GCC 8.2.1 20181127
   Build        : ('default', 'Jan 10 2019 23:51:51')
   Arch         : ('64bit', '')
   ------------Pip Info-----------
   Version      : 18.1
   Directory    : /usr/lib/python3.7/site-packages/pip
   ----------MXNet Info-----------
   Version      : 1.5.0
   Directory    : /home/jermaine/.local/lib/python3.7/site-packages/mxnet
   Commit Hash   : 3f4f3d578c23388c850c1691e3e77ab5d6e81ee1
   ----------System Info----------
   Platform     : Linux-4.20.7-arch1-1-ARCH-x86_64-with-arch
   system       : Linux
   node         : wmj-broadway
   release      : 4.20.7-arch1-1-ARCH
   version      : #1 SMP PREEMPT Wed Feb 6 18:42:40 UTC 2019
   ----------Hardware Info----------
   machine      : x86_64
   processor    : 
   ----------Network Test----------
   Setting timeout: 10
   Timing for MXNet: https://github.com/apache/incubator-mxnet, DNS: 0.0004 sec, LOAD: 0.4747 sec.
   Timing for Gluon Tutorial(en): http://gluon.mxnet.io, DNS: 0.0022 sec, LOAD: 0.4775 sec.
   Timing for Gluon Tutorial(cn): https://zh.gluon.ai, DNS: 0.0015 sec, LOAD: 0.5216 sec.
   Timing for FashionMNIST: https://apache-mxnet.s3-accelerate.dualstack.amazonaws.com/gluon/dataset/fashion-mnist/train-labels-idx1-ubyte.gz, DNS: 0.0014 sec, LOAD: 0.7149 sec.
   Timing for PYPI: https://pypi.python.org/pypi/pip, DNS: 0.0015 sec, LOAD: 0.0694 sec.
   Timing for Conda: https://repo.continuum.io/pkgs/free/, DNS: 0.0012 sec, LOAD: 0.0365 sec.
   ```
   
   Package used (Python/R/Scala/Julia): Python
   
   ## Error Message:
   
   ```python
   Error in autograd.Function.delete: Traceback (most recent call last):
     File "/home/jermaine/.local/lib/python3.7/site-packages/mxnet/autograd.py", line 482, in delete_entry
       del Function._registry.ref_holder[key]
   KeyError: 0
   
   Error in autograd.Function.delete: Traceback (most recent call last):
     File "/home/jermaine/.local/lib/python3.7/site-packages/mxnet/autograd.py", line 482, in delete_entry
       del Function._registry.ref_holder[key]
   KeyError: 1
   
   Error in autograd.Function.delete: Traceback (most recent call last):
     File "/home/jermaine/.local/lib/python3.7/site-packages/mxnet/autograd.py", line 482, in delete_entry
       del Function._registry.ref_holder[key]
   KeyError: 2
   
   Error in autograd.Function.delete: Traceback (most recent call last):
     File "/home/jermaine/.local/lib/python3.7/site-packages/mxnet/autograd.py", line 482, in delete_entry
       del Function._registry.ref_holder[key]
   KeyError: 3
   
   Error in autograd.Function.delete: Traceback (most recent call last):
     File "/home/jermaine/.local/lib/python3.7/site-packages/mxnet/autograd.py", line 482, in delete_entry
       del Function._registry.ref_holder[key]
   KeyError: 4
   
   
   [[5. 5. 5. 5.]
    [5. 5. 5. 5.]
    [5. 5. 5. 5.]]
   <NDArray 3x4 @gpu(0)>
   ```
   
   ## Minimum reproducible example
   
   ```python
   import mxnet as mx
   
   class Foo(mx.autograd.Function):
       def __init__(self):
           super(Foo, self).__init__()
   
       def forward(self, X):
           return X + 1;
   
       def backward(self, dY):
           return dY
   
   with mx.autograd.record():
       X = mx.nd.zeros((3, 4), ctx=mx.gpu(0))
       #X.attach_grad()  # uncommenting this line works
       for i in range(5):
           f = Foo()
           X = f(X)
       print(X)
   ```
   
   ## Steps to reproduce
   
   Run the code.
   
   ## What have you tried to solve it?
   
   The problem is here:
   https://github.com/apache/incubator-mxnet/blob/bcff49888fdaae6b9922de4d4712d505cf33c596/python/mxnet/autograd.py#L488-L505
   
   Need to move L503 before L496. Otherwise, it is possible that the deletion callback will be called before the key is set to the dictionary.

----------------------------------------------------------------
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:
users@infra.apache.org


With regards,
Apache Git Services