Doing trained_model[i][0][k]=foo is an inplace operation. So you did not removed it.
In this case, replace:
# Your copy code

By
with torch.no_grad():
  # Your copy code

You can leave the inplace as they won’t cause issues in no grad mode.