AdilZouitine:

Hi, I tried the solution you proposed but it doesn’t work.


It does work  It is just that the code has another unrelated problem.
Running the updated sample works fine:
import torch
slize = [1, 2, 3, 4]
x = torch.randn(10, requires_grad=True)
y = x[slize]
y.sum().backward(retain_graph=True)
y.sum().backward() # runs fine

As the error mentions, you modify inplace a Tensor whose value is required for the backward computation. You can follow the instructions in the error message to get a pointer to which op is faulty and replace the inplace op there by an out of place one.