Hey @Omegastick,
what I dont like about your solution is that it has the potential to break other peoples code. Your solution would at least require to put it in parenthesis, e.g.
{
    NoGradGuard guard;
    module.named_parameters()["layer"].copy_(torch::from_blob(vector.data(), tensor_size));
}

You could either do this or this, as mentioned above
torch::Tensor tensor = torch::from_blob(vector.data(), tensor_size);
net->named_parameters()["layer"].set_data(tensor);