Skip to content

Commit aa11628

Browse files
tmctpytorchmergebot
authored andcommitted
Issue warning with reference to user code rather than torch (pytorch#155112)
Re-raising of pytorch#129959 as that was closed. Warning message before: ``` /home/admin/.local/share/hatch/env/virtual/toms-project-1/Qv9k_r_5/dev/lib/python3.10/site-packages/torch/cuda/amp/grad_scaler.py:120: UserWarning: torch.cuda.amp.GradScaler is enabled, but CUDA is not available. Disabling. ``` Warning message after: ``` /path/to/my/code:91: UserWarning: torch.cuda.amp.GradScaler is enabled, but CUDA is not available. Disabling. ``` Helps the user find where the issue stems from in their code. What do you think? (Looks like "skip_file_prefixes" is not available until Python 3.12 minimum...) Pull Request resolved: pytorch#155112 Approved by: https://github.com/Skylion007, https://github.com/cyyever
1 parent 9ca080d commit aa11628

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

torch/amp/grad_scaler.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,8 @@ def __init__(
134134
if self._device == "cuda":
135135
if enabled and torch.cuda.amp.common.amp_definitely_not_available():
136136
warnings.warn(
137-
"torch.cuda.amp.GradScaler is enabled, but CUDA is not available. Disabling."
137+
"torch.cuda.amp.GradScaler is enabled, but CUDA is not available. Disabling.",
138+
stacklevel=2,
138139
)
139140
self._enabled = False
140141

0 commit comments

Comments
 (0)