You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Apr 14, 2022. It is now read-only.
Repository navigation
This repository was archived by the owner on Apr 14, 2022. It is now read-only.
With the new PyTorch type stubs (pytorch/pytorch#12500), the stub for the tensor method seems to not be utilized by intellisense (example below). I think this is related to the existence of a module called tensor.py in the PyTorch package - if I delete that file, then the stub is utilized. Maybe the language server is somehow getting confused between whether torch.tensor should be inferred to refer to the module or the method defined in the stub. In this case, it should refer to the stub.
The stub for tensor indicates it has a Tensor return type, but we see vscode not showing Tensor methods here:
Meanwhile the similar as_tensor method, which has the same return type, is working:
I don't have a minimal example at the moment. PyTorch is a big package and in my simple attempts to reduce the problem to a minimal version, VSCode did the right thing, so it's hard for me to tell what exactly is going wrong.
This is with Python 3.7, extension version 2019.5.5433 and VSCode 1.31.1.
I'm checking this against the LS in master (very different than the released one) which does a much better job with stubs, and can at least do:
However, neither torch.tensor nor torch.as_tensor are things which appear in the torch module's __all__ list, which means that they aren't being exposed:
Ya, it's because of dynamic code like that that a type stub was added to aid code completion. You'll see a __init__.pyi in the 'torch' package folder, and that stub explicitly declares a def tensor(...).
I opened this issue because I thought the language server would use the information in the stub, and it does seem to with the exception of the tensor method. It's on the nightly pytorch that I see as_tensor is being suggested as a completion while tensor is not, despite them both being in the stub file.
I installed the nightly with pip install torch_nightly -f https://download.pytorch.org/whl/nightly/cpu/torch_nightly.html.
The version of torch I have installed doesn't have those two functions in the stub, so I'll have to switch up and see. With some __all__ filtering removed, I can see loads of Torch functions already.
Just to say so, the visual difference between -> Tensor and -> 'Tensor' is visual only; the tooltips in the new language server are essentially copies from the declaration to the output, but the analysis itself parses out the string and does something with it.
Activity
jakebailey commentedon Mar 5, 2019
I'm checking this against the LS in master (very different than the released one) which does a much better job with stubs, and can at least do:
However, neither
torch.tensornortorch.as_tensorare things which appear in the torch module's__all__list, which means that they aren't being exposed:https://github.com/pytorch/pytorch/blob/master/torch/__init__.py#L19
Are you on a different version of Torch which exposes those functions? I'm testing with:
jakebailey commentedon Mar 5, 2019
Oh. Gross.
malmaud commentedon Mar 6, 2019
Thanks for looking into this!
Ya, it's because of dynamic code like that that a type stub was added to aid code completion. You'll see a
__init__.pyiin the 'torch' package folder, and that stub explicitly declares adef tensor(...).I opened this issue because I thought the language server would use the information in the stub, and it does seem to with the exception of the
tensormethod. It's on the nightly pytorch that I seeas_tensoris being suggested as a completion whiletensoris not, despite them both being in the stub file.I installed the nightly with
pip install torch_nightly -f https://download.pytorch.org/whl/nightly/cpu/torch_nightly.html.jakebailey commentedon Mar 6, 2019
The version of torch I have installed doesn't have those two functions in the stub, so I'll have to switch up and see. With some
__all__filtering removed, I can see loads of Torch functions already.Just to say so, the visual difference between
-> Tensorand-> 'Tensor'is visual only; the tooltips in the new language server are essentially copies from the declaration to the output, but the analysis itself parses out the string and does something with it.jakebailey commentedon Mar 6, 2019
Alright, testing with the nightly build of torch:
I'm going to close this issue, as it's working as expected in the new LS (which should be released into daily and beta soon).
malmaud commentedon Mar 6, 2019
jakebailey commentedon Mar 6, 2019
0.2.16 is now available on beta channel. You can set this in your VS Code
settings.jsonto get it:malmaud commentedon Mar 6, 2019
Confirmed that switching to the beta channel fixes things on my end too.