Hello I am creating custom loss function, on of the component is modifying the values of the data array.
so for example function f mutates A into B both A and B are the same shape and data type
in order to keep backpropagation working I need to supply new array as the output so for example
so I will not mutate A
or mutation is allowed?
I assume “mutation” refers to inplace operations, which are directly manipulating the data of the tensor, e.g. as seen here:
a = torch.zeros(1)
b = a
If so, then it would depend on the used operations and if these values are needed for the gradient calculation. PyTorch will raise a
RuntimeError is disallowed inplace operations are detected and will fail during the
ok, thanks @ptrblck ! If it will just give error I can just experiment on this - fantastic
One more thing as this mutation function acts element wise on 3D array - is there supported way to apply the function to each element of the tensor - with access to its cartesian coordinate in the array
pseudo code below
apply_on_coord( add_neighbour ,arr)
Your indexing approach of:
x[index] = x[index] + b
would also manipulate
x inplace and will also raise an error if it’s disallowed.