'is_sparse_any' from 'torch._cannot import namesubclasses.meta_utils'

this is my code:

class Seq2Seq(nn.Module):
    def __init__(self,encoder,decoder,config):
        self.encoder = encoder(config)
        self.decoder = decoder(config)
    def forward(self,src,tgt):
        encoder_output = self.encoder(src)
        decoder_output = self.decoder(encoder_output, tgt)
        return decoder_output
optimizer = torch.optim.Adam(model.parameters())```


but in the last line I have this error: ImportError: cannot import name 'is_sparse_any' from 'torch._subclasses.meta_utils' can anyone help me to solve this issue? apparently it's related to environmentvariable but I don't know how to fix it

Can you share please your pytorch version and the import statement that you are using?

1 Like

(torch version is ‘2.3.1+cpu’)
by the way, I don’t know why but I could run my code in in a new session!