dmlc / gluon-nlp

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

[Bug][Conversion Tools] mxnet block.py Overriding Parameter attribute %s is not allowed #1485

Closed makua-bernal closed 3 years ago

makua-bernal commented 3 years ago

Description

When using the conversion tools to convert a roberta model the following error occurs.

Error Message

Traceback (most recent call last):
  File "convert_fairseq_roberta.py", line 386, in <module>
    convert_fairseq_model(args)
  File "convert_fairseq_roberta.py", line 355, in convert_fairseq_model
    gluon_roberta = convert_params(fairseq_roberta,
  File "convert_fairseq_roberta.py", line 174, in convert_params
    gluon_model = RobertaForMLM(backbone_cfg=gluon_cfg)
  File "/home/user/.local/lib/python3.8/site-packages/mxnet/util.py", line 297, in _with_np_shape
    return func(*args, **kwargs)
  File "/home/user/.local/lib/python3.8/site-packages/mxnet/util.py", line 481, in _with_np_array
    return func(*args, **kwargs)
  File "/home/user/gluon-nlp/src/gluonnlp/models/roberta.py", line 484, in __init__
    self.mlm_decoder[-1].weight = self.backbone_model.word_embed.weight
  File "/home/user/.local/lib/python3.8/site-packages/mxnet/gluon/block.py", line 886, in __setattr__
    super(HybridBlock, self).__setattr__(name, value)
  File "/home/user/.local/lib/python3.8/site-packages/mxnet/gluon/block.py", line 305, in __setattr__
    assert name not in self._reg_params, \
AssertionError: Overriding Parameter attribute %s is not allowed. If you want to share parameters between blocks, please set 'params' at Block construction instead.

To Reproduce

gluonnlp version 1.0.0.dev20210116 mxnet version 1.7.0.post1 fairseq version 1.0.0a0+4a6f89d

bash convert_roberta.sh

sxjscience commented 3 years ago

@jumpily You may need to install MXNet 2.0 and try again. You can try out the following commands:


# Install the version with CUDA 10.1
python3 -m pip install -U --pre "mxnet-cu101>=2.0.0b20201206" -f https://dist.mxnet.io/python

# Install the version with CUDA 10.2
python3 -m pip install -U --pre "mxnet-cu102>=2.0.0b20201206" -f https://dist.mxnet.io/python

# Install the version with CUDA 11
python3 -m pip install -U --pre "mxnet-cu110>=2.0.0b20201206" -f https://dist.mxnet.io/python

# Install the cpu-only version
python3 -m pip install -U --pre "mxnet>=2.0.0b20201206" -f https://dist.mxnet.io/python
makua-bernal commented 3 years ago

@sxjscience That seems to have worked, thank you! Are the converted models compatible with lower MXNet versions?

sxjscience commented 3 years ago

No, they are not.

Get Outlook for iOShttps://aka.ms/o0ukef


From: jumpily notifications@github.com Sent: Sunday, January 17, 2021 1:38:44 AM To: dmlc/gluon-nlp gluon-nlp@noreply.github.com Cc: Xingjian SHI xshiab@connect.ust.hk; Mention mention@noreply.github.com Subject: Re: [dmlc/gluon-nlp] [Bug][Conversion Tools] mxnet block.py Overriding Parameter attribute %s is not allowed (#1485)

@sxjsciencehttps://github.com/sxjscience That seems to have worked, thank you! Are the converted models compatible with lower MXNet versions?

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHubhttps://github.com/dmlc/gluon-nlp/issues/1485#issuecomment-761761877, or unsubscribehttps://github.com/notifications/unsubscribe-auth/ABHQH3SYL3RFSBWLVFBF33LS2KV2JANCNFSM4WFI5EZA.

sxjscience commented 3 years ago

@jumpily i’ll close this issue since it has been solved. Feel free to reopen.