you could try this.
#include <torch/csrc/jit/update_graph_executor_opt.h> //... setGraphExecutorOptimize(false);