Thanks~
I used to implement it with midvar[:, 0] = 0 and encounter a bug as below, however I can not reproduce it… Maybe i just made something wrong.
RuntimeError: a leaf Variable that requires grad has been used in an in-place operation

Anyway now your solution works well.