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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

设备不一致 #1

Open
GDUT-ZJJ opened this issue Nov 21, 2024 · 3 comments
Open

设备不一致 #1

GDUT-ZJJ opened this issue Nov 21, 2024 · 3 comments

Comments

@GDUT-ZJJ
Copy link
Owner

@Dragon1573
{J @7ORP3$1~7SK3P9%K9TY

@Dragon1573
Copy link

终于是复现成功了

命令行日志
20:31:23 D:\Repository 0ms pwsh> cd .\NASA\

20:31:26 D:\...\NASA  [main ≡] 5ms pwsh> git log -n 1 --show-signature
───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
commit 1dc5a6f31c092b2682126d76cebb94a2baff2fdc (HEAD -> main, origin/main, origin/HEAD)
gpg: Signature made Sun May 12 13:34:56 2024
gpg:                using RSA key B5690EEEBB952194
gpg: Good signature from "GitHub <noreply@github.com>" [ultimate]
Author: Xiuze Zhou <zhouxiuze@foxmail.com>
Date:   Sun May 12 13:34:56 2024 +0800

    Add files via upload

20:31:37 D:\...\NASA  [main ≡] 6.416s pwsh> python -m venv .venv

20:32:03 D:\...\NASA  [main ≡ +1 ~0 -0 !] 2.55s pwsh> .\.venv\Scripts\activate

(.venv) 20:32:08 (NASA) D:\...\NASA  [main ≡ +1 ~0 -0 !] 42ms pwsh> python -c 'from sys import version; print(version)'
3.12.7 (tags/v3.12.7:0b05ead, Oct  1 2024, 03:06:41) [MSC v.1941 64 bit (AMD64)]

(.venv) 20:32:24 (NASA) D:\...\NASA  [main ≡ +1 ~0 -0 !] 22ms pwsh> python -m pip install -U torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu124 > $null

(.venv) 20:34:42 (NASA) D:\...\NASA  [main ≡ +1 ~0 -0 !] 2m 2.422s pwsh> python -m pip install -U ipykernel numpy scipy matplotlib scikit-learn > $null

[notice] A new release of pip is available: 24.2 -> 24.3.1
[notice] To update, run: python.exe -m pip install --upgrade pip

(.venv) 20:37:34 (NASA) D:\...\NASA  [main ≡ +1 ~0 -0 !] 1m 37.286s pwsh> python -m pip install -U pip > $null

(.venv) 20:38:55 (NASA) D:\...\NASA  [main ≡ +1 ~0 -0 !] 1.922s pwsh> python -m pip list 'torch*'
Package           Version
----------------- ------------
asttokens         2.4.1
colorama          0.4.6
comm              0.2.2
contourpy         1.3.1
cycler            0.12.1
debugpy           1.8.8
decorator         5.1.1
executing         2.1.0
filelock          3.13.1
fonttools         4.55.0
fsspec            2024.2.0
ipykernel         6.29.5
ipython           8.29.0
jedi              0.19.2
Jinja2            3.1.3
joblib            1.4.2
jupyter_client    8.6.3
jupyter_core      5.7.2
kiwisolver        1.4.7
MarkupSafe        2.1.5
matplotlib        3.9.2
matplotlib-inline 0.1.7
mpmath            1.3.0
nest-asyncio      1.6.0
networkx          3.2.1
numpy             2.1.3
packaging         24.2
parso             0.8.4
pillow            10.2.0
pip               24.3.1
platformdirs      4.3.6
prompt_toolkit    3.0.48
psutil            6.1.0
pure_eval         0.2.3
Pygments          2.18.0
pyparsing         3.2.0
python-dateutil   2.9.0.post0
pywin32           308
pyzmq             26.2.0
scikit-learn      1.5.2
scipy             1.14.1
setuptools        70.0.0
six               1.16.0
stack-data        0.6.3
sympy             1.13.1
threadpoolctl     3.5.0
torch             2.5.1+cu124
torchaudio        2.5.1+cu124
torchvision       0.20.1+cu124
tornado           6.4.1
traitlets         5.14.3
typing_extensions 4.9.0
wcwidth           0.2.13

(.venv) 20:40:27 (NASA) D:\...\NASA  [main ≡ +1 ~0 -0 !] 1ms pwsh> python -m pip install -U notebook > $null

(.venv) 20:43:09 (NASA) D:\...\NASA  [main ≡ +1 ~0 -0 !] 0ms pwsh> python -m jupyter notebook
[I 2024-11-21 20:43:18.150 ServerApp] jupyter_lsp | extension was successfully linked.
[I 2024-11-21 20:43:18.150 ServerApp] jupyter_server_terminals | extension was successfully linked.
[I 2024-11-21 20:43:18.155 ServerApp] jupyterlab | extension was successfully linked.
[I 2024-11-21 20:43:18.160 ServerApp] notebook | extension was successfully linked.
[I 2024-11-21 20:43:18.160 ServerApp] Writing Jupyter server cookie secret to C:\Users\Dragon1573\AppData\Roaming\jupyter\runtime\jupyter_cookie_secret
[I 2024-11-21 20:43:18.482 ServerApp] notebook_shim | extension was successfully linked.
[I 2024-11-21 20:43:18.522 ServerApp] notebook_shim | extension was successfully loaded.
[I 2024-11-21 20:43:18.522 ServerApp] jupyter_lsp | extension was successfully loaded.
[I 2024-11-21 20:43:18.522 ServerApp] jupyter_server_terminals | extension was successfully loaded.
[I 2024-11-21 20:43:18.522 LabApp] JupyterLab extension loaded from D:\Repository\NASA\.venv\Lib\site-packages\jupyterlab
[I 2024-11-21 20:43:18.522 LabApp] JupyterLab application directory is D:\Repository\NASA\.venv\share\jupyter\lab
[I 2024-11-21 20:43:18.527 LabApp] Extension Manager is 'pypi'.
[I 2024-11-21 20:43:18.622 ServerApp] jupyterlab | extension was successfully loaded.
[I 2024-11-21 20:43:18.624 ServerApp] notebook | extension was successfully loaded.
[I 2024-11-21 20:43:18.626 ServerApp] Serving notebooks from local directory: D:\Repository\NASA
[I 2024-11-21 20:43:18.626 ServerApp] Jupyter Server 2.14.2 is running at:
[I 2024-11-21 20:43:18.626 ServerApp] http://localhost:8888/tree?token=e3219bcee91d1befc416debd97cdb90c3316b11549b48cd4
[I 2024-11-21 20:43:18.626 ServerApp]     http://127.0.0.1:8888/tree?token=e3219bcee91d1befc416debd97cdb90c3316b11549b48cd4
[I 2024-11-21 20:43:18.626 ServerApp] Use Control-C to stop this server and shut down all kernels (twice to skip confirmation).
[C 2024-11-21 20:43:18.662 ServerApp]

    To access the server, open this file in a browser:
        file:///C:/Users/Dragon1573/AppData/Roaming/jupyter/runtime/jpserver-43464-open.html
    Or copy and paste one of these URLs:
        http://localhost:8888/tree?token=e3219bcee91d1befc416debd97cdb90c3316b11549b48cd4
        http://127.0.0.1:8888/tree?token=e3219bcee91d1befc416debd97cdb90c3316b11549b48cd4
[I 2024-11-21 20:43:18.942 ServerApp] Skipped non-installed server(s): bash-language-server, dockerfile-language-server-nodejs, javascript-typescript-langserver, jedi-language-server, julia-language-server, pyright, python-language-server, python-lsp-server, r-languageserver, sql-language-server, texlab, typescript-language-server, unified-language-server, vscode-css-languageserver-bin, vscode-html-languageserver-bin, vscode-json-languageserver-bin, yaml-language-server
报错堆栈
---------------------------------------------------------------------------
RuntimeError                              Traceback (most recent call last)
Cell In[10], line 11
      9 MAE, RMSE, RE = [], [], []
     10 for seed in range(10):
---> 11     re_list, mae_list, rmse_list, _ = tain(LR, feature_size, hidden_size, 
     12                                            weight_decay, window_size, EPOCH, seed)
     13     RE.append(np.mean(np.array(re_list)))
     14     MAE.append(np.mean(np.array(mae_list)))

Cell In[9], line 24, in tain(LR, feature_size, hidden_size, weight_decay, window_size, EPOCH, seed)
     21 y = np.reshape(train_y[:,-1]/Rated_Capacity,(-1,1)).astype(np.float32)
     23 X, y = torch.from_numpy(X).to(device), torch.from_numpy(y).to(device)
---> 24 output= model(X)
     25 loss = criterion(output, y)
     26 optimizer.zero_grad()              # clear gradients for this training step

File D:\Repository\NASA\.venv\Lib\site-packages\torch\nn\modules\module.py:1736, in Module._wrapped_call_impl(self, *args, **kwargs)
   1734     return self._compiled_call_impl(*args, **kwargs)  # type: ignore[misc]
   1735 else:
-> 1736     return self._call_impl(*args, **kwargs)

File D:\Repository\NASA\.venv\Lib\site-packages\torch\nn\modules\module.py:1747, in Module._call_impl(self, *args, **kwargs)
   1742 # If we don't have any hooks, we want to skip the rest of the logic in
   1743 # this function, and just call forward.
   1744 if not (self._backward_hooks or self._backward_pre_hooks or self._forward_hooks or self._forward_pre_hooks
   1745         or _global_backward_pre_hooks or _global_backward_hooks
   1746         or _global_forward_hooks or _global_forward_pre_hooks):
-> 1747     return forward_call(*args, **kwargs)
   1749 result = None
   1750 called_always_called_hooks = set()

Cell In[8], line 13, in Net.forward(self, x)
     11 out = self.layer0(x)
     12 for layer in self.layers:
---> 13     out = layer(out)
     14 out = self.linear(out) 
     15 return out

File D:\Repository\NASA\.venv\Lib\site-packages\torch\nn\modules\module.py:1736, in Module._wrapped_call_impl(self, *args, **kwargs)
   1734     return self._compiled_call_impl(*args, **kwargs)  # type: ignore[misc]
   1735 else:
-> 1736     return self._call_impl(*args, **kwargs)

File D:\Repository\NASA\.venv\Lib\site-packages\torch\nn\modules\module.py:1747, in Module._call_impl(self, *args, **kwargs)
   1742 # If we don't have any hooks, we want to skip the rest of the logic in
   1743 # this function, and just call forward.
   1744 if not (self._backward_hooks or self._backward_pre_hooks or self._forward_hooks or self._forward_pre_hooks
   1745         or _global_backward_pre_hooks or _global_backward_hooks
   1746         or _global_forward_hooks or _global_forward_pre_hooks):
-> 1747     return forward_call(*args, **kwargs)
   1749 result = None
   1750 called_always_called_hooks = set()

File D:\Repository\NASA\.venv\Lib\site-packages\torch\nn\modules\container.py:250, in Sequential.forward(self, input)
    248 def forward(self, input):
    249     for module in self:
--> 250         input = module(input)
    251     return input

File D:\Repository\NASA\.venv\Lib\site-packages\torch\nn\modules\module.py:1736, in Module._wrapped_call_impl(self, *args, **kwargs)
   1734     return self._compiled_call_impl(*args, **kwargs)  # type: ignore[misc]
   1735 else:
-> 1736     return self._call_impl(*args, **kwargs)

File D:\Repository\NASA\.venv\Lib\site-packages\torch\nn\modules\module.py:1747, in Module._call_impl(self, *args, **kwargs)
   1742 # If we don't have any hooks, we want to skip the rest of the logic in
   1743 # this function, and just call forward.
   1744 if not (self._backward_hooks or self._backward_pre_hooks or self._forward_hooks or self._forward_pre_hooks
   1745         or _global_backward_pre_hooks or _global_backward_hooks
   1746         or _global_forward_hooks or _global_forward_pre_hooks):
-> 1747     return forward_call(*args, **kwargs)
   1749 result = None
   1750 called_always_called_hooks = set()

File D:\Repository\NASA\.venv\Lib\site-packages\torch\nn\modules\linear.py:125, in Linear.forward(self, input)
    124 def forward(self, input: Tensor) -> Tensor:
--> 125     return F.linear(input, self.weight, self.bias)

RuntimeError: Expected all tensors to be on the same device, but found at least two devices, cpu and cuda:0! (when checking argument for argument mat1 in method wrapper_CUDA_addmm)

@GDUT-ZJJ
Copy link
Owner Author

终于是复现成功了

命令行日志
报错堆栈

谢谢大佬,非常感谢o(╥﹏╥)o

@Dragon1573
Copy link

Dragon1573 commented Nov 22, 2024

要是解决了,可以考虑 Close Issue 。


Edit: 或者我做个 Pull Request 作为 Closer 吧

Dragon1573 added a commit to Dragon1573/NASA that referenced this issue Nov 22, 2024
- Several tensors and modules forget to move to target device.
- They left on CPU while user running the notebook with a CUDA version
  of PyTorch, hence a "device mismatch" error occur.

Signed-off-by: Dragon1573 <49941141+Dragon1573@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants