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

Function annotate_source

tensorflow/python/debug/lib/source_utils.py:93–157  ·  view source on GitHub ↗

Annotate a Python source file with a list of ops created at each line. (The annotation doesn't change the source file itself.) Args: dump: (`DebugDumpDir`) A `DebugDumpDir` object of which the Python graph has been loaded. source_file_path: (`str`) Path to the source file being a

(dump,
                    source_file_path,
                    do_dumped_tensors=False,
                    file_stack_top=False,
                    min_line=None,
                    max_line=None)

Source from the content-addressed store, hash-verified

91
92
93def annotate_source(dump,
94 source_file_path,
95 do_dumped_tensors=False,
96 file_stack_top=False,
97 min_line=None,
98 max_line=None):
99 """Annotate a Python source file with a list of ops created at each line.
100
101 (The annotation doesn't change the source file itself.)
102
103 Args:
104 dump: (`DebugDumpDir`) A `DebugDumpDir` object of which the Python graph
105 has been loaded.
106 source_file_path: (`str`) Path to the source file being annotated.
107 do_dumped_tensors: (`str`) Whether dumped Tensors, instead of ops are to be
108 used to annotate the source file.
109 file_stack_top: (`bool`) Whether only the top stack trace in the
110 specified source file is to be annotated.
111 min_line: (`None` or `int`) The 1-based line to start annotate the source
112 file from (inclusive).
113 max_line: (`None` or `int`) The 1-based line number to end the annotation
114 at (exclusive).
115
116 Returns:
117 A `dict` mapping 1-based line number to a list of op name(s) created at
118 that line, or tensor names if `do_dumped_tensors` is True.
119
120 Raises:
121 ValueError: If the dump object does not have a Python graph set.
122 """
123
124 py_graph = dump.python_graph
125 if not py_graph:
126 raise ValueError("Cannot perform source annotation due to a lack of set "
127 "Python graph in the dump object")
128
129 source_file_path = _norm_abs_path(source_file_path)
130
131 line_to_op_names = {}
132 for op in py_graph.get_operations():
133 for file_path, line_number, _, _ in reversed(dump.node_traceback(op.name)):
134 if (min_line is not None and line_number < min_line or
135 max_line is not None and line_number >= max_line):
136 continue
137
138 if _norm_abs_path(file_path) != source_file_path:
139 continue
140
141 if do_dumped_tensors:
142 watch_keys = dump.debug_watch_keys(op.name)
143 # Convert watch keys to unique Tensor names.
144 items_to_append = list(
145 set(map(_convert_watch_key_to_tensor_name, watch_keys)))
146 else:
147 items_to_append = [op.name]
148
149 if line_number in line_to_op_names:
150 line_to_op_names[line_number].extend(items_to_append)

Callers

nothing calls this directly

Calls 5

_norm_abs_pathFunction · 0.85
get_operationsMethod · 0.80
node_tracebackMethod · 0.80
debug_watch_keysMethod · 0.80
extendMethod · 0.45

Tested by

no test coverage detected