dmlc / gluon-nlp

NLP made easy
https://nlp.gluon.ai/
Apache License 2.0
2.56k stars 538 forks source link

FastText embeddings not working on MxNET 1.5.1/GluonNLP 0.8.1 #981

Closed mohammedkhalilia closed 4 years ago

mohammedkhalilia commented 4 years ago

Description

Calling gluonnlp.model.train.FasttextEmbeddingModel.load_fasttext_format() generates an error when using MxNET 1.5.1 and GluonNLP 0.8.1. But the call works when using MxNET 1.4.1 and GluonNLP 0.7.1.

Error Message

Traceback (most recent call last):
  File "/home/khallia/workspace/CompMedNER/bin/train.py", line 66, in <module>
    main()
  File "/home/khallia/workspace/CompMedNER/bin/train.py", line 38, in main
    Vocab(sentences, wordvectors=config.word_vecs, bert_vocab=config.bert_vocab)
  File "/home/khallia/workspace/CompMedNER/src/vocab.py", line 29, in __init__
    Vocab.word = self.create_word_vocab()
  File "/home/khallia/workspace/CompMedNER/src/vocab.py", line 120, in create_word_vocab
    model = nlp.model.train.FasttextEmbeddingModel.load_fasttext_format(self.wordvectors)
  File "/env/mx_1.5.1_gnlp_0.8.1/lib/python3.5/site-packages/gluonnlp/model/train/embedding.py", line 278, in load_fasttext_format
    self.weight.set_data(nd.array(matrix))
  File "/env/mx_1.5.1_gnlp_0.8.1/lib/python3.5/site-packages/mxnet/ndarray/utils.py", line 146, in array
    return _array(source_array, ctx=ctx, dtype=dtype)
  File "/env/mx_1.5.1_gnlp_0.8.1/lib/python3.5/site-packages/mxnet/ndarray/ndarray.py", line 2505, in array
    arr[:] = source_array
  File "/env/mx_1.5.1_gnlp_0.8.1/lib/python3.5/site-packages/mxnet/ndarray/ndarray.py", line 449, in __setitem__
    self._set_nd_basic_indexing(key, value)
  File "/env/mx_1.5.1_gnlp_0.8.1/lib/python3.5/site-packages/mxnet/ndarray/ndarray.py", line 715, in _set_nd_basic_indexing
    self._sync_copyfrom(value)
  File "/env/mx_1.5.1_gnlp_0.8.1/lib/python3.5/site-packages/mxnet/ndarray/ndarray.py", line 881, in _sync_copyfrom
    ctypes.c_size_t(source_array.size)))
  File "/env/mx_1.5.1_gnlp_0.8.1/lib/python3.5/site-packages/mxnet/base.py", line 253, in check_call
    raise MXNetError(py_str(_LIB.MXGetLastError()))
mxnet.base.MXNetError: [11:32:50] src/ndarray/ndarray_function.cc:51: Check failed: size == to->Size() (-585876896 vs. 3709090400) : copying size mismatch, from: 18446744071366044032 bytes, to: 14836361600 bytes.
Stack trace:
  [bt] (0) /env/mx_1.5.1_gnlp_0.8.1/lib/python3.5/site-packages/mxnet/libmxnet.so(+0x4b04cb) [0x7f350d5a34cb]
  [bt] (1) /env/mx_1.5.1_gnlp_0.8.1/lib/python3.5/site-packages/mxnet/libmxnet.so(+0x281c85b) [0x7f350f90f85b]
  [bt] (2) /env/mx_1.5.1_gnlp_0.8.1/lib/python3.5/site-packages/mxnet/libmxnet.so(mxnet::NDArray::SyncCopyFromCPU(void const*, unsigned long) const+0x27c) [0x7f350f89b59c]
  [bt] (3) /env/mx_1.5.1_gnlp_0.8.1/lib/python3.5/site-packages/mxnet/libmxnet.so(MXNDArraySyncCopyFromCPU+0x2b) [0x7f350f61790b]
  [bt] (4) /env/mx_1.5.1_gnlp_0.8.1/lib/python3.5/lib-dynload/_ctypes.cpython-35m-x86_64-linux-gnu.so(ffi_call_unix64+0x4c) [0x7f354255ee20]
  [bt] (5) /env/mx_1.5.1_gnlp_0.8.1/lib/python3.5/lib-dynload/_ctypes.cpython-35m-x86_64-linux-gnu.so(ffi_call+0x2eb) [0x7f354255e88b]
  [bt] (6) /env/mx_1.5.1_gnlp_0.8.1/lib/python3.5/lib-dynload/_ctypes.cpython-35m-x86_64-linux-gnu.so(_ctypes_callproc+0x49a) [0x7f354255901a]
  [bt] (7) /env/mx_1.5.1_gnlp_0.8.1/lib/python3.5/lib-dynload/_ctypes.cpython-35m-x86_64-linux-gnu.so(+0x9fcb) [0x7f354254cfcb]
  [bt] (8) /env/mx_1.5.1_gnlp_0.8.1/bin/python3(PyObject_Call+0x47) [0x5c20e7]

