V0.4 - PyCharm "unknown" inspections: `unexpected argument`, `not callable`, etc

After installing PyTorch via pip on Mac, my PyCharm seems to not be recognizing many of the v0.4 commands. For example, for torch.rand the device argument is an unexpected argument, and torch.tensor is considered not callable. Of course, it’s possible to disable these inspections, but I would prefer the inspections remained on if possible. The correct interpreter seems to be being used, so I think it’s due to how the PyTorch code is written that’s causing PyCharm not to recognize this commands in the right way. Is there an existing solution to this issue? Or perhaps am I mistaken with my setup and all the commands should be correctly recognized? Thank you for your time!

2 Likes

We will fix this in the next release. It’s being tracked at:

3 Likes

Good to hear a fix is being discussed. This does however reveal another concerning issue: the PyTorch developers don’t use the JetBrains IDEs. That alone may be enough to drive me back to TensorFlow.

(I’m just kidding. I could never do such a thing.)

I am using pycharm professional connected a remote linux server. powerful!

Haha! :slight_smile: But IMO you do have a point. PyCharm debugger is just awesome and I’m just relying on it more and more in my day to day workflow.

Here’s an example: I’m starting to write some code from scratch. I’m not sure if I got the shapes/outputs right so I just set a breakpoint at a line and run the debugger. Execution stops at the line and now I can either hit Alt+F8 to evaluate expression or open a console and print stuff or plot activations as much as I want. I can also continue writing the code in the expression evaluator to check it works right and copypaste that to the actual code etc. Makes development just that much faster! Still, if others have even more efficient working habits, I’m all ears! :slight_smile:

1 Like

I have a very temporary solution until a real fix is available. This is for those who are very hesitant to disable inspections, but who can’t stand the warnings being listed in PyCharm.

In one of your files in PyCharm, type in torch.abs(). Right click on abs, and select Go To -> Declaration. This will drop you into PyCharm’s auto generated python stubs for PyTorch. For any of the functions that are giving you a warning, just copy an existing function stub, and give it the proper signature for the missing function (don’t worry about the example or description). Your manually added pieces will certainly be overwritten when you make a change to the interpreter that results in re-caching, but it’ll allow you to get rid of the warnings for now at least (and fix some autocomplete, etc).

Hi,

It is still an unsolved issue, right?
With latest updates of both pycharm and pytorch …
So when does PyTorch is going to release that ideal version?

Thanks

Thank you for the reply but I have seen this github issue before and I don’t see any progress in it.
Please let me know if a PyTorch release is not going to solve the problem in the very near future, I don’t waste time and switch back to TF ASAP or don’t use pycharm for the project.

Thank you very much

You’re right. They’ve bumped up the priority on it, but it doesn’t look like any of the main developers directly are working on it. So it’ll probably take a while. And I’m not sure what to tell you between switching back to TF or not using PyCharm. PyCharm is good enough to make that a hard choice.

Any progress on this?

I’d also be interested on the progress on this! :slight_smile:

I think the latest pytorch 1.0.1 or later version has it fixed.