Skip to content
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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

TYP: declare torch.utils in __all__ #126401

Open
twoertwein opened this issue May 16, 2024 · 3 comments
Open

TYP: declare torch.utils in __all__ #126401

twoertwein opened this issue May 16, 2024 · 3 comments
Labels
module: python frontend For issues relating to PyTorch's Python frontend module: typing Related to mypy type annotations triaged This issue has been looked at a team member, and triaged and prioritized into an appropriate module

Comments

@twoertwein
Copy link
Contributor

twoertwein commented May 16, 2024

馃悰 Describe the bug

torch.utils is accessible but utils is not declared in __all__ in torch/.__init__.py so type checkers do not know it exists.

impor torch

torch.utils.data.Dataset  # pyright: "utils" is not a known attribute of module "torch" (reportAttributeAccessIssue)

Versions

Collecting environment information...
PyTorch version: 2.3.0
Is debug build: False
CUDA used to build PyTorch: None
ROCM used to build PyTorch: N/A

OS: macOS 14.4.1 (arm64)
GCC version: Could not collect
Clang version: 15.0.0 (clang-1500.3.9.4)
CMake version: Could not collect
Libc version: N/A

Python version: 3.10.14 | packaged by conda-forge | (main, Mar 20 2024, 12:51:49) [Clang 16.0.6 ] (64-bit runtime)
Python platform: macOS-14.4.1-arm64-arm-64bit
Is CUDA available: False
CUDA runtime version: No CUDA
CUDA_MODULE_LOADING set to: N/A
GPU models and configuration: No CUDA
Nvidia driver version: No CUDA
cuDNN version: No CUDA
HIP runtime version: N/A
MIOpen runtime version: N/A
Is XNNPACK available: True

CPU:
Apple M2 Pro

Versions of relevant libraries:
[pip3] numpy==1.24.3
[pip3] onnx==1.16.0
[pip3] tf2onnx==1.16.1
[pip3] torch==2.3.0
[pip3] torchaudio==2.3.0
[conda] numpy 1.24.3 pypi_0 pypi
[conda] torch 2.3.0 pypi_0 pypi
[conda] torchaudio 2.3.0 pypi_0 pypi

cc @ezyang @malfet @xuzhao9 @gramster @albanD

@mikaylagawarecki mikaylagawarecki added the module: typing Related to mypy type annotations label May 20, 2024
@kalium222
Copy link

same for me.

Version

PyTorch version: 2.3.0+cu118
Is debug build: False
CUDA used to build PyTorch: 11.8
ROCM used to build PyTorch: N/A

OS: Arch Linux (x86_64)
GCC version: (GCC) 14.1.1 20240507
Clang version: 17.0.6
CMake version: version 3.28.1
Libc version: glibc-2.39

Python version: 3.12.3 (main, Apr 23 2024, 09:16:07) [GCC 13.2.1 20240417] (64-bit runtime)
Python platform: Linux-6.9.1-zen1-1-zen-x86_64-with-glibc2.39
Is CUDA available: True
CUDA runtime version: Could not collect
CUDA_MODULE_LOADING set to: LAZY
GPU models and configuration: GPU 0: NVIDIA GeForce RTX 4070 SUPER
Nvidia driver version: 550.78
cuDNN version: Could not collect
HIP runtime version: N/A
MIOpen runtime version: N/A
Is XNNPACK available: True

CPU:
Architecture: x86_64
CPU op-mode(s): 32-bit, 64-bit
Address sizes: 39 bits physical, 48 bits virtual
Byte Order: Little Endian
CPU(s): 8
On-line CPU(s) list: 0-7
Vendor ID: GenuineIntel
Model name: Intel(R) Core(TM) i7-1065G7 CPU @ 1.30GHz
...

Versions of relevant libraries:
[pip3] numpy==1.26.4
[pip3] torch==2.3.0+cu118
[pip3] torchaudio==2.3.0+cu118
[pip3] torchvision==0.18.0+cu118
[conda] Could not collect

@jbschlosser jbschlosser added triaged This issue has been looked at a team member, and triaged and prioritized into an appropriate module module: python frontend For issues relating to PyTorch's Python frontend labels May 22, 2024
@albanD
Copy link
Collaborator

albanD commented May 22, 2024

Does submodules need to be in the __all__ in general?

@twoertwein
Copy link
Contributor Author

Does submodules need to be in the __all__ in general?

Not when importing them using from torch import utils or import torch.utils.

The torch namespace does not directly import utils, it seems to be a side effect of from ._tensor import Tensor which makes utils available through the torch namespace.

I'm now using import torch.utils.data so that torch.utils.data.Dataset and torch.utils.data.Dataloader are understood by type checkers.

Feel free to close this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
module: python frontend For issues relating to PyTorch's Python frontend module: typing Related to mypy type annotations triaged This issue has been looked at a team member, and triaged and prioritized into an appropriate module
Projects
None yet
Development

No branches or pull requests

5 participants