Partially reset a Variable, in-place vs. new Variable

Are you sure you want to do state_layer.data[b].zero_() and not state_layer[b].zero_() ? Because in the first case, the operation is not registered to autograd and can have unexpected behaviour.

If what you want is to reset the content of the tensor to use it again independently of how you were using it before, you should repack it in a new Variable otherwise it will still have the history of the previous usage.