Open prashantraina opened 1 week ago
Is this the stub you are referencing? https://github.com/pytorch/pytorch/blob/main/torch%2Fnn%2Fparameter.pyi
Actually no. Small correction, Go to Definition on torch.nn.Parameter.__new__
took me to TensorBase.__new__
.
After pip installing, the stub file is located in site-packages/torch/_C/__init__.pyi
around line 1880.
The closest equivalent in their Github repo is https://github.com/pytorch/pytorch/blob/main/torch/_C/__init__.pyi.in
The subclass' actual __new__
is defined in https://github.com/pytorch/pytorch/blob/main/torch/nn/parameter.py , line 31, which is installed as site-packages/torch/nn/parameter.py
The main problem I'm facing is that the Parameter
constructor is treated as returning a Tensor
, which doesn't happen in PyLance.
FYI PyLance also goes to TensorBase.__new__
when Ctrl+clicking on torch.nn.Parameter.__new__
.
Thanks, if a __new__
is added to the stub for Parameter
then everything works correctly. we will look into this more
Version: VS Code extension v1.13.1 Type checking level: basic
In PyTorch,
torch.nn.Parameter
is a subclass oftorch.Tensor
.For some reason, basedpyright thinks the constructor of
Parameter
returns aTensor
.E.g.
Using Go To Definition on
torch.nn.Parameter.__new__
leads to the stub fortorch.Tensor.__new__
. But using Go To Definition ontorch.nn.Parameter
correctly leads to the class definition ofParameter
, which has an override of__new__
that returnsParameter
.I know ML libraries often have wrong or missing types, but this seems like a language server issue.
Thanks for all you do, btw.