thunlp / Chinese_NRE

Source code for ACL 2019 paper "Chinese Relation Extraction with Multi-Grained Information and External Linguistic Knowledge"
MIT License
269 stars 43 forks source link

RuntimeError:set_storge is not allowed on Tensor created from .data or .detach() #23

Open ZMD177 opened 2 years ago

ZMD177 commented 2 years ago

Traceback (most recent call last): File "D:/pycharm/work/Chinese_NRE-master/main.py", line 187, in train(data, configure.savemodel) File "D:/pycharm/work/Chinese_NRE-master/main.py", line 97, in train model = MGLattice_model(data) File "D:\pycharm\work\Chinese_NRE-master\nn\framework.py", line 15, in init self.encoder = BiLstmEncoder(data) File "D:\pycharm\work\Chinese_NRE-master\nn\encoder.py", line 98, in init self.forward_lstm = LatticeLSTM(lstm_input, lstm_hidden, data.gaz_dropout, data.gaz_alphabet.size(), data.gaz_emb_dim, data.pretrain_gaz_embedding, True, data.HP_fix_gaz_emb, self.gpu) File "D:\pycharm\work\Chinese_NRE-master\nn\mglattice.py", line 262, in init self.rnn = MultiInputLSTMCell(input_dim, hidden_dim) File "D:\pycharm\work\Chinese_NRE-master\nn\mglattice.py", line 163, in init self.reset_parameters() File "D:\pycharm\work\Chinese_NRE-master\nn\mglattice.py", line 174, in reset_parameters self.weighthh.data.set(weight_hh_data) RuntimeError: set_storage is not allowed on Tensor created from .data or .detach()

zhangluoli commented 2 years ago

请问你把这个问题解决了吗

civugd commented 1 year ago

可能是pytorch版本太高,这里需要的版本是0.4.1 对于pytorch1.8版本,可以将所有的

x.data.set_(y)

替换成

with torch.no_grad():
    x.set_(y)