How to change a loaded model to evaluation mode in C++

I loaded a model in my C++ code in this way:

std::shared_ptr<torch::jit::script::Module> model = torch::jit::load("");

Is there an equivalent of the python model.eval() to turn it into evaluation mode in the C++ frontend?

Yes, just call model.eval()

related doc:

When I use model.eval(), the compiler says:

error: ‘struct torch::jit::script::Module’ has no member named ‘eval’

Do I need to include some additional header file?

You are right, unfortunately it is not that easy. The main problem is that jit::scriptmodule and nn::module do not have the same set of methods. I do not know the solution, but in this post they write that eval is not yet implemented in scriptmodule, but they suggest a workaround and there seems to be a brand new fix.

@Panpan_CAI calling model.eval() on a torch::jit::script::Module already works. Example: