In that case you can use set:
import torch

w = torch.nn.Parameter(torch.randn((2,5)),requires_grad=True)

l = torch.sum(w)
l.backward()

# if "del l" is added here then the code runs 

ext_w = torch.randn((1,5),requires_grad=True) # now the shape is (3,5)
with torch.no_grad():
    w.set_(ext_w)

l = torch.sum(w)
l.backward()

And you will need to update the optimizer if it has state as well