Repository navigation
Open
Milestone
Description
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
Labels
No labels
Activity
vadimkantorov commentedon Apr 8, 2017
Possibly it's because Torch inserts the character
⋱(which also doesn't get displayed properly by Putty) in tensor printouts. But anyway, I guess IPython shouldn't crash.Carreau commentedon Apr 10, 2017
ultratab is an extremely old utility that is is desperate need for a refactor. I won't mark that as critical as the refactor is extremely complex but will try to make it relatively pressing.
Marking as 6.1, but we can likely backport to 5.4 or 5.5 if not too complex of a fix.
takluyver commentedon Apr 11, 2017
I'm planning to have a go at reworking that code when I get a chance. I think there are things that can be simplified once we require Python 3, so that will probably be for 6.x+ only, though.
vadimkantorov commentedon Apr 12, 2017
I originally found FormattedTb on StackOveflow as a way to drop automatically into IPython on exception. Is there another more supported way?