Python tensorflow.GraphOptions() Examples
The following are 30
code examples of tensorflow.GraphOptions().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
tensorflow
, or try the search function
.
![](https://www.programcreek.com/common/static/images/search.png)
Example #1
Source File: trainer_lib.py From fine-lm with MIT License | 6 votes |
def create_session_config(log_device_placement=False, enable_graph_rewriter=False, gpu_mem_fraction=0.95, use_tpu=False, inter_op_parallelism_threads=0, intra_op_parallelism_threads=0): """The TensorFlow Session config to use.""" if use_tpu: graph_options = tf.GraphOptions() else: if enable_graph_rewriter: rewrite_options = rewriter_config_pb2.RewriterConfig() rewrite_options.layout_optimizer = rewriter_config_pb2.RewriterConfig.ON graph_options = tf.GraphOptions(rewrite_options=rewrite_options) else: graph_options = tf.GraphOptions( optimizer_options=tf.OptimizerOptions( opt_level=tf.OptimizerOptions.L1, do_function_inlining=False)) gpu_options = tf.GPUOptions(per_process_gpu_memory_fraction=gpu_mem_fraction) config = tf.ConfigProto( allow_soft_placement=True, graph_options=graph_options, gpu_options=gpu_options, log_device_placement=log_device_placement, inter_op_parallelism_threads=inter_op_parallelism_threads, intra_op_parallelism_threads=intra_op_parallelism_threads) return config
Example #2
Source File: function_test.py From deep_image_model with Apache License 2.0 | 6 votes |
def testTanhSymGrad(self): @function.Defun(tf.float32) def Forward(x): return tf.reduce_sum(tf.tanh(x)) g = tf.Graph() with g.as_default(): x = tf.placeholder(tf.float32) y = Forward(x) dx = tf.gradients([y], [x]) inp = np.array([-1, 1, 2, -2], dtype=np.float32) feed = {x: inp} cfg = tf.ConfigProto(graph_options=tf.GraphOptions( optimizer_options=tf.OptimizerOptions( opt_level=tf.OptimizerOptions.L1, do_function_inlining=True))) with tf.Session(graph=g, config=cfg) as sess: out, = sess.run(dx, feed) self.assertAllClose(1 - np.square(np.tanh(inp)), out)
Example #3
Source File: parameterized_truncated_normal_op_test.py From deep_image_model with Apache License 2.0 | 6 votes |
def parameterized_vs_naive(shape, num_iters, use_gpu=False): np.random.seed(1618) # Make it reproducible. # No CSE/CF. optimizer_options = tf.OptimizerOptions(opt_level=tf.OptimizerOptions.L0) config = tf.ConfigProto( graph_options=tf.GraphOptions(optimizer_options=optimizer_options)) with tf.Session(config=config) as sess: with tf.device("/cpu:0" if not use_gpu else None): param_op = tf.group(random_ops.parameterized_truncated_normal(shape)) naive_op = tf.group(random_ops.truncated_normal(shape)) # Burn-in to avoid session setup costs in the timing. sess.run(param_op) sess.run(param_op) param_dt = timeit.timeit(lambda: sess.run(param_op), number=num_iters) sess.run(naive_op) sess.run(naive_op) naive_dt = timeit.timeit(lambda: sess.run(naive_op), number=num_iters) return param_dt, naive_dt
Example #4
Source File: multinomial_op_test.py From deep_image_model with Apache License 2.0 | 6 votes |
def native_op_vs_composed_ops(batch_size, num_classes, num_samples, num_iters): np.random.seed(1618) # Make it reproducible. shape = [batch_size, num_classes] logits_np = np.random.randn(*shape).astype(np.float32) # No CSE/CF. optimizer_options = tf.OptimizerOptions(opt_level=tf.OptimizerOptions.L0) config = tf.ConfigProto( graph_options=tf.GraphOptions(optimizer_options=optimizer_options)) with tf.Session(config=config) as sess: logits = tf.constant(logits_np, shape=shape) native_op = tf.group(native_sampler(logits, num_samples)) composed_op = tf.group(composed_sampler(logits, num_samples)) native_dt = timeit.timeit(lambda: sess.run(native_op), number=num_iters) composed_dt = timeit.timeit(lambda: sess.run(composed_op), number=num_iters) return native_dt, composed_dt
Example #5
Source File: tf_nizza.py From sgnmt with Apache License 2.0 | 6 votes |
def _session_config(self): """Creates the session config with t2t default parameters.""" graph_options = tf.GraphOptions(optimizer_options=tf.OptimizerOptions( opt_level=tf.OptimizerOptions.L1, do_function_inlining=False)) if self._single_cpu_thread: config = tf.ConfigProto( intra_op_parallelism_threads=1, inter_op_parallelism_threads=1, allow_soft_placement=True, graph_options=graph_options, log_device_placement=False) else: gpu_options = tf.GPUOptions( per_process_gpu_memory_fraction=0.95) config = tf.ConfigProto( allow_soft_placement=True, graph_options=graph_options, gpu_options=gpu_options, log_device_placement=False) return config
Example #6
Source File: multiple_memory_obtain_test.py From gradient-checkpointing with MIT License | 5 votes |
def create_session(): config = tf.ConfigProto(log_device_placement=False, graph_options=tf.GraphOptions(optimizer_options=tf.OptimizerOptions(opt_level=tf.OptimizerOptions.L0))) return tf.InteractiveSession(config=config)
Example #7
Source File: translator.py From transformer-aan with BSD 3-Clause "New" or "Revised" License | 5 votes |
def session_config(params): optimizer_options = tf.OptimizerOptions(opt_level=tf.OptimizerOptions.L1, do_function_inlining=False) graph_options = tf.GraphOptions(optimizer_options=optimizer_options) config = tf.ConfigProto(allow_soft_placement=True, graph_options=graph_options) if params.device_list: device_str = ",".join([str(i) for i in params.device_list]) config.gpu_options.visible_device_list = device_str return config
Example #8
Source File: config.py From tf-encrypted with Apache License 2.0 | 5 votes |
def build_graph_options(cls, disable_optimizations): if not disable_optimizations: return tf.GraphOptions() return tf.GraphOptions( optimizer_options=tf.OptimizerOptions( opt_level=tf.OptimizerOptions.L0, do_common_subexpression_elimination=False, do_constant_folding=False, do_function_inlining=False, ), rewrite_options=rewriter_config_pb2.RewriterConfig( arithmetic_optimization=rewriter_config_pb2.RewriterConfig.OFF ), )
Example #9
Source File: trainer.py From transformer-aan with BSD 3-Clause "New" or "Revised" License | 5 votes |
def session_config(params): optimizer_options = tf.OptimizerOptions(opt_level=tf.OptimizerOptions.L1, do_function_inlining=True) graph_options = tf.GraphOptions(optimizer_options=optimizer_options) config = tf.ConfigProto(allow_soft_placement=True, graph_options=graph_options) if params.device_list: device_str = ",".join([str(i) for i in params.device_list]) config.gpu_options.visible_device_list = device_str return config
Example #10
Source File: mem_util_test.py From gradient-checkpointing with MIT License | 5 votes |
def create_session(): """Create session with optimizations disabled.""" from tensorflow.core.protobuf import rewriter_config_pb2 optimizer_options = tf.OptimizerOptions(opt_level=tf.OptimizerOptions.L0) config = tf.ConfigProto(operation_timeout_in_ms=150000, graph_options=tf.GraphOptions(optimizer_options=optimizer_options)) config.graph_options.rewrite_options.constant_folding=rewriter_config_pb2.RewriterConfig.OFF config.graph_options.place_pruned_graph = True return tf.Session(config=config)
Example #11
Source File: linearize_test.py From gradient-checkpointing with MIT License | 5 votes |
def _create_session(): optimizer_options = tf.OptimizerOptions(opt_level=tf.OptimizerOptions.L0) config = tf.ConfigProto(operation_timeout_in_ms=3000, graph_options=tf.GraphOptions(optimizer_options=optimizer_options)) config.graph_options.rewrite_options.constant_folding = rewriter_config_pb2.RewriterConfig.OFF config.graph_options.place_pruned_graph = True return tf.Session(config=config)
Example #12
Source File: imagenet_test.py From gradient-checkpointing with MIT License | 5 votes |
def create_session(): global sess optimizer_options = tf.OptimizerOptions(opt_level=tf.OptimizerOptions.L0) config = tf.ConfigProto(operation_timeout_in_ms=150000, graph_options=tf.GraphOptions(optimizer_options=optimizer_options)) sess = tf.Session(config=config) return sess
Example #13
Source File: imagenet_correctness_test.py From gradient-checkpointing with MIT License | 5 votes |
def create_session(): global sess optimizer_options = tf.OptimizerOptions(opt_level=tf.OptimizerOptions.L0) config = tf.ConfigProto(operation_timeout_in_ms=150000, graph_options=tf.GraphOptions(optimizer_options=optimizer_options)) sess = tf.Session(config=config) return sess
Example #14
Source File: resnet_test.py From gradient-checkpointing with MIT License | 5 votes |
def create_session(): optimizer_options = tf.OptimizerOptions(opt_level=tf.OptimizerOptions.L0) config = tf.ConfigProto(operation_timeout_in_ms=150000, graph_options=tf.GraphOptions(optimizer_options=optimizer_options)) # config.graph_options.rewrite_options.constant_folding = rewriter_config_pb2.RewriterConfig.OFF config.graph_options.place_pruned_graph = True return tf.Session(config=config)
Example #15
Source File: resnet_correctness_test.py From gradient-checkpointing with MIT License | 5 votes |
def create_session(): optimizer_options = tf.OptimizerOptions(opt_level=tf.OptimizerOptions.L0) config = tf.ConfigProto(operation_timeout_in_ms=150000, graph_options=tf.GraphOptions(optimizer_options=optimizer_options)) config.graph_options.rewrite_options.constant_folding = rewriter_config_pb2.RewriterConfig.OFF config.graph_options.place_pruned_graph = True return tf.Session(config=config)
Example #16
Source File: tf_utils.py From sgnmt with Apache License 2.0 | 5 votes |
def session_config(n_cpu_threads=-1): """Creates the session config with default parameters. Args: n_cpu_threads (int): Number of CPU threads. If negative, we assume either GPU decoding or that all CPU cores can be used. Returns: A TF session config object. """ graph_options = tf.GraphOptions(optimizer_options=tf.OptimizerOptions( opt_level=tf.OptimizerOptions.L1, do_function_inlining=False)) if n_cpu_threads < 0: gpu_options = tf.GPUOptions( per_process_gpu_memory_fraction=0.95) config = tf.ConfigProto( allow_soft_placement=True, graph_options=graph_options, gpu_options=gpu_options, log_device_placement=False) else: #device_count={'CPU': n_cpu_threads}, if n_cpu_threads >= 4: # This adjustment is an estimate of the effective load which # accounts for the sequential parts in SGNMT. if n_cpu_threads == 4: n_cpu_threads = 5 else: n_cpu_threads = int(n_cpu_threads*5/1.5 - 10) logging.debug("Setting TF inter and intra op parallelism " "to %d" % n_cpu_threads) config = tf.ConfigProto( intra_op_parallelism_threads=n_cpu_threads, inter_op_parallelism_threads=n_cpu_threads, allow_soft_placement=True, graph_options=graph_options, log_device_placement=False) return config
Example #17
Source File: deep_imagenet_benchmark.py From gradient-checkpointing with MIT License | 5 votes |
def create_session(): optimizer_options = tf.OptimizerOptions(opt_level=tf.OptimizerOptions.L0) config = tf.ConfigProto(operation_timeout_in_ms=150000, graph_options=tf.GraphOptions(optimizer_options=optimizer_options)) # config.graph_options.rewrite_options.constant_folding = rewriter_config_pb2.RewriterConfig.OFF config.graph_options.place_pruned_graph = True return tf.Session(config=config)
Example #18
Source File: deep_resnet_benchmark.py From gradient-checkpointing with MIT License | 5 votes |
def create_session(): optimizer_options = tf.OptimizerOptions(opt_level=tf.OptimizerOptions.L0) config = tf.ConfigProto(operation_timeout_in_ms=150000, graph_options=tf.GraphOptions(optimizer_options=optimizer_options)) # config.graph_options.rewrite_options.constant_folding = rewriter_config_pb2.RewriterConfig.OFF config.graph_options.place_pruned_graph = True return tf.Session(config=config)
Example #19
Source File: mnist_correctness_test.py From gradient-checkpointing with MIT License | 5 votes |
def create_session(): from tensorflow.core.protobuf import rewriter_config_pb2 optimizer_options = tf.OptimizerOptions(opt_level=tf.OptimizerOptions.L0) config = tf.ConfigProto(operation_timeout_in_ms=150000, graph_options=tf.GraphOptions(optimizer_options=optimizer_options)) config.graph_options.rewrite_options.constant_folding = rewriter_config_pb2.RewriterConfig.OFF config.graph_options.place_pruned_graph = True return tf.Session(config=config)
Example #20
Source File: trainer.py From XMUNMT with BSD 3-Clause "New" or "Revised" License | 5 votes |
def session_config(params): optimizer_options = tf.OptimizerOptions(opt_level=tf.OptimizerOptions.L1, do_function_inlining=True) graph_options = tf.GraphOptions(optimizer_options=optimizer_options) config = tf.ConfigProto(allow_soft_placement=True, graph_options=graph_options) if params.device_list: device_str = ",".join([str(i) for i in params.device_list]) config.gpu_options.visible_device_list = device_str return config
Example #21
Source File: translator.py From XMUNMT with BSD 3-Clause "New" or "Revised" License | 5 votes |
def session_config(params): optimizer_options = tf.OptimizerOptions(opt_level=tf.OptimizerOptions.L1, do_function_inlining=False) graph_options = tf.GraphOptions(optimizer_options=optimizer_options) config = tf.ConfigProto(allow_soft_placement=True, graph_options=graph_options) if params.device_list: device_str = ",".join([str(i) for i in params.device_list]) config.gpu_options.visible_device_list = device_str return config
Example #22
Source File: trainer.py From Document-Transformer with BSD 3-Clause "New" or "Revised" License | 5 votes |
def session_config(params): optimizer_options = tf.OptimizerOptions(opt_level=tf.OptimizerOptions.L1, do_function_inlining=True) graph_options = tf.GraphOptions(optimizer_options=optimizer_options) config = tf.ConfigProto(allow_soft_placement=True, graph_options=graph_options) if params.device_list: device_str = ",".join([str(i) for i in params.device_list]) config.gpu_options.visible_device_list = device_str return config
Example #23
Source File: translator.py From Document-Transformer with BSD 3-Clause "New" or "Revised" License | 5 votes |
def session_config(params): optimizer_options = tf.OptimizerOptions(opt_level=tf.OptimizerOptions.L1, do_function_inlining=False) graph_options = tf.GraphOptions(optimizer_options=optimizer_options) config = tf.ConfigProto(allow_soft_placement=True, graph_options=graph_options) if params.device_list: device_str = ",".join([str(i) for i in params.device_list]) config.gpu_options.visible_device_list = device_str return config
Example #24
Source File: translator_ctx.py From Document-Transformer with BSD 3-Clause "New" or "Revised" License | 5 votes |
def session_config(params): optimizer_options = tf.OptimizerOptions(opt_level=tf.OptimizerOptions.L1, do_function_inlining=False) graph_options = tf.GraphOptions(optimizer_options=optimizer_options) config = tf.ConfigProto(allow_soft_placement=True, graph_options=graph_options) if params.device_list: device_str = ",".join([str(i) for i in params.device_list]) config.gpu_options.visible_device_list = device_str return config
Example #25
Source File: trainer_ctx.py From Document-Transformer with BSD 3-Clause "New" or "Revised" License | 5 votes |
def session_config(params): optimizer_options = tf.OptimizerOptions(opt_level=tf.OptimizerOptions.L1, do_function_inlining=True) graph_options = tf.GraphOptions(optimizer_options=optimizer_options) config = tf.ConfigProto(allow_soft_placement=True, graph_options=graph_options) if params.device_list: device_str = ",".join([str(i) for i in params.device_list]) config.gpu_options.visible_device_list = device_str return config
Example #26
Source File: scorer.py From Document-Transformer with BSD 3-Clause "New" or "Revised" License | 5 votes |
def session_config(params): optimizer_options = tf.OptimizerOptions(opt_level=tf.OptimizerOptions.L1, do_function_inlining=False) graph_options = tf.GraphOptions(optimizer_options=optimizer_options) config = tf.ConfigProto(allow_soft_placement=True, graph_options=graph_options) if params.device_list: device_str = ",".join([str(i) for i in params.device_list]) config.gpu_options.visible_device_list = device_str return config
Example #27
Source File: train_low_level_runner.py From training_results_v0.5 with Apache License 2.0 | 5 votes |
def __init__(self, iterations): tf.logging.info("TrainLowLevelRunner: constructor") self.feature_structure = {} self.loss = None self.infeed_queue = [] self.enqueue_ops = [] self.dataset_initializer = [] self.iterations = iterations self.num_hosts = FLAGS.num_shards // FLAGS.num_shards_per_host self.scaffold_fn = None # Having two separate sessions and graphs to make the initialization faster. self.input_sess = None self.train_sess = None self.input_graph = tf.Graph() self.train_graph = None self.tpu_cluster_resolver = tf.contrib.cluster_resolver.TPUClusterResolver( FLAGS.tpu_name, zone=FLAGS.tpu_zone, project=FLAGS.gcp_project) # Disable grappler for better performance. self.session_config = tf.ConfigProto( allow_soft_placement=True, graph_options=tf.GraphOptions( rewrite_options=rewriter_config_pb2.RewriterConfig( disable_meta_optimizer=True)), isolate_session_state=True) cluster_spec = self.tpu_cluster_resolver.cluster_spec() if cluster_spec: self.session_config.cluster_def.CopyFrom(cluster_spec.as_cluster_def()) self.tpu_init = [tpu.initialize_system()] self.tpu_shutdown = tpu.shutdown_system() self.init_sess = tf.Session(self.tpu_cluster_resolver.get_master(), config=self.session_config) self.init_sess.run(self.tpu_init) self.queue = Queue.Queue()
Example #28
Source File: trainer.py From THUMT with BSD 3-Clause "New" or "Revised" License | 5 votes |
def session_config(params): optimizer_options = tf.OptimizerOptions(opt_level=tf.OptimizerOptions.L1, do_function_inlining=True) graph_options = tf.GraphOptions(optimizer_options=optimizer_options) config = tf.ConfigProto(allow_soft_placement=True, graph_options=graph_options) if distribute.is_distributed_training_mode(): config.gpu_options.visible_device_list = str(distribute.local_rank()) elif params.device_list: device_str = ",".join([str(i) for i in params.device_list]) config.gpu_options.visible_device_list = device_str return config
Example #29
Source File: get_relevance.py From THUMT with BSD 3-Clause "New" or "Revised" License | 5 votes |
def session_config(params): optimizer_options = tf.OptimizerOptions(opt_level=tf.OptimizerOptions.L1, do_function_inlining=False) graph_options = tf.GraphOptions(optimizer_options=optimizer_options) config = tf.ConfigProto(allow_soft_placement=True, graph_options=graph_options, intra_op_parallelism_threads=16, inter_op_parallelism_threads=16) if params.device_list: device_str = ",".join([str(i) for i in params.device_list]) config.gpu_options.visible_device_list = device_str return config
Example #30
Source File: translator.py From THUMT with BSD 3-Clause "New" or "Revised" License | 5 votes |
def session_config(params): optimizer_options = tf.OptimizerOptions(opt_level=tf.OptimizerOptions.L1, do_function_inlining=False) graph_options = tf.GraphOptions(optimizer_options=optimizer_options) config = tf.ConfigProto(allow_soft_placement=True, graph_options=graph_options) if params.device_list: device_str = ",".join([str(i) for i in params.device_list]) config.gpu_options.visible_device_list = device_str return config