Recently, I need to use torch.unique to choose the unique elements in a 2D tensor as part of my graph computation. But the runtime error popped up derivative for _unique2 is not implemented. I used a similar function called tf.raw_ops.uniquev2 in TensorFlow, which fulfills same functioning as torch.unique and it is differentiable in my case, I think. Anyone would know how to make this torch.unique differentiable? Or is there any suggestion someone would make? I will really appreciate it.
I also attached part of code for simulating my case:
import torch
a = torch.tensor([1.0,1.0,2.1,3.1,3.5,2.0,2.0])
w1 = torch.tensor(5.0, requires_grad=True)
d = w1 * a
u = torch.unique(d)
w2 = torch.tensor(.5, requires_grad=True)
g = w2 * u
g.sum().backward()