Hello,
.clone() is not a shared memory operation.
In the first for loop, you clone the conv1.weight to orig_params, here conv1.weight and p point to the same memory, and orig_params points to another memory.
Then changing the value of p and conv1.weight together, because they are sharing the same memory.
In the second loop before clone to p, p and conv1.weight still share the same memory, but after cloning the case becomes different, p and conv1.weight don’t use the same memory, so modify the value of p will not influnce conv1.weight's value.
Additionally, you could add A is B in each if-clause to check if they point to the same memory. I have checked that:
# the first if
p is conv1.weight -> True
# the second if
p is conv1.weight -> True
# the third if
p is conv1.weight -> False