The below statements doesn’t change the values in opt_weights[tr == kth].data
opt_weights[tr == kth].data = dist.sample_n(opt_weights[tr == kth].shape[0])
opt_weights[tr == kth].data = dist.sample_n(opt_weights[tr == kth].shape[0]).data
opt_weights[tr == kth].data.copy_(dist.sample_n(opt_weights[tr == kth].shape[0]))
I don’t get an error in above cases but as I said they’re not helpful in changing values.
When I try to change it without .data part, I get the following.
*** RuntimeError: a leaf Variable that requires grad is being used in an in-place operation.
What is the right way of overwriting certain values in a tensor with samples of a distribution?