ezyang / pytorch-unattached

Tensors and Dynamic neural networks in Python with strong GPU acceleration
http://pytorch.org
Other
20 stars 8 forks source link

Tracing identity function does not work #228

Open ezyang opened 7 years ago

ezyang commented 7 years ago
        x = Variable(torch.FloatTensor([1]))
        def fn(x):
            return x 
        trace, _ = torch.jit.record_trace(fn, x)
        print(str(trace))

This outputs:

<expired TracingState>

It still fails even if you call x.add_(2) or some other inplace operation inside fn.

From @apaszke:

That's expected Either make the Variable volatile or say num_derivatives=0 The graph died before you got to first backward so it expired