MCPcopy Create free account
hub / github.com/DeepRec-AI/DeepRec / _run_graph

Method _run_graph

tensorflow/python/ops/split_benchmark.py:58–107  ·  view source on GitHub ↗

Run the graph and print its execution time. Args: device: string, the device to run on. output_shape: shape of each output tensors. variable: whether or not the output shape should be fixed num_outputs: the number of outputs to split the input into axis: axis to be

(self, device, output_shape, variable, num_outputs, axis)

Source from the content-addressed store, hash-verified

56 """Benchmark split!"""
57
58 def _run_graph(self, device, output_shape, variable, num_outputs, axis):
59 """Run the graph and print its execution time.
60
61 Args:
62 device: string, the device to run on.
63 output_shape: shape of each output tensors.
64 variable: whether or not the output shape should be fixed
65 num_outputs: the number of outputs to split the input into
66 axis: axis to be split
67
68 Returns:
69 The duration of the run in seconds.
70 """
71 graph = ops.Graph()
72 with graph.as_default():
73 if not variable:
74 if axis == 0:
75 input_shape = [output_shape[0] * num_outputs, output_shape[1]]
76 sizes = [output_shape[0] for _ in range(num_outputs)]
77 else:
78 input_shape = [output_shape[0], output_shape[1] * num_outputs]
79 sizes = [output_shape[1] for _ in range(num_outputs)]
80 else:
81 sizes = np.random.randint(
82 low=max(1, output_shape[axis] - 2),
83 high=output_shape[axis] + 2,
84 size=num_outputs)
85 total_size = np.sum(sizes)
86 if axis == 0:
87 input_shape = [total_size, output_shape[1]]
88 else:
89 input_shape = [output_shape[0], total_size]
90
91 outputs = build_graph(device, input_shape, sizes, axis)
92 config = config_pb2.ConfigProto(graph_options=config_pb2.GraphOptions(
93 optimizer_options=config_pb2.OptimizerOptions(
94 opt_level=config_pb2.OptimizerOptions.L0)))
95 with session_lib.Session(graph=graph, config=config) as session:
96 logging.set_verbosity("info")
97 variables.global_variables_initializer().run()
98 bench = benchmark.TensorFlowBenchmark()
99 bench.run_op_benchmark(
100 session,
101 outputs,
102 mbs=input_shape[0] * input_shape[1] * 4 * 2 * 100 / 1e6,
103 extras={
104 "input_shape": input_shape,
105 "variable": variable,
106 "axis": axis
107 })
108
109 def benchmark_split(self):
110 print("Forward vs backward concat")

Callers 1

benchmark_splitMethod · 0.95

Calls 9

as_defaultMethod · 0.95
run_op_benchmarkMethod · 0.95
rangeFunction · 0.70
build_graphFunction · 0.70
maxFunction · 0.50
GraphMethod · 0.45
sumMethod · 0.45
SessionMethod · 0.45
runMethod · 0.45

Tested by

no test coverage detected