jiesutd / LatticeLSTM

Chinese NER using Lattice LSTM. Code for ACL 2018 paper.
1.79k stars 457 forks source link

RuntimeError: set_storage is not allowed on a Tensor created from .data or .detach(). #128

Open actforjason opened 3 years ago

actforjason commented 3 years ago
        weight_hh_data = torch.eye(self.hidden_size)
        weight_hh_data = weight_hh_data.repeat(1, 3)
        self.weight_hh.data.set_(weight_hh_data)

        alpha_weight_hh_data = torch.eye(self.hidden_size)
        alpha_weight_hh_data = alpha_weight_hh_data.repeat(1, 1)
        self.alpha_weight_hh.data.set_(alpha_weight_hh_data)

model\latticelstm.py", line 107, in reset_parameters self.weighthh.data.set(weight_hh_data) RuntimeError: set_storage is not allowed on a Tensor created from .data or .detach(). If your intent is to change the metadata of a Tensor (such as sizes / strides / storage / storage_offset) without autograd tracking the change, remove the .data / .detach() call and wrap the change in a with torch.no_grad(): block. For example, change: x.data.set_(y) to: with torch.nograd(): x.set(y)

actforjason commented 3 years ago
        with torch.no_grad():
            self.weight_hh.set_(weight_hh_data)
            self.alpha_weight_hh.set_(alpha_weight_hh_data)

解决问题

yolanda182 commented 2 years ago

你好👋 请问这个问题具体怎么解决呢?

WangYao-GoGoGo commented 1 year ago

你好👋 请问这个问题具体怎么解决呢?

版本不一致

WangYao-GoGoGo commented 1 year ago

升级pytroch版本或者,不升级改成上面的版本