residual and x won’t be modified by the operations, as new tensors are being created.
Have a look at this small example:
lin = nn.Linear(10, 2)
x = torch.ones(1, 10)
residual = x
output = lin(x)

Both, residual and x have still the same shape and values.