As you can see, this function is using .data which means that it break the computational graph. This is not expected to work with differentiable operations.
nn.Parameters() are built only to be trainable parameters, not intermediary Tensors that require gradients.
One way to go around this is to manually delete the old parameters and just put your new weights there:
del mod.weight # Remove it from the Parameter list
mod.weight = your_new weights
# mod.weight is not just a Tensor, not a Parameter anymore.