Error in script::Module::get_method

torch::Tensor hidden = module.get_method("get_initial_state")({torch::tensor({20})});

/home/rakesh/rishabh_workspace/Garbage/LMtesting/LMtesting.cpp:65:64: error: conversion from ‘ c10::IValue ’ to non-scalar type ‘ at::Tensor ’ requested

torch::Tensor hidden = module.get_method(“get_initial_state”)({torch::tensor({20})}) ;
^

get_method returns an IValue, which you can sort of think of as like a PyObject. You need to explicitly cast it to the C++ type you want, so you should do hidden.toTensor() to get an at::Tensor.

For example :

auto hidden_map = module.get_method("get_initial_state")({torch::tensor({1})});
torch::Tensor t = hidden_map.toTensor()