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

  
      github.com
  
  
    pytorch/pytorch/blob/a3346e100e7f4e7ec90f18b7befcccc47d5a1c82/test/cpp/jit/test_misc.h#L445-L450 19

torch::jit::script::Module module = torch::jit::load(module_path);
AT_ASSERT(module.get_module("dropout").is_training());
module.eval();
AT_ASSERT(!module.get_module("dropout").is_training());
module.train();
AT_ASSERT(module.get_module("dropout").is_training());