You could use the .copy_ operation as in this example:
torch::NoGradGuard guard;
for (auto& p : model->parameters()) {
  auto sz = p.view(-1).size(0);
  p.copy_(torch::cos(torch::arange(0, sz, tensor_options).view(p.sizes())));
}