I’m not sure where this warning is raised, since I cannot see any usage of the .grad attribute.
However, your current code should fail with:
RuntimeError: a view of a leaf Variable that requires grad is being used in an in-place operation.

and you would need to manipulate the parameter in a torch.no_grad() block, which seems to work fine:
model = models.resnet18()

with torch.no_grad():
    for layerPara in model.parameters():
        layerPara[0][0][0][0] = -6.0173e+3
        break
    
x = torch.randn(2, 3, 224, 224)
target = torch.randint(0, 1000, (2,))
criterion = nn.CrossEntropyLoss()

out = model(x)
loss = criterion(out, target)
loss.backward()