Hm, the memcpy approach I wrote above only works for small tensors. It works for 5x5 tensors but on 64x64 ones it stops working part-way through the tensor.
EDIT:
Okay, I found the proper way to do it. You need a NoGradGuard and Tensor::copy():
NoGradGuard guard;
module.named_parameters()["layer"].copy_(torch::from_blob(vector.data(), tensor_size));