zleyk22 opened a new issue #18078: A possible bug when computing a gradient vector URL: https://github.com/apache/incubator-mxnet/issues/18078 ## Description I investigated the MXNet C++ code and noticed that the gradient of the input array `[[x, y]]` is computed as `[[(x*y)/x, (x*y)/y]]`. Therefore, if `y` is zero, then we always get `nan` as the second element of the array. Is it a bug? ### Error Message No error message ## To Reproduce This is a python program I run: ``` import mxnet as mx sym = mx.symbol.prod(data=mx.symbol.Variable("in"), axis=(1)) exec = sym.bind(mx.cpu(0), {"in":mx.nd.array([[4, 0]])}, {"in":mx.nd.array([[9, 9]])}) out = exec.forward()[0] exec.backward(mx.nd.ones(out.shape)) print('-- Gradient:') print(exec.grad_dict['in']) ``` I get this output: ``` -- Gradient: [[ 0. nan]] <NDArray 1x2 @cpu(0)> ``` ## Environment We recommend using our script for collecting the diagnositc information. Run the following command and paste the outputs below: ``` curl --retry 10 -s https://raw.githubusercontent.com/dmlc/gluon-nlp/master/tools/diagnose.py | python ``` ### paste outputs here ``` ----------Python Info---------- Version : 3.7.7 Compiler : Clang 11.0.0 (clang-1100.0.33.17) Build : ('default', 'Mar 10 2020 15:43:03') Arch : ('64bit', '') ------------Pip Info----------- Version : 20.0.2 Directory : /usr/local/lib/python3.7/site-packages/pip ----------MXNet Info----------- Version : 1.6.0 Directory : /Users/zibi22/MXNet-1.6.0/python/mxnet Num GPUs : 0 Hashtag not found. Not installed from pre-built package. ----------System Info---------- Platform : Darwin-18.7.0-x86_64-i386-64bit system : Darwin node : zibi22maclap release : 18.7.0 version : Darwin Kernel Version 18.7.0: Thu Jan 23 06:52:12 PST 2020; root:xnu-4903.278.25~1/RELEASE_X86_64 ----------Hardware Info---------- machine : x86_64 processor : i386 b'machdep.cpu.brand_string: Intel(R) Core(TM) i7-7820HQ CPU @ 2.90GHz' b'machdep.cpu.features: FPU VME DE PSE TSC MSR PAE MCE CX8 APIC SEP MTRR PGE MCA CMOV PAT PSE36 CLFSH DS ACPI MMX FXSR SSE SSE2 SS HTT TM PBE SSE3 PCLMULQDQ DTES64 MON DSCPL VMX SMX EST TM2 SSSE3 FMA CX16 TPR PDCM SSE4.1 SSE4.2 x2APIC MOVBE POPCNT AES PCID XSAVE OSXSAVE SEGLIM64 TSCTMR AVX1.0 RDRAND F16C' b'machdep.cpu.leaf7_features: RDWRFSGS TSC_THREAD_OFFSET SGX BMI1 HLE AVX2 SMEP BMI2 ERMS INVPCID RTM FPU_CSDS MPX RDSEED ADX SMAP CLFSOPT IPT MDCLEAR TSXFA IBRS STIBP L1DF SSBD' b'machdep.cpu.extfeatures: SYSCALL XD 1GBPAGE EM64T LAHF LZCNT PREFETCHW RDTSCP TSCI' ----------Network Test---------- Setting timeout: 10 Timing for MXNet: https://github.com/apache/incubator-mxnet, DNS: 0.0756 sec, LOAD: 0.9306 sec. Timing for GluonNLP GitHub: https://github.com/dmlc/gluon-nlp, DNS: 0.0006 sec, LOAD: 0.8133 sec. Timing for GluonNLP: http://gluon-nlp.mxnet.io, DNS: 0.0008 sec, LOAD: 0.3825 sec. Timing for D2L: http://d2l.ai, DNS: 0.0006 sec, LOAD: 0.1266 sec. Timing for D2L (zh-cn): http://zh.d2l.ai, DNS: 0.0008 sec, LOAD: 0.1243 sec. Timing for FashionMNIST: https://repo.mxnet.io/gluon/dataset/fashion-mnist/train-labels-idx1-ubyte.gz, DNS: 0.0009 sec, LOAD: 0.3131 sec. Timing for PYPI: https://pypi.python.org/pypi/pip, DNS: 0.0731 sec, LOAD: 0.9831 sec. Error open Conda: https://repo.continuum.io/pkgs/free/, HTTP Error 403: Forbidden, DNS finished in 0.00061798095703125 sec. ```
---------------------------------------------------------------- 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] With regards, Apache Git Services
