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

Function _parse_debug_tensor_name

tensorflow/python/debug/cli/evaluator.py:34–103  ·  view source on GitHub ↗

Parse a debug tensor name in a to-be-evaluated expression. Args: debug_tensor_name: name of the debug tensor, with or without device name as a prefix, with or without debug op, with or without '[ ]' as a suffix. E.g., without device name prefix, without debug op s

(debug_tensor_name)

Source from the content-addressed store, hash-verified

32
33
34def _parse_debug_tensor_name(debug_tensor_name):
35 # pylint: disable=line-too-long
36 """Parse a debug tensor name in a to-be-evaluated expression.
37
38 Args:
39 debug_tensor_name: name of the debug tensor, with or without
40 device name as a prefix, with or without debug op, with or
41 without '[<exec_index>]' as a suffix.
42 E.g., without device name prefix, without debug op suffix:
43 "hidden_0/MatMul:0"
44 E.g., with device name prefix:
45 "/job:worker/replica:0/task:1/gpu:0:hidden_0/MatMul:0"
46 E.g., with debug op suffix:
47 "hidden_0/MatMul:0:DebugNumericSummary"
48 E.g., with device name prefix and debug op suffix:
49 "/job:worker/replica:0/task:1/gpu:0:hidden_0/MatMul:0:DebugNumericSummary"
50 E.g., with device name prefix, debug op and an exec index:
51 "/job:worker/replica:0/task:1/gpu:0:hidden_0/MatMul:0:DebugNumericSummary[1]"
52
53 Returns:
54 device_name: If device name prefix exists, the device name; otherwise,
55 `None`.
56 node_name: Name of the node.
57 output_slot: Output slot index as an `int`.
58 debug_op: If the debug op suffix exists, the debug op name; otheriwse,
59 `None`.
60 exec_index: Execution index (applicable to cases in which a debug tensor
61 is computed multiple times in a `tf.Session.run` call, e.g., due to
62 `tf.while_loop`). If the exec_index suffix does not exist, this value
63 defaults to `0`.
64
65 Raises:
66 ValueError: If the input `debug_tensor_name` is malformed.
67 """
68 # pylint: enable=line-too-long
69 device_prefix_match = re.match(_DEVICE_NAME_PREFIX_PATTERN, debug_tensor_name)
70 if device_prefix_match:
71 device_name = debug_tensor_name[
72 device_prefix_match.start() : device_prefix_match.end() - 1]
73 debug_tensor_name = debug_tensor_name[device_prefix_match.end():]
74 else:
75 device_name = None
76
77 split_items = debug_tensor_name.split(":")
78 if len(split_items) not in (2, 3):
79 raise ValueError(
80 "The debug tensor name in the to-be-evaluated expression is malformed: "
81 "'%s'" % debug_tensor_name)
82 # TODO(cais): Provide examples of good debug tensor names in the error
83 # message.
84
85 exec_index_match = re.search(_EXEC_INDEX_SUFFIX_PATTERN, split_items[-1])
86 if exec_index_match:
87 exec_index = int(split_items[-1][
88 exec_index_match.start() + 1 : exec_index_match.end() - 1])
89 split_items[-1] = split_items[-1][:exec_index_match.start()]
90 else:
91 exec_index = 0

Callers 1

evaluateMethod · 0.85

Calls 4

matchMethod · 0.45
startMethod · 0.45
endMethod · 0.45
splitMethod · 0.45

Tested by

no test coverage detected