That’s why I am registering a backward hook, to kill the history for a given batch index.
Repackaging the whole Variable would kill all the history, which is unacceptable.
I am now wondering whether
state_layer.data[b].zero_()
state_layer.register_hook(lambda grad: grad[b].zero_())

is equivalent to your
state_layer[b].zero_()