I have code that looks like the following:
import torch import torch.autograd as grad # A is a Variable that has undergone previous operations and has an existing graph dummy = grad.Variable(torch.zeros(6, 5, 4, 3)) for i in xrange(6): # Do something here... indices = # Determine indices somehow dummy[i] = torch.index_select(A[i], 1, indices.view(-1)).view(5, -1, 3)
- From this answer, it seems that
index_selectwill preserve the state as long as you are indexing from a Variable with some existing state. So am I right to presume that
dummywill have a graph that is composed of the graphs of the selected indices?
- Does dummy need to have
requires_grad=True, or will assigning to it a Variable with
requires_grad=Trueautomatically cause that flag to “flip”?