parrt / tensor-sensor

The goal of this library is to generate more helpful exception messages for matrix algebra expressions for numpy, pytorch, jax, tensorflow, keras, fastai.
https://github.com/parrt/tensor-sensor
MIT License
794 stars 40 forks source link

Seem a problem with np.ones() function #16

Closed DemonsHunter closed 3 years ago

DemonsHunter commented 4 years ago

Hi! I really thank u for your brilliant work of tsensor which help me to debug more effectively.

But recently, when I run this code in Jupyter or Pycharm, it always leads to a KeyError:

code: with ts.explain(): a = np.ones(3)

KeyError report: KeyError Traceback (most recent call last)

in () 1 with ts.explain(): ----> 2 a = np.ones(3) 3 F:\anaconda_file2\envs\test\lib\site-packages\numpy\core\numeric.py in ones(shape, dtype, order) 206 """ 207 a = empty(shape, dtype, order) --> 208 multiarray.copyto(a, 1, casting='unsafe') 209 return a 210 <__array_function__ internals> in copyto(*args, **kwargs) F:\anaconda_file2\envs\test\lib\site-packages\tsensor\analysis.py in listener(self, frame, event, arg) 266 267 def listener(self, frame, event, arg): --> 268 module = frame.f_globals['__name__'] 269 info = inspect.getframeinfo(frame) 270 filename, line = info.filename, info.lineno KeyError: '__name__' Is there anything I can do to fix this problem? Grateful to gain any feedback!
parrt commented 4 years ago

Hi! Wow, that is strange. Oh, are you using python2? that might be the issue.

On Python 3, I actually get a different error:

>>> with tsensor.explain():
...     a = np.ones(3)
... 
Traceback (most recent call last):
  File "<stdin>", line 2, in <module>
  File "<stdin>", line 2, in <module>
  File "/Users/parrt/github/tensor-sensor/tsensor/analysis.py", line 274, in listener
    self.line_listener(module, name, filename, line, info, frame)
  File "/Users/parrt/github/tensor-sensor/tsensor/analysis.py", line 282, in line_listener
    code = info.code_context[0].strip()
TypeError: 'NoneType' object is not subscriptable
DemonsHunter commented 3 years ago

Sorry for applying too late, actually I use Python3. And I also wonder why the same code leads to different error. I guess that it partly due to the tsenor does not include the function "np.ones". I am not sure and I will keep an eye on related error or issues.

parrt commented 3 years ago

Ok, think I figured this out. You're using ipython and I'm using python. Also, it appears to be different if I run it in interactive mode!!! investigating