( # noqa: C901
evalue: EValue, show_meminfo: bool, mark_dynamic_shape_tensor: bool
)
| 77 | |
| 78 | |
| 79 | def _format_evalue( # noqa: C901 |
| 80 | evalue: EValue, show_meminfo: bool, mark_dynamic_shape_tensor: bool |
| 81 | ) -> str: |
| 82 | evstr = "\033[34m" |
| 83 | if isinstance(evalue.val, Tensor): |
| 84 | tensor = evalue.val |
| 85 | if tensor.data_buffer_idx > 0: |
| 86 | assert not _is_dynamic_shape_tensor( |
| 87 | tensor |
| 88 | ), "A constant tensor can not be dynamic shape" |
| 89 | evstr += "CT" # constant tensor |
| 90 | assert tensor.allocation_info is None |
| 91 | else: |
| 92 | if mark_dynamic_shape_tensor: |
| 93 | if tensor.shape_dynamism == TensorShapeDynamism.DYNAMIC_BOUND: |
| 94 | evstr += "UB" # upper bound tensor will be shown as 'UBT' |
| 95 | elif tensor.shape_dynamism == TensorShapeDynamism.DYNAMIC_UNBOUND: |
| 96 | evstr += "DU" # dynamic unbound tensor will be shown as 'DUT' |
| 97 | evstr += "T" |
| 98 | if show_meminfo: |
| 99 | if tensor.allocation_info: |
| 100 | evstr += f"m{tensor.allocation_info.memory_id}.{tensor.allocation_info.memory_offset}" |
| 101 | else: |
| 102 | evstr += "m." |
| 103 | evstr += f"{tensor.sizes}{_scalar_type_str(tensor.scalar_type)}" |
| 104 | elif isinstance(evalue.val, TensorList): |
| 105 | evstr += "TL" |
| 106 | tensorlist = evalue.val |
| 107 | # pyre-ignore |
| 108 | evstr += str(tensorlist.items) |
| 109 | elif isinstance(evalue.val, OptionalTensorList): |
| 110 | evstr += "OTL" |
| 111 | optionaltensorlist = evalue.val |
| 112 | # pyre-ignore |
| 113 | evstr += str(optionaltensorlist.items) |
| 114 | elif isinstance(evalue.val, IntList): |
| 115 | evstr += "IL" |
| 116 | intlist = evalue.val |
| 117 | # pyre-ignore |
| 118 | evstr += str(intlist.items) |
| 119 | elif isinstance(evalue.val, DoubleList): |
| 120 | evstr += "DL" |
| 121 | doublelist = evalue.val |
| 122 | # pyre-ignore |
| 123 | evstr += str(doublelist.items) |
| 124 | elif isinstance(evalue.val, BoolList): |
| 125 | evstr += "BL" |
| 126 | boollist = evalue.val |
| 127 | # pyre-ignore |
| 128 | evstr += str(boollist.items) |
| 129 | elif isinstance(evalue.val, Int): |
| 130 | intval = evalue.val |
| 131 | evstr += f"I{intval.int_val}" |
| 132 | elif isinstance(evalue.val, Double): |
| 133 | doubleval = evalue.val |
| 134 | evstr += f"D{doubleval.double_val}" |
| 135 | elif isinstance(evalue.val, Bool): |
| 136 | boolval = evalue.val |
no test coverage detected