Change dtype of torch::nn::Linear

How can I change the dtype of a torch::nn::Linear layer. It seems to be float32 be default because when I pass a torch::Tensor with dtype=float64 I get the following error:

libc++abi: terminating due to uncaught exception of type c10::Error: expected scalar type Double but found Float

Could you check if either casting the layer or the model works for you? How to use kDouble type input for Linear layer in C++

If you know the dtype when the layer is created I would also check if the layer accepts a dtype parameter on when it is created similar to the Python API.