apache / mxnet

Lightweight, Portable, Flexible Distributed/Mobile Deep Learning with Dynamic, Mutation-aware Dataflow Dep Scheduler; for Python, R, Julia, Scala, Go, Javascript and more
https://mxnet.apache.org
Apache License 2.0
20.78k stars 6.79k forks source link

[bug] Incorrect Indexed Assignment #17342

Open kshitij12345 opened 4 years ago

kshitij12345 commented 4 years ago

Description

Incorrect output when assigning with mask_array

To Reproduce

import mxnet as mx
import numpy as np

def test_replace(array_constructor):
    array = [[0.0, 2]]
    x = array_constructor(array)
    zero_mask = x == 0.0
    print(zero_mask)
    x[zero_mask] = 1e-6
    print(x)

test_replace(mx.nd.array)
print('*' * 8)
test_replace(np.array)

Output

[[1. 0.]]
<NDArray 1x2 @cpu(0)>

[[1.e-06 1.e-06]]
<NDArray 1x2 @cpu(0)>
********
[[ True False]]
[[1.e-06 2.e+00]]

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

----------Python Info----------
Version      : 3.6.8
Compiler     : GCC 7.3.0
Build        : ('default', 'Dec 30 2018 01:22:34')
Arch         : ('64bit', '')
------------Pip Info-----------
Version      : 19.3.1
Directory    : /home/user/Desktop/Repositories/mxnet/ENV/lib/python3.6/site-packages/pip
----------MXNet Info-----------
Version      : 1.6.0
Directory    : /home/user/Desktop/Repositories/mxnet/incubator-mxnet/python/mxnet
Num GPUs     : 1
Hashtag not found. Not installed from pre-built package.
----------System Info----------
Platform     : Linux-4.15.0-74-generic-x86_64-with-debian-buster-sid
system       : Linux
node         : user-Predator-PH315-51
release      : 4.15.0-74-generic
version      : #84-Ubuntu SMP Thu Dec 19 08:06:28 UTC 2019
----------Hardware Info----------
machine      : x86_64
processor    : x86_64
Architecture:        x86_64
CPU op-mode(s):      32-bit, 64-bit
Byte Order:          Little Endian
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:               158
Model name:          Intel(R) Core(TM) i5-8300H CPU @ 2.30GHz
Stepping:            10
CPU MHz:             840.639
CPU max MHz:         4000.0000
CPU min MHz:         800.0000
BogoMIPS:            4608.00
Virtualization:      VT-x
L1d cache:           32K
L1i cache:           32K
L2 cache:            256K
L3 cache:            8192K
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 art arch_perfmon pebs bts rep_good nopl xtopology nonstop_tsc cpuid aperfmperf tsc_known_freq pni pclmulqdq dtes64 monitor ds_cpl vmx est tm2 ssse3 sdbg fma cx16 xtpr pdcm pcid sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand lahf_lm abm 3dnowprefetch cpuid_fault epb invpcid_single pti ssbd ibrs ibpb stibp tpr_shadow vnmi flexpriority ept vpid fsgsbase tsc_adjust bmi1 avx2 smep bmi2 erms invpcid mpx rdseed adx smap clflushopt intel_pt xsaveopt xsavec xgetbv1 xsaves dtherm ida arat pln pts hwp hwp_notify hwp_act_window hwp_epp md_clear flush_l1d
----------Network Test----------
Setting timeout: 10
Timing for MXNet: https://github.com/apache/incubator-mxnet, DNS: 0.0176 sec, LOAD: 0.9623 sec.
Timing for GluonNLP GitHub: https://github.com/dmlc/gluon-nlp, DNS: 0.0012 sec, LOAD: 0.7134 sec.
Timing for GluonNLP: http://gluon-nlp.mxnet.io, DNS: 0.3052 sec, LOAD: 1.1265 sec.
Timing for D2L: http://d2l.ai, DNS: 0.0560 sec, LOAD: 0.3511 sec.
Timing for D2L (zh-cn): http://zh.d2l.ai, DNS: 0.0683 sec, LOAD: 0.3417 sec.
Timing for FashionMNIST: https://repo.mxnet.io/gluon/dataset/fashion-mnist/train-labels-idx1-ubyte.gz, DNS: 0.0578 sec, LOAD: 1.0116 sec.
haojin2 commented 4 years ago

@kshitij12345 This has been addressed in the new np module:

from mxnet import np, npx
npx.set_np()
import numpy as onp

def test_replace(array_constructor):
    array = [[0.0, 2]]
    x = array_constructor(array)
    zero_mask = x == 0.0
    print(zero_mask)
    x[zero_mask] = 1e-6
    print(x)

test_replace(np.array)
print('*' * 8)
test_replace(onp.array)

running this on the latest master:

[[ True False]]
[[1.e-06 2.e+00]]
********
[[ True False]]
[[1.e-06 2.e+00]]
kshitij12345 commented 4 years ago

@haojin2 Noted.

However shouldn't there be some sort of deprecation warning or anything. Cause right now it silently computes the incorrect result.