pytorch - ✅(Solved) Fix __all__ not implemented for torch.amp [1 pull requests, 1 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
pytorch/pytorch#181654Fetched 2026-04-28 06:23:57
View on GitHub
Comments
0
Participants
1
Timeline
41
Reactions
0
Participants
Timeline (top)
mentioned ×18subscribed ×18labeled ×5

PR fix notes

PR #179715: Add all to torch.amp to explicitly declare public API

Description (problem / solution / changelog)

🚀 The feature, motivation and pitch

This PR adds an explicit __all__ attribute to torch/amp/__init__.py to clearly declare the module's public API. Currently, the module imports several names from submodules (_enter_autocast, _exit_autocast, autocast, custom_bwd, custom_fwd, is_autocast_available, GradScaler) but does not declare them in __all__.

According to PEP 8, modules should explicitly declare their public API using the __all__ attribute to better support introspection. Adding __all__ also helps static type checkers like pyright and pylance correctly recognize these names as publicly exported symbols, preventing false-positive "not exported" warnings.

This is a code quality improvement only and has no user-facing impact.

📝 Changes

Added __all__ to torch/amp/__init__.py:

__all__ = [
    "_enter_autocast",
    "_exit_autocast",
    "autocast",
    "custom_bwd",
    "custom_fwd",
    "is_autocast_available",
    "GradScaler",
]

✅ Verification

  • Verified that from torch.amp import * correctly imports only the symbols listed in __all__.
  • Verified that static type checkers (pyright) no longer report "not exported" warnings for these symbols.
  • The change follows the same pattern as previously accepted PRs: #108630 and #78553.

📋 Additional context

Related PRs for reference:

  • #108630: Added __all__ to torch.cuda.amp modules
  • #78553: Added __all__ to torch.profiler

cc @mcarilli @ptrblck @leslie-fang-intel @jgong5

Changed files

  • torch/amp/__init__.py (modified, +10/-0)
RAW_BUFFERClick to expand / collapse

🐛 Describe the bug

The torch.amp module does not have an __all__ variable defined, causing type checkers like Pylance to report problems like "GradScaler" is not exported from module "torch.amp". Other modules (i.e. torch.cpu.amp and torch.cuda.amp) do have this defined, but seeing as torch.amp is recommended over these two, it should also be implemented for them.

#179715 implements the fix for this issue, but was closed by the author before being reviewed by any maintainers.

Versions

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

OS: macOS 26.2 (arm64) GCC version: Could not collect Clang version: 17.0.0 (clang-1700.6.3.2) CMake version: version 4.2.3 Libc version: N/A

Python version: 3.14.0 (main, Oct 31 2025, 23:20:55) [Clang 21.1.4 ] (64-bit runtime) Python platform: macOS-26.2-arm64-arm-64bit-Mach-O 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 Is XPU available: False HIP runtime version: N/A MIOpen runtime version: N/A Is XNNPACK available: True Caching allocator config: N/A

CPU: Apple M4

Versions of relevant libraries: [pip3] Could not collect [conda] Could not collect

cc @lolpack @maggiemoss @ndmitchell @kinto0 @samwgoldman @mcarilli @ptrblck @leslie-fang-intel @jgong5

extent analysis

TL;DR

The missing __all__ variable in the torch.amp module can be fixed by applying the changes from the closed pull request #179715.

Guidance

  • Review the changes in pull request #179715 to understand the proposed fix for the missing __all__ variable.
  • Consider reaching out to the maintainers to reopen the pull request or create a new one with the necessary changes.
  • Verify that the fix resolves the type checker issues reported by Pylance.
  • Check if there are any other modules missing the __all__ variable that may need similar fixes.

Example

No code snippet is provided as the fix is specific to the PyTorch library and requires a pull request or code change.

Notes

The fix is currently not available in the main branch, and the pull request #179715 was closed before being reviewed. The issue may be resolved once the changes are merged into the main branch.

Recommendation

Apply the workaround by manually adding the __all__ variable to the torch.amp module or wait for the official fix to be merged. The reason is that the proposed fix in pull request #179715 seems to address the issue, but it needs to be reviewed and merged by the maintainers.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING

pytorch - ✅(Solved) Fix __all__ not implemented for torch.amp [1 pull requests, 1 participants]