To Reproduce

import mxnet as mx
import gluonnlp as nlp
wordvectors = 'BioWordVec_PubMed_MIMICIII_d200.bin'
model = nlp.model.train.FasttextEmbeddingModel.load_fasttext_format(wordvectors)

Steps to reproduce

  1. Download the embeddings from here: https://ftp.ncbi.nlm.nih.gov/pub/lu/Suppl/BioSentVec/BioWordVec_PubMed_MIMICIII_d200.bin
  2. Run the code snippet above.

Environment

Architecture:          x86_64
CPU op-mode(s):        32-bit, 64-bit
Byte Order:            Little Endian
CPU(s):                64
On-line CPU(s) list:   0-63
Thread(s) per core:    2
Core(s) per socket:    16
Socket(s):             2
NUMA node(s):          2
Vendor ID:             GenuineIntel
CPU family:            6
Model:                 79
Model name:            Intel(R) Xeon(R) CPU E5-2686 v4 @ 2.30GHz
Stepping:              1
CPU MHz:               2699.984
CPU max MHz:           3000.0000
CPU min MHz:           1200.0000
BogoMIPS:              4600.15
Hypervisor vendor:     Xen
Virtualization type:   full
L1d cache:             32K
L1i cache:             32K
L2 cache:              256K
L3 cache:              46080K
NUMA node0 CPU(s):     0-15,32-47
NUMA node1 CPU(s):     16-31,48-63
Flags:                 fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush mmx fxsr sse sse2 ht syscall nx pdpe1gb rdtscp lm constant_tsc arch_perfmon rep_good nopl xtopology nonstop_tsc aperfmperf pni pclmulqdq monitor est ssse3 fma cx16 pcid sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand hypervisor lahf_lm abm 3dnowprefetch invpcid_single pti fsgsbase bmi1 hle avx2 smep bmi2 erms invpcid rtm rdseed adx xsaveopt ida
----------Python Info----------
Version      : 3.5.2
Compiler     : GCC 5.4.0 20160609
Build        : ('default', 'Nov 12 2018 13:43:14')
Arch         : ('64bit', 'ELF')
------------Pip Info-----------
Version      : 19.3
Directory    : /env/mx_1.5.1_gnlp_0.8.1/lib/python3.5/site-packages/pip
----------MXNet Info-----------
Version      : 1.5.1
Directory    : /env/mx_1.5.1_gnlp_0.8.1/lib/python3.5/site-packages/mxnet
Num GPUs     : 8
Commit Hash   : c9818480680f84daa6e281a974ab263691302ba8
----------System Info----------
Platform     : Linux-4.4.0-1090-aws-x86_64-with-Ubuntu-16.04-xenial
system       : Linux
node         : ip-172-31-30-122
release      : 4.4.0-1090-aws
version      : #101-Ubuntu SMP Fri Aug 2 15:21:01 UTC 2019
----------Hardware Info----------
machine      : x86_64
processor    : x86_64
----------Network Test----------
Setting timeout: 10
Timing for GluonNLP GitHub: https://github.com/dmlc/gluon-nlp, DNS: 0.0023 sec, LOAD: 0.4338 sec.
Timing for FashionMNIST: https://repo.mxnet.io/gluon/dataset/fashion-mnist/train-labels-idx1-ubyte.gz, DNS: 0.0919 sec, LOAD: 0.0523 sec.
Timing for D2L (zh-cn): http://zh.d2l.ai, DNS: 0.0060 sec, LOAD: 0.0718 sec.
Timing for D2L: http://d2l.ai, DNS: 0.0155 sec, LOAD: 0.0264 sec.
Timing for MXNet: https://github.com/apache/incubator-mxnet, DNS: 0.0003 sec, LOAD: 0.4836 sec.
Timing for PYPI: https://pypi.python.org/pypi/pip, DNS: 0.0024 sec, LOAD: 0.3733 sec.
Timing for Conda: https://repo.continuum.io/pkgs/free/, DNS: 0.0127 sec, LOAD: 0.0653 sec.
Timing for GluonNLP: http://gluon-nlp.mxnet.io, DNS: 0.1836 sec, LOAD: 0.2207 sec.
leezu commented 4 years ago

The model is very large and requires large tensor support in MXNet. Large tensor support was enabled in MXNet 1.4 by default but disabled due to performance regressions (https://github.com/apache/incubator-mxnet/issues/14496 https://github.com/apache/incubator-mxnet/issues/14790). For MXNet 1.5 you can build MXNet from source and enable large tensor support via a compile time flag: https://github.com/apache/incubator-mxnet/blob/df4125aa1d4ef013e68e6adf3738dabdb1b52865/NEWS.md#large-tensor-support The team is currently working on addressing the regression and enable large tensor support by default again (https://github.com/apache/incubator-mxnet/issues/15589#issuecomment-512921102)