Skip to content

FormattedTB causes UnicodeDecodeError when PyTorch is used #10428

@vadimkantorov

Description

@vadimkantorov

The code below should get into debugger after AttributeError "list object has no attribute norm". Instead if crashes during formatting of the traceback with UnicodeDecodeError (it seems it tries to call str on all the tensors in the list passed as an argument).

import sys
import IPython
import torch

def norm(tensor):
        return tensor.norm(2, dim = 1)

sys.excepthook = IPython.core.ultratb.FormattedTB(mode = 'Verbose', color_scheme = 'Linux', call_pdb = 1)
embeddings = [torch.Tensor(2000, 20) for i in range(50)]
norm(embeddings)
Error in sys.excepthook:
Traceback (most recent call last):
  File ".../lib/python2.7/site-packages/IPython/core/ultratb.py", line 1268, in __call__
    self.handler((etype, evalue, etb))
  File ".../lib/python2.7/site-packages/IPython/core/ultratb.py", line 1257, in handler
    ostream.write(self.text(etype, evalue, etb))
  File ".../lib/python2.7/site-packages/IPython/core/ultratb.py", line 567, in text
    tb_offset, context)
  File ".../lib/python2.7/site-packages/IPython/core/ultratb.py", line 1320, in structured_traceback
    self, etype, value, tb, tb_offset, number_of_lines_of_context
  File ".../lib/python2.7/site-packages/IPython/core/ultratb.py", line 1170, in structured_traceback
    tb_offset)
  File ".../lib/python2.7/site-packages/IPython/core/ultratb.py", line 1115, in format_exception_as_a_whole
    frames = self.format_records(records, last_unique, recursion_repeat)
  File ".../lib/python2.7/site-packages/IPython/core/ultratb.py", line 842, in format_records
    frames.append(self.format_record(*r))
  File ".../lib/python2.7/site-packages/IPython/core/ultratb.py", line 1012, in format_record
    lvals.append(tpl_name_val % (name, value))
UnicodeDecodeError: 'ascii' codec can't decode byte 0xe2 in position 204: ordinal not in range(128)

Original exception was:
Traceback (most recent call last):
  File "test.py", line 10, in <module>
    norm(embeddings)
  File "test.py", line 6, in norm
    return tensor.norm(2, dim = 1)
AttributeError: 'list' object has no attribute 'norm'

IPython version: 5.3.0, Python version: 2.7.12, PyTorch tag is 7f03182

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions