@@ -35,13 +35,14 @@ class PrintModelAnalysisTest(test.TestCase):
35
35
def testDumpToFile (self ):
36
36
ops .reset_default_graph ()
37
37
opts = model_analyzer .TRAINABLE_VARS_PARAMS_STAT_OPTIONS
38
- opts ['dump_to_file' ] = os .path .join (test .get_temp_dir (), 'dump' )
38
+ outfile = os .path .join (test .get_temp_dir (), 'dump' )
39
+ opts ['output' ] = 'file:outfile=' + outfile
39
40
40
41
with session .Session () as sess , ops .device ('/cpu:0' ):
41
42
_ = lib .BuildSmallModel ()
42
43
model_analyzer .print_model_analysis (sess .graph , tfprof_options = opts )
43
44
44
- with gfile .Open (opts [ 'dump_to_file' ] , 'r' ) as f :
45
+ with gfile .Open (outfile , 'r' ) as f :
45
46
self .assertEqual (u'_TFProfRoot (--/451 params)\n '
46
47
' DW (3x3x3x6, 162/162 params)\n '
47
48
' DW2 (2x2x6x12, 288/288 params)\n '
@@ -51,15 +52,14 @@ def testDumpToFile(self):
51
52
def testSelectEverything (self ):
52
53
ops .reset_default_graph ()
53
54
opts = model_analyzer .TRAINABLE_VARS_PARAMS_STAT_OPTIONS
54
- opts ['dump_to_file' ] = os .path .join (test .get_temp_dir (), 'dump' )
55
+ outfile = os .path .join (test .get_temp_dir (), 'dump' )
56
+ opts ['output' ] = 'file:outfile=' + outfile
55
57
opts ['account_type_regexes' ] = ['.*' ]
56
58
opts ['select' ] = [
57
59
'bytes' , 'params' , 'float_ops' , 'num_hidden_ops' , 'device' , 'op_types'
58
60
]
59
61
60
- config = config_pb2 .ConfigProto (
61
- graph_options = config_pb2 .GraphOptions (build_cost_model = 1 ))
62
- with session .Session (config = config ) as sess , ops .device ('/cpu:0' ):
62
+ with session .Session () as sess , ops .device ('/cpu:0' ):
63
63
x = lib .BuildSmallModel ()
64
64
65
65
sess .run (variables .global_variables_initializer ())
@@ -72,17 +72,18 @@ def testSelectEverything(self):
72
72
model_analyzer .print_model_analysis (
73
73
sess .graph , run_meta , tfprof_options = opts )
74
74
75
- with gfile .Open (opts [ 'dump_to_file' ] , 'r' ) as f :
75
+ with gfile .Open (outfile , 'r' ) as f :
76
76
# pylint: disable=line-too-long
77
77
self .assertEqual (
78
- '_TFProfRoot (0/451 params, 0/10.44k flops, 0B/5.28KB, _kTFScopeParent)\n Conv2D (0/0 params, 5.83k/5.83k flops, 432B/432B, /job:localhost/replica:0/task:0/cpu:0, /job:localhost/replica:0/task:0/cpu:0|Conv2D)\n Conv2D_1 (0/0 params, 4.61k/4.61k flops, 384B/384B, /job:localhost/replica:0/task:0/cpu:0, /job:localhost/replica:0/task:0/cpu:0|Conv2D)\n DW (3x3x3x6, 162/162 params, 0/0 flops, 648B/1.30KB, /job:localhost/replica:0/task:0/cpu:0, /job:localhost/replica:0/task:0/cpu:0|VariableV2|_trainable_variables)\n DW/Assign (0/0 params, 0/0 flops, 0B/0B, /device:CPU:0, /device:CPU:0|Assign)\n DW/Initializer (0/0 params, 0/0 flops, 0B/0B, _kTFScopeParent)\n DW/Initializer/random_normal (0/0 params, 0/0 flops, 0B/0B, Add)\n DW/Initializer/random_normal/RandomStandardNormal (0/0 params, 0/0 flops, 0B/0B, RandomStandardNormal)\n DW/Initializer/random_normal/mean (0/0 params, 0/0 flops, 0B/0B, Const)\n DW/Initializer/random_normal/mul (0/0 params, 0/0 flops, 0B/0B, Mul)\n DW/Initializer/random_normal/shape (0/0 params, 0/0 flops, 0B/0B, Const)\n DW/Initializer/random_normal/stddev (0/0 params, 0/0 flops, 0B/0B, Const)\n DW/read (0/0 params, 0/0 flops, 648B/648B, /job:localhost/replica:0/task:0/cpu:0, /job:localhost/replica:0/task:0/cpu:0|Identity)\n DW2 (2x2x6x12, 288/288 params, 0/0 flops, 1.15KB/2.30KB, /job:localhost/replica:0/task:0/cpu:0, /job:localhost/replica:0/task:0/cpu:0|VariableV2|_trainable_variables)\n DW2/Assign (0/0 params, 0/0 flops, 0B/0B, /device:CPU:0, /device:CPU:0|Assign)\n DW2/Initializer (0/0 params, 0/0 flops, 0B/0B, _kTFScopeParent)\n DW2/Initializer/random_normal (0/0 params, 0/0 flops, 0B/0B, Add)\n DW2/Initializer/random_normal/RandomStandardNormal (0/0 params, 0/0 flops, 0B/0B, RandomStandardNormal)\n DW2/Initializer/random_normal/mean (0/0 params, 0/0 flops, 0B/0B, Const)\n DW2/Initializer/random_normal/mul (0/0 params, 0/0 flops, 0B/0B, Mul)\n DW2/Initializer/random_normal/shape (0/0 params, 0/0 flops, 0B/0B, Const)\n DW2/Initializer/random_normal/stddev (0/0 params, 0/0 flops, 0B/0B, Const)\n DW2/read (0/0 params, 0/0 flops, 1.15KB/1.15KB, /job:localhost/replica:0/task:0/cpu:0, /job:localhost/replica:0/task:0/cpu:0|Identity)\n ScalarW (1, 1/1 params, 0/0 flops, 0B/0B, /device:CPU:0, /device:CPU:0|VariableV2|_trainable_variables)\n ScalarW/Assign (0/0 params, 0/0 flops, 0B/0B, /device:CPU:0, /device:CPU:0|Assign)\n ScalarW/Initializer (0/0 params, 0/0 flops, 0B/0B, _kTFScopeParent)\n ScalarW/Initializer/random_normal (0/0 params, 0/0 flops, 0B/0B, Add)\n ScalarW/Initializer/random_normal/RandomStandardNormal (0/0 params, 0/0 flops, 0B/0B, RandomStandardNormal)\n ScalarW/Initializer/random_normal/mean (0/0 params, 0/0 flops, 0B/0B, Const)\n ScalarW/Initializer/random_normal/mul (0/0 params, 0/0 flops, 0B/0B, Mul)\n ScalarW/Initializer/random_normal/shape (0/0 params, 0/0 flops, 0B/0B, Const)\n ScalarW/Initializer/random_normal/stddev (0/0 params, 0/0 flops, 0B/0B, Const)\n ScalarW/read (0/0 params, 0/0 flops, 0B/0B, /device:CPU:0, /device:CPU:0|Identity)\n init (0/0 params, 0/0 flops, 0B/0B, /device:CPU:0, /device:CPU:0|NoOp)\n zeros (0/0 params, 0/0 flops, 864B/864B, /job:localhost/replica:0/task:0/cpu:0, /job:localhost/replica:0/task:0/cpu:0|Const)\n ' ,
78
+ '_TFProfRoot (0/451 params, 0/10.44k flops, 0B/5.28KB, _kTFScopeParent)\n Conv2D (0/0 params, 5.83k/5.83k flops, 432B/432B, /job:localhost/replica:0/task:0/cpu:0, /job:localhost/replica:0/task:0/cpu:0|Conv2D)\n Conv2D_1 (0/0 params, 4.61k/4.61k flops, 384B/384B, /job:localhost/replica:0/task:0/cpu:0, /job:localhost/replica:0/task:0/cpu:0|Conv2D)\n DW (3x3x3x6, 162/162 params, 0/0 flops, 648B/1.30KB, /job:localhost/replica:0/task:0/cpu:0, /job:localhost/replica:0/task:0/cpu:0|VariableV2|_trainable_variables)\n DW/Assign (0/0 params, 0/0 flops, 0B/0B, Assign)\n DW/Initializer (0/0 params, 0/0 flops, 0B/0B, _kTFScopeParent)\n DW/Initializer/random_normal (0/0 params, 0/0 flops, 0B/0B, Add)\n DW/Initializer/random_normal/RandomStandardNormal (0/0 params, 0/0 flops, 0B/0B, RandomStandardNormal)\n DW/Initializer/random_normal/mean (0/0 params, 0/0 flops, 0B/0B, Const)\n DW/Initializer/random_normal/mul (0/0 params, 0/0 flops, 0B/0B, Mul)\n DW/Initializer/random_normal/shape (0/0 params, 0/0 flops, 0B/0B, Const)\n DW/Initializer/random_normal/stddev (0/0 params, 0/0 flops, 0B/0B, Const)\n DW/read (0/0 params, 0/0 flops, 648B/648B, /job:localhost/replica:0/task:0/cpu:0, /job:localhost/replica:0/task:0/cpu:0|Identity)\n DW2 (2x2x6x12, 288/288 params, 0/0 flops, 1.15KB/2.30KB, /job:localhost/replica:0/task:0/cpu:0, /job:localhost/replica:0/task:0/cpu:0|VariableV2|_trainable_variables)\n DW2/Assign (0/0 params, 0/0 flops, 0B/0B, Assign)\n DW2/Initializer (0/0 params, 0/0 flops, 0B/0B, _kTFScopeParent)\n DW2/Initializer/random_normal (0/0 params, 0/0 flops, 0B/0B, Add)\n DW2/Initializer/random_normal/RandomStandardNormal (0/0 params, 0/0 flops, 0B/0B, RandomStandardNormal)\n DW2/Initializer/random_normal/mean (0/0 params, 0/0 flops, 0B/0B, Const)\n DW2/Initializer/random_normal/mul (0/0 params, 0/0 flops, 0B/0B, Mul)\n DW2/Initializer/random_normal/shape (0/0 params, 0/0 flops, 0B/0B, Const)\n DW2/Initializer/random_normal/stddev (0/0 params, 0/0 flops, 0B/0B, Const)\n DW2/read (0/0 params, 0/0 flops, 1.15KB/1.15KB, /job:localhost/replica:0/task:0/cpu:0, /job:localhost/replica:0/task:0/cpu:0|Identity)\n ScalarW (1, 1/1 params, 0/0 flops, 0B/0B, VariableV2|_trainable_variables)\n ScalarW/Assign (0/0 params, 0/0 flops, 0B/0B, Assign)\n ScalarW/Initializer (0/0 params, 0/0 flops, 0B/0B, _kTFScopeParent)\n ScalarW/Initializer/random_normal (0/0 params, 0/0 flops, 0B/0B, Add)\n ScalarW/Initializer/random_normal/RandomStandardNormal (0/0 params, 0/0 flops, 0B/0B, RandomStandardNormal)\n ScalarW/Initializer/random_normal/mean (0/0 params, 0/0 flops, 0B/0B, Const)\n ScalarW/Initializer/random_normal/mul (0/0 params, 0/0 flops, 0B/0B, Mul)\n ScalarW/Initializer/random_normal/shape (0/0 params, 0/0 flops, 0B/0B, Const)\n ScalarW/Initializer/random_normal/stddev (0/0 params, 0/0 flops, 0B/0B, Const)\n ScalarW/read (0/0 params, 0/0 flops, 0B/0B, Identity)\n init (0/0 params, 0/0 flops, 0B/0B, NoOp)\n zeros (0/0 params, 0/0 flops, 864B/864B, /job:localhost/replica:0/task:0/cpu:0, /job:localhost/replica:0/task:0/cpu:0|Const)\n ' ,
79
79
f .read ())
80
80
# pylint: enable=line-too-long
81
81
82
82
def testSimpleCodeView (self ):
83
83
ops .reset_default_graph ()
84
84
opts = model_analyzer .TRAINABLE_VARS_PARAMS_STAT_OPTIONS .copy ()
85
- opts ['dump_to_file' ] = os .path .join (test .get_temp_dir (), 'dump' )
85
+ outfile = os .path .join (test .get_temp_dir (), 'dump' )
86
+ opts ['output' ] = 'file:outfile=' + outfile
86
87
opts ['account_type_regexes' ] = ['.*' ]
87
88
opts ['show_name_regexes' ] = ['.*model_analyzer_testlib.*' ]
88
89
opts ['account_displayed_op_only' ] = False
@@ -92,9 +93,7 @@ def testSimpleCodeView(self):
92
93
'bytes' , 'params' , 'float_ops' , 'num_hidden_ops' , 'device' ,
93
94
]
94
95
95
- config = config_pb2 .ConfigProto (
96
- graph_options = config_pb2 .GraphOptions (build_cost_model = 1 ))
97
- with session .Session (config = config ) as sess , ops .device ('/cpu:0' ):
96
+ with session .Session () as sess , ops .device ('/cpu:0' ):
98
97
x = lib .BuildSmallModel ()
99
98
100
99
sess .run (variables .global_variables_initializer ())
@@ -107,7 +106,7 @@ def testSimpleCodeView(self):
107
106
model_analyzer .print_model_analysis (
108
107
sess .graph , run_meta , tfprof_cmd = 'code' , tfprof_options = opts )
109
108
110
- with gfile .Open (opts [ 'dump_to_file' ] , 'r' ) as f :
109
+ with gfile .Open (outfile , 'r' ) as f :
111
110
# pylint: disable=line-too-long
112
111
self .assertEqual (
113
112
'_TFProfRoot (0/451 params, 0/10.44k flops, 0B/5.28KB)\n model_analyzer_testlib.py:33:BuildSmallModel:image = array_ops... (0/0 params, 0/0 flops, 0B/864B)\n model_analyzer_testlib.py:37:BuildSmallModel:initializer=init_... (0/1 params, 0/0 flops, 0B/0B)\n model_analyzer_testlib.py:41:BuildSmallModel:initializer=init_... (0/162 params, 0/0 flops, 0B/1.30KB)\n model_analyzer_testlib.py:42:BuildSmallModel:x = nn_ops.conv2d... (0/0 params, 0/5.83k flops, 0B/432B)\n model_analyzer_testlib.py:46:BuildSmallModel:initializer=init_... (0/288 params, 0/0 flops, 0B/2.30KB)\n model_analyzer_testlib.py:47:BuildSmallModel:x = nn_ops.conv2d... (0/0 params, 0/4.61k flops, 0B/384B)\n ' ,
@@ -117,15 +116,14 @@ def testSimpleCodeView(self):
117
116
def testComplexCodeView (self ):
118
117
ops .reset_default_graph ()
119
118
opts = model_analyzer .TRAINABLE_VARS_PARAMS_STAT_OPTIONS .copy ()
120
- opts ['dump_to_file' ] = os .path .join (test .get_temp_dir (), 'dump' )
119
+ outfile = os .path .join (test .get_temp_dir (), 'dump' )
120
+ opts ['output' ] = 'file:outfile=' + outfile
121
121
opts ['account_type_regexes' ] = ['.*' ]
122
122
opts ['show_name_regexes' ] = ['.*model_analyzer_testlib.py.*' ]
123
123
opts ['account_displayed_op_only' ] = False
124
124
opts ['select' ] = ['params' , 'float_ops' ]
125
125
126
- config = config_pb2 .ConfigProto (
127
- graph_options = config_pb2 .GraphOptions (build_cost_model = 1 ))
128
- with session .Session (config = config ) as sess , ops .device ('/cpu:0' ):
126
+ with session .Session () as sess , ops .device ('/cpu:0' ):
129
127
x = lib .BuildFullModel ()
130
128
131
129
sess .run (variables .global_variables_initializer ())
@@ -139,7 +137,7 @@ def testComplexCodeView(self):
139
137
sess .graph , run_meta , tfprof_cmd = 'code' , tfprof_options = opts )
140
138
141
139
# pylint: disable=line-too-long
142
- with gfile .Open (opts [ 'dump_to_file' ] , 'r' ) as f :
140
+ with gfile .Open (outfile , 'r' ) as f :
143
141
self .assertEqual (
144
142
'_TFProfRoot (0/2.84k params, 0/54.08k flops)\n model_analyzer_testlib.py:56:BuildFullModel:seq.append(array_... (0/1.80k params, 0/41.76k flops)\n model_analyzer_testlib.py:33:BuildSmallModel:image = array_ops... (0/0 params, 0/0 flops)\n model_analyzer_testlib.py:37:BuildSmallModel:initializer=init_... (0/4 params, 0/0 flops)\n model_analyzer_testlib.py:41:BuildSmallModel:initializer=init_... (0/648 params, 0/0 flops)\n model_analyzer_testlib.py:42:BuildSmallModel:x = nn_ops.conv2d... (0/0 params, 0/23.33k flops)\n model_analyzer_testlib.py:46:BuildSmallModel:initializer=init_... (0/1.15k params, 0/0 flops)\n model_analyzer_testlib.py:47:BuildSmallModel:x = nn_ops.conv2d... (0/0 params, 0/18.43k flops)\n model_analyzer_testlib.py:60:BuildFullModel:cell, array_ops.c... (0/1.04k params, 0/4.13k flops)\n model_analyzer_testlib.py:62:BuildFullModel:target = array_op... (0/0 params, 0/0 flops)\n model_analyzer_testlib.py:63:BuildFullModel:loss = nn_ops.l2_... (0/0 params, 0/0 flops)\n model_analyzer_testlib.py:65:BuildFullModel:return sgd_op.min... (0/0 params, 0/8.19k flops)\n ' ,
145
143
f .read ())
@@ -170,9 +168,7 @@ def testCodeViewLeafGraphNode(self):
170
168
'bytes' , 'params' , 'float_ops' , 'num_hidden_ops' , 'device'
171
169
]
172
170
173
- config = config_pb2 .ConfigProto (
174
- graph_options = config_pb2 .GraphOptions (build_cost_model = 1 ))
175
- with session .Session (config = config ) as sess , ops .device ('/cpu:0' ):
171
+ with session .Session () as sess , ops .device ('/cpu:0' ):
176
172
x = lib .BuildSmallModel ()
177
173
178
174
sess .run (variables .global_variables_initializer ())
0 commit comments