pcpLiu
(Tim)
1
Hi,
Is it possible to assign weights & bias of linear op in C++?
auto m = torch::nn::Linear(
torch::nn::LinearOptions(in_feature_dim, out_feature_dim).bias(true));
// assign weights & bias
m.get()->weight.copy_(weight_py_tensor);????
Searched around, didn’t find a good solution.
Thanks!!
ptrblck
2
I’m not sure, if you need the get()
operation, but you might want to add the NoGrad
guard:
torch::NoGradGuard no_grad;
linear->weight.copy_(tensor);
should work.
1 Like
pcpLiu
(Tim)
3
Thanks @ptrblck . Works well!
1 Like