LatticeLSTM icon indicating copy to clipboard operation
LatticeLSTM copied to clipboard

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

Open actforjason opened this issue 4 years ago • 4 comments

        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.weight_hh.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.no_grad(): x.set_(y)

actforjason avatar Jun 17 '21 03:06 actforjason

        with torch.no_grad():
            self.weight_hh.set_(weight_hh_data)
            self.alpha_weight_hh.set_(alpha_weight_hh_data)

解决问题

actforjason avatar Jun 17 '21 03:06 actforjason

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

yolanda182 avatar Sep 24 '21 04:09 yolanda182

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

版本不一致

WangYao-GoGoGo avatar Oct 03 '22 06:10 WangYao-GoGoGo

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

WangYao-GoGoGo avatar Oct 03 '22 06:10 WangYao-GoGoGo