diff options
author | Nick Felt <nickfelt@google.com> | 2018-09-21 15:48:47 -0700 |
---|---|---|
committer | TensorFlower Gardener <gardener@tensorflow.org> | 2018-09-21 15:53:04 -0700 |
commit | 5d7d8f9f7500e1b648e62fdd43f6d2999524e833 (patch) | |
tree | 85278e7d68be773e378d6f1300eae47ffc1cb030 /tensorflow/contrib/tensorboard | |
parent | 47d8a750bc0a9e3165e8fc61d38df3646bf8f278 (diff) |
Remove unused tf.contrib.tensorboard.plugins.trace code
PiperOrigin-RevId: 214056834
Diffstat (limited to 'tensorflow/contrib/tensorboard')
6 files changed, 1 insertions, 378 deletions
diff --git a/tensorflow/contrib/tensorboard/BUILD b/tensorflow/contrib/tensorboard/BUILD index 2b6a2b2f3c..7f0b3255ed 100644 --- a/tensorflow/contrib/tensorboard/BUILD +++ b/tensorflow/contrib/tensorboard/BUILD @@ -32,7 +32,6 @@ py_library( srcs_version = "PY2AND3", deps = [ ":projector", - ":trace", ], ) @@ -60,33 +59,3 @@ py_test( "//tensorflow/python:summary", ], ) - -# API methods and protos in `tf.contrib.tensorboard.plugins.trace` package. -py_library( - name = "trace", - srcs = glob( - ["plugins/trace/**/*.py"], - exclude = ["**/*test*"], - ), - srcs_version = "PY2AND3", - deps = [ - ":protos_all_py", - "//tensorflow/python:framework_for_generated_wrappers", - "//tensorflow/python:lib", - "//tensorflow/python:platform", - ], -) - -py_test( - name = "trace_test", - size = "small", - srcs = ["plugins/trace/trace_test.py"], - srcs_version = "PY2AND3", - tags = ["no_windows"], - deps = [ - ":trace", - "//tensorflow/python:client_testlib", - "//tensorflow/python:framework_for_generated_wrappers", - "//tensorflow/python:platform", - ], -) diff --git a/tensorflow/contrib/tensorboard/plugins/__init__.py b/tensorflow/contrib/tensorboard/plugins/__init__.py index 41aa77910c..4ba469eb52 100644 --- a/tensorflow/contrib/tensorboard/plugins/__init__.py +++ b/tensorflow/contrib/tensorboard/plugins/__init__.py @@ -20,4 +20,4 @@ from __future__ import print_function # Add projects here, they will show up under tf.contrib.tensorboard.plugins from tensorflow.contrib.tensorboard.plugins import projector -from tensorflow.contrib.tensorboard.plugins import trace + diff --git a/tensorflow/contrib/tensorboard/plugins/trace/__init__.py b/tensorflow/contrib/tensorboard/plugins/trace/__init__.py deleted file mode 100644 index 2c99f4077e..0000000000 --- a/tensorflow/contrib/tensorboard/plugins/trace/__init__.py +++ /dev/null @@ -1,24 +0,0 @@ -# Copyright 2016 The TensorFlow Authors. All Rights Reserved. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# ============================================================================== -"""Public API for the Trace plugin.""" - -from __future__ import absolute_import -from __future__ import division -from __future__ import print_function - -# pylint: disable=wildcard-import -from tensorflow.contrib.tensorboard.plugins.trace.trace import * -from tensorflow.contrib.tensorboard.plugins.trace.trace_info_pb2 import * -# pylint: enable=wildcard-import diff --git a/tensorflow/contrib/tensorboard/plugins/trace/trace.py b/tensorflow/contrib/tensorboard/plugins/trace/trace.py deleted file mode 100644 index 07e5316b8b..0000000000 --- a/tensorflow/contrib/tensorboard/plugins/trace/trace.py +++ /dev/null @@ -1,167 +0,0 @@ -# Copyright 2016 The TensorFlow Authors. All Rights Reserved. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# ============================================================================== -"""Stores debugging information regarding TensorFlow model.""" - -from __future__ import absolute_import -from __future__ import division -from __future__ import print_function - -import os -import parser -import re -import token - -from google.protobuf import json_format - -from tensorflow.contrib.tensorboard.plugins.trace.trace_info_pb2 import TraceInfo -from tensorflow.python.framework import ops -from tensorflow.python.platform import gfile - -# List of regex patterns that match files in the core tensorflow library. -TF_LIB_REGEX_FPATHS = [os.sep + os.path.join('tensorflow', 'python')] - -LEFT_TOKENS = [token.LPAR, token.LSQB, token.LBRACE] -RIGHT_TOKENS = [token.RPAR, token.RSQB, token.RBRACE] -TOKENS = LEFT_TOKENS + RIGHT_TOKENS - - -def store_trace_info(output_file_path, - graph=None, - ignore_regex_fpaths=None): - """Collects and stores trace information for a TensorFlow model. - - The output proto is stored in json format. - - Args: - output_file_path: The path where to store the output proto. - graph: Optional. The data flow graph. Defaults to `tf.get_default_graph()`. - ignore_regex_fpaths: Optional. Files whose path matches any of the regexes - in this list will be ignored. Defaults to patterns that match the core - tensorflow python library. - """ - graph = graph or ops.get_default_graph() - - if not ignore_regex_fpaths: - ignore_regex_fpaths = TF_LIB_REGEX_FPATHS - - trace_info = TraceInfo() - # Extract trace information for every op in the graph. - source_fpaths = set() - for op in graph.get_operations(): - op_info = trace_info.ops.add() - op_info.name = op.name - op_info.op_type = op.type - op_info.device = op.device - for trace in op.traceback: - fname, lineno, _, _ = trace - # Ignore traces in specified file paths. - if os.path.isabs(fname) and not _ignore_file_path(fname, - ignore_regex_fpaths): - line_trace = op_info.traceback.add() - line_trace.file_path = fname - line_trace.line_number = lineno - source_fpaths.add(fname) - _add_data_from_tensors(op.inputs, op_info.inputs) - _add_data_from_tensors(op.outputs, op_info.outputs) - - # Read the source files involved in the graph construction. - for fpath in source_fpaths: - file_info = trace_info.files.add() - - with gfile.Open(fpath, 'r') as f: - source = f.read() - - file_info.file_path = fpath - file_info.source_code = source - - line2start = find_multiline_statements(source) - - for key, value in line2start.items(): - file_info.multiline_statements[key] = value - - # Make sure the directory for the output file exists. - output_file_path = os.path.expanduser(output_file_path) - output_dir = os.path.dirname(output_file_path) - if not gfile.Exists(output_dir): - gfile.MakeDirs(output_dir) - - # Store the debug information. - with gfile.Open(output_file_path, 'w') as f: - f.write(json_format.MessageToJson(trace_info)) - - -def find_multiline_statements(source): - """Parses the python source and finds multiline statements. - - Based on counting the number of open and closed parenthesis on each line. - - Args: - source: The source code string. - - Returns: - A dict that maps a line index A to a line index B, where A is the end of a - multiline statement and B is the start. Line indexing is 0-based. - """ - # Get the AST. - tree = parser.suite(source) - line2paren_count = [0] * (source.count('\n') + 1) - _count_brackets_braces_parenthesis(tree.totuple(True), line2paren_count) - - line2start = {} - for end in range(len(line2paren_count)): - if line2paren_count[end] >= 0: - # This is not the end of a multiline statement. - continue - cumulative_paren_count = 0 - for start in range(end, -1, -1): - cumulative_paren_count += line2paren_count[start] - if cumulative_paren_count == 0: - line2start[end] = start - break - return line2start - - -def _add_data_from_tensors(tensors, info): - for t in tensors: - tensor_info = info.add() - - shape = t.get_shape() - if shape.ndims: - shape = [(-1 if s is None else s) for s in shape.as_list()] - tensor_info.shape.extend(shape) - tensor_info.dtype = t.dtype.name - tensor_info.num_bytes_per_elem = t.dtype.size - - for c in t.consumers(): - tensor_info.consumers.append(c.name) - - -def _ignore_file_path(fname, ignore_regex_fpaths): - for regex_pattern in ignore_regex_fpaths: - if re.search(regex_pattern, fname): - return True - return False - - -def _count_brackets_braces_parenthesis(node, line2par): - if isinstance(node[1], tuple): - for child in node[1:]: - _count_brackets_braces_parenthesis(child, line2par) - else: - tok = node[0] - if tok in TOKENS: - lineno = node[2] - line2par[lineno - 1] += (1 if tok in LEFT_TOKENS else -1) - return line2par diff --git a/tensorflow/contrib/tensorboard/plugins/trace/trace_info.proto b/tensorflow/contrib/tensorboard/plugins/trace/trace_info.proto deleted file mode 100644 index 9f20becb0f..0000000000 --- a/tensorflow/contrib/tensorboard/plugins/trace/trace_info.proto +++ /dev/null @@ -1,60 +0,0 @@ -/* Copyright 2016 The TensorFlow Authors. All Rights Reserved. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -==============================================================================*/ - -syntax = "proto3"; - -package tensorflow.contrib.tensorboard; - -message TraceInfo { - repeated OpInfo ops = 1; - repeated FileInfo files = 2; -} - -message OpInfo { - string name = 1; - string op_type = 2; - string device = 3; - repeated LineTrace traceback = 4; - repeated TensorInfo inputs = 5; - repeated TensorInfo outputs = 6; -} - -message LineTrace { - // Absolute file path. - string file_path = 1; - // 1-based line number. - uint32 line_number = 2; -} - -message TensorInfo { - // Size of the tensor for each dimension. Value of -1 denotes "unknown" - // size for that dimension. - repeated int32 shape = 1; - // The data type of the tensor. - string dtype = 2; - // Number of bytes per element in the tensor. - uint32 num_bytes_per_elem = 3; - // List of operation names that consume this tensor. - repeated string consumers = 4; -} - -message FileInfo { - // Absolute file path to the source code. - string file_path = 1; - string source_code = 2; - // Map from end of statement to start of statement. End and start are 0-based - // line indexes. - map<uint32, uint32> multiline_statements = 3; -} diff --git a/tensorflow/contrib/tensorboard/plugins/trace/trace_test.py b/tensorflow/contrib/tensorboard/plugins/trace/trace_test.py deleted file mode 100644 index d580f04c5f..0000000000 --- a/tensorflow/contrib/tensorboard/plugins/trace/trace_test.py +++ /dev/null @@ -1,95 +0,0 @@ -# Copyright 2016 The TensorFlow Authors. All Rights Reserved. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# ============================================================================== -"""Tests for tensorflow.contrib.tensorboard.plugins.trace package.""" - -from __future__ import absolute_import -from __future__ import division -from __future__ import print_function - -import tempfile - -from google.protobuf import json_format - -from tensorflow.contrib.tensorboard.plugins import trace -from tensorflow.python.framework import constant_op -from tensorflow.python.platform import gfile -from tensorflow.python.platform import test - - -class TraceTest(test.TestCase): - - def setUp(self): - self._temp_dir = tempfile.mkdtemp() - self._temp_trace_json = self._temp_dir + 'trace.json' - - def tearDown(self): - gfile.DeleteRecursively(self._temp_dir) - - def testEmptyGraph(self): - trace_info = self._store_and_read_trace_info() - self.assertEqual(len(trace_info.ops), 0) - - def testHasSourceCodeOfThisFile(self): - constant_op.constant(0) - trace_info = self._store_and_read_trace_info() - - self.assertTrue(trace_info.files) - for file_info in trace_info.files: - if file_info.file_path.endswith('trace_test.py'): - return - self.fail('trace_test file not found in the trace info json') - - def testHasTheConstantOp(self): - constant_op.constant(0) - trace_info = self._store_and_read_trace_info() - - self.assertTrue(trace_info.ops) - - for op in trace_info.ops: - if op.op_type == 'Const': - return - self.fail('Could not find operation of type `Const` in the graph') - - def testMultilineStatements(self): - source = """def test(): - a(4, - 3, - 1) - - b(3, 4, 5) - - c((4, 3), - (), - ) - """ - line2start = trace.find_multiline_statements(source) - - self.assertEqual(line2start[3], 1) - self.assertEqual(line2start[9], 7) - self.assertEqual(len(line2start), 2) - - def _store_and_read_trace_info(self): - trace.store_trace_info(self._temp_trace_json) - trace_info = trace.TraceInfo() - - with gfile.Open(self._temp_trace_json) as f: - text = f.read() - json_format.Parse(text, trace_info) - - return trace_info - - -if __name__ == '__main__': - test.main() |