I am trying to debug a PyTorch model with pdb, but I cannot seem to get around this particular Unicode encoding error when trying to view the contents of tensors or net parameters, and none of the usual tricks work to strip or reformat Unicode:
(Pdb) dir(params)
['__add__', '__class__', '__contains__', '__delattr__', '__delitem__', '__dir__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__getitem__', '__gt__', '__hash__', '__iadd__', '__imul__', '__init__', '__iter__', '__le__', '__len__', '__lt__', '__mul__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__reversed__', '__rmul__', '__setattr__', '__setitem__', '__sizeof__', '__str__', '__subclasshook__', 'append', 'clear', 'copy', 'count', 'extend', 'index', 'insert', 'pop', 'remove', 'reverse', 'sort']
(Pdb) params
*** UnicodeEncodeError: 'ascii' codec can't encode character '\u22f1' in position 294: ordinal not in range(128)
(Pdb) print(params).encode('ascii', 'ignore').decode('ascii')
*** UnicodeEncodeError: 'ascii' codec can't encode character '\u22f1' in position 294: ordinal not in range(128)
(Pdb) print(params).encode('utf-8')
*** UnicodeEncodeError: 'ascii' codec can't encode character '\u22f1' in position 294: ordinal not in range(128)
(Pdb) print(params).encode('utf-8').strip()
*** UnicodeEncodeError: 'ascii' codec can't encode character '\u22f1' in position 294: ordinal not in range(128)
I can’t even use locals() or globals() in pdb to dump everything:
(Pdb) locals()
*** UnicodeEncodeError: 'ascii' codec can't encode character '\u22f1' in position 335: ordinal not in range(128)
(Pdb) globals()
*** UnicodeEncodeError: 'ascii' codec can't encode character '\u22f1' in position 335: ordinal not in range(128)
Any ideas about a way around this? TIA