-
Notifications
You must be signed in to change notification settings - Fork 764
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
"Parameter" is not exported from module "torch.nn" #2953
Comments
I have just checked that the issue can be reproduced with the latest torch as well (1.11.0). |
torch==1.11.0 worked for me on windows with python 3.10 |
couldn't repro on linux. any luck on your side? |
I get the same error as well.
I'm on
|
nope, and in fact I have been experiencing this issue for a long time |
Torch is a "py.typed" library which means it contains inlined type information. When a library is marked "py.typed", pyright (the type checker that underlies pylance) applies certain rules to determine whether specific symbols are intended to be visible from a module. These rules are documented here. The module If you believe that As a workaround, you can access the You can also configure pylance to disable the |
Thank you for the detailed answer! I created the issue in the PyTorch repository. P.S. Is the approach |
This approach was standardized in PEP 484 for type stubs. It hasn't been officially adopted in a PEP for "py.typed" libraries, but there is general consensus among type checker authors that it makes sense to use the pattern established by PEP 484. This guidance has been posted on the python/typing site. The |
Related: https://github.com/pytorch/pytorch/wiki/Public-API-definition-and-documentation Related: microsoft/pylance-release#2953 This fixes pylance issues for these classes: ``` "FullyShardedDataParallel" is not exported from module "torch.distributed.fsdp" ``` These classes all have public docs: * [`BackwardPrefetch`](https://pytorch.org/docs/stable/fsdp.html#torch.distributed.fsdp.BackwardPrefetch) * [`CPUOffload`](https://pytorch.org/docs/stable/fsdp.html#torch.distributed.fsdp.CPUOffload) * [`FullyShardedDataParallel`](https://pytorch.org/docs/stable/fsdp.html#torch.distributed.fsdp.FullyShardedDataParallel) * [`MixedPrecision`](https://pytorch.org/docs/stable/fsdp.html#torch.distributed.fsdp.MixedPrecision) * [`ShardingStrategy`](https://pytorch.org/docs/stable/fsdp.html#torch.distributed.fsdp.ShardingStrategy) And it seems like all the newly added classes will have docs once they are released. Pull Request resolved: #109922 Approved by: https://github.com/wanchaol
Python type checker libraries such as Pyrite have built a consensus around PEP 484 for how to export symbols from a py.typed library. This requires redundantly re-exporting symbols to make them publicly visible. Without re-exporting the symbol type checkers will complain that the symbol (e.g., from aws_error_utils.errors) is not exported, but a direct import will work as expected (e.g., from aws_error_utils.aws_error_utils import errors). Based on official Python guidance to type checkers: https://github.com/python/typing/blob/master/docs/source/libraries.rst#library-interface-public-and-private-symbols For more detail from author of Pyrite (for a similar issue in PyTorch): microsoft/pylance-release#2953 (comment)
Python type checker libraries such as Pyright have built a consensus around PEP 484 for how to export symbols from a py.typed library. This requires redundantly re-exporting symbols to make them publicly visible. Without re-exporting the symbol type checkers will complain that the symbol (e.g., from aws_error_utils.errors) is not exported, but a direct import will work as expected (e.g., from aws_error_utils.aws_error_utils import errors). Based on official Python guidance to type checkers: https://github.com/python/typing/blob/master/docs/source/libraries.rst#library-interface-public-and-private-symbols For more detail from author of Pyright (for a similar issue in PyTorch): microsoft/pylance-release#2953 (comment)
Follows pattern introduced by #80955 which [pyright](https://github.com/microsoft/pyright) prefers over `__all__` symbol, see microsoft/pylance-release#2953 (comment) Fixes #134985 Pull Request resolved: #135043 Approved by: https://github.com/janeyx99
Follows pattern introduced by pytorch#80955 which [pyright](https://github.com/microsoft/pyright) prefers over `__all__` symbol, see microsoft/pylance-release#2953 (comment) Fixes pytorch#134985 Pull Request resolved: pytorch#135043 Approved by: https://github.com/janeyx99
Follows pattern introduced by pytorch#80955 which [pyright](https://github.com/microsoft/pyright) prefers over `__all__` symbol, see microsoft/pylance-release#2953 (comment) Fixes pytorch#134985 Pull Request resolved: pytorch#135043 Approved by: https://github.com/janeyx99
Follows pattern introduced by pytorch#80955 which [pyright](https://github.com/microsoft/pyright) prefers over `__all__` symbol, see microsoft/pylance-release#2953 (comment) Fixes pytorch#134985 Pull Request resolved: pytorch#135043 Approved by: https://github.com/janeyx99
Environment data
I am working on this repository. So, my environment can be reproduced as follows:
Code Snippet
Create a file
rtdl/a.py
with the following content:Expected behavior
I expect no warnings and no red underlines regarding
nn.Parameter
. mypy agrees with me and does not complain about this file.Actual behavior
The
nn.Parameter
is underlined in red. Interestingly, when I hover over it, I see the correctly inferred docstring, but in the end at also contains the following error message:"Parameter" is not exported from module "torch.nn" Pylance (reportPrivateImportUsage)"
Logs
The logs are going beyond the GitHub limits :( If they are needed, what are the relevant parts that I should provide?
The text was updated successfully, but these errors were encountered: