Command handler for print_tensor. Print value of a given dumped tensor. Args: args: Command-line arguments, excluding the command prefix, as a list of str. screen_info: Optional dict input containing screen information such as cols. Returns: Output te
(self, args, screen_info=None)
| 908 | return output |
| 909 | |
| 910 | def print_tensor(self, args, screen_info=None): |
| 911 | """Command handler for print_tensor. |
| 912 | |
| 913 | Print value of a given dumped tensor. |
| 914 | |
| 915 | Args: |
| 916 | args: Command-line arguments, excluding the command prefix, as a list of |
| 917 | str. |
| 918 | screen_info: Optional dict input containing screen information such as |
| 919 | cols. |
| 920 | |
| 921 | Returns: |
| 922 | Output text lines as a RichTextLines object. |
| 923 | """ |
| 924 | |
| 925 | parsed = self._arg_parsers["print_tensor"].parse_args(args) |
| 926 | |
| 927 | np_printoptions = cli_shared.numpy_printoptions_from_screen_info( |
| 928 | screen_info) |
| 929 | |
| 930 | # Determine if any range-highlighting is required. |
| 931 | highlight_options = cli_shared.parse_ranges_highlight(parsed.ranges) |
| 932 | |
| 933 | tensor_name, tensor_slicing = ( |
| 934 | command_parser.parse_tensor_name_with_slicing(parsed.tensor_name)) |
| 935 | |
| 936 | node_name, output_slot = debug_graphs.parse_node_or_tensor_name(tensor_name) |
| 937 | if (self._debug_dump.loaded_partition_graphs() and |
| 938 | not self._debug_dump.node_exists(node_name)): |
| 939 | output = cli_shared.error( |
| 940 | "Node \"%s\" does not exist in partition graphs" % node_name) |
| 941 | _add_main_menu( |
| 942 | output, |
| 943 | node_name=None, |
| 944 | enable_list_tensors=True, |
| 945 | enable_print_tensor=False) |
| 946 | return output |
| 947 | |
| 948 | watch_keys = self._debug_dump.debug_watch_keys(node_name) |
| 949 | if output_slot is None: |
| 950 | output_slots = set() |
| 951 | for watch_key in watch_keys: |
| 952 | output_slots.add(int(watch_key.split(":")[1])) |
| 953 | |
| 954 | if len(output_slots) == 1: |
| 955 | # There is only one dumped tensor from this node, so there is no |
| 956 | # ambiguity. Proceed to show the only dumped tensor. |
| 957 | output_slot = list(output_slots)[0] |
| 958 | else: |
| 959 | # There are more than one dumped tensors from this node. Indicate as |
| 960 | # such. |
| 961 | # TODO(cais): Provide an output screen with command links for |
| 962 | # convenience. |
| 963 | lines = [ |
| 964 | "Node \"%s\" generated debug dumps from %s output slots:" % |
| 965 | (node_name, len(output_slots)), |
| 966 | "Please specify the output slot: %s:x." % node_name |
| 967 | ] |