Tensorflow grappler

Tensorflow runtime got a module grappler which does optimizations once model is loaded into module. Tensorflow session parameter can be used to control this optimization applied by grappler.

// Tensorflow session
tensorflow::SessionOptions session_opts;
tensorflow::OptimizerOptions* options = session_opts.config.mutable_graph_options()->mutable_optimizer_options();
// Disable optimizations
options->set_opt_level(tensorflow::OptimizerOptions::L0);
// Grappler related optimizations
auto config = session_opts.config.mutable_graph_options()->mutable_rewrite_options();
config->set_layout_optimizer(tensorflow::RewriterConfig::OFF);
config->set_disable_model_pruning(true);
config->set_function_optimization(tensorflow::RewriterConfig::OFF);
config->set_arithmetic_optimization(tensorflow::RewriterConfig::OFF);
config->set_loop_optimization(tensorflow::RewriterConfig::OFF);
config->set_dependency_optimization(tensorflow::RewriterConfig::OFF);
config->set_constant_folding(tensorflow::RewriterConfig::OFF);
config->set_memory_optimization(tensorflow::RewriterConfig::NO_MEM_OPT);
config->set_shape_optimization(tensorflow::RewriterConfig::OFF);
config->set_remapping(tensorflow::RewriterConfig::OFF);
config->set_pin_to_host_optimization(tensorflow::RewriterConfig::OFF);
config->mutable_auto_parallel()->set_enable(false);
config->clear_optimizers();
// Create tensorflow session with customized options
std::unique_ptr<tensorflow::Session> tf_session(tensorflow::NewSession(session_opts));