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

Fastai version 2.7.14 produces "AttributeError: device" when running .predict #4013

Open
mumbledenoise opened this issue Mar 3, 2024 · 1 comment

Comments

@mumbledenoise
Copy link

mumbledenoise commented Mar 3, 2024

Please confirm you have the latest versions of fastai, fastcore, and nbdev prior to reporting a bug (delete one): YES

Describe the bug
Running a prediction on Fastai 2.7.14 produces "AttributeError: device" when running .predict. Downgrading to 2.7.13 fixes it. I'm guessing this is because I'm using torch 1.13.1.

To Reproduce
Steps to reproduce the behavior:

Here are the logs of me reproducing the behavior, along with the fix:

root@Ubuntu-2204-jammy-amd64-base ~/run/gpu # python3
Python 3.10.12 (main, Nov 20 2023, 15:14:05) [GCC 11.4.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from fastai.text.all import *
>>> sent = load_learner('model_3.pkl', cpu=False).to_fp16()
>>> sent.predict('hello')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python3.10/dist-packages/fastai/learner.py", line 320, in predict
    dl = self.dls.test_dl([item], rm_type_tfms=rm_type_tfms, num_workers=0)
  File "/usr/local/lib/python3.10/dist-packages/fastai/data/core.py", line 526, in test_dl
    return self.valid.new(test_ds, **kwargs)
  File "/usr/local/lib/python3.10/dist-packages/fastai/text/data.py", line 218, in new
    return super().new(dataset=dataset, res=res, **kwargs)
  File "/usr/local/lib/python3.10/dist-packages/fastai/data/core.py", line 94, in new
    res = super().new(dataset, cls, do_setup=False, **kwargs)
  File "/usr/local/lib/python3.10/dist-packages/fastai/data/load.py", line 144, in new
    bs=self.bs, shuffle=self.shuffle, drop_last=self.drop_last, indexed=self.indexed, device=self.device)
  File "/usr/local/lib/python3.10/dist-packages/fastcore/basics.py", line 496, in __getattr__
    if attr is not None: return getattr(attr,k)
  File "/usr/local/lib/python3.10/dist-packages/fastai/data/core.py", line 450, in __getattr__
    def __getattr__(self,k): return gather_attrs(self, k, 'tls')
  File "/usr/local/lib/python3.10/dist-packages/fastcore/transform.py", line 173, in gather_attrs
    if not res: raise AttributeError(k)
AttributeError: device

>>> exit()
root@Ubuntu-2204-jammy-amd64-base ~/run/gpu # pip show fastcore
Name: fastcore
Version: 1.5.29
Summary: Python supercharged for fastai development
Home-page: https://github.com/fastai/fastcore/
Author: Jeremy Howard and Sylvain Gugger
Author-email: infos@fast.ai
License: Apache Software License 2.0
Location: /usr/local/lib/python3.10/dist-packages
Requires: packaging, pip
Required-by: fastai, fastdownload, ohmeow-blurr

root@Ubuntu-2204-jammy-amd64-base ~/run/gpu # pip show fastai
Name: fastai
Version: 2.7.14
Summary: fastai simplifies training fast and accurate neural nets using modern best practices
Home-page: https://github.com/fastai/fastai
Author: Jeremy Howard, Sylvain Gugger, and contributors
Author-email: info@fast.ai
License: Apache Software License 2.0
Location: /usr/local/lib/python3.10/dist-packages
Requires: fastcore, fastdownload, fastprogress, matplotlib, packaging, pandas, pillow, pip, pyyaml, requests, scikit-learn, scipy, spacy, torch, torchvision
Required-by: fastinference, ohmeow-blurr

root@Ubuntu-2204-jammy-amd64-base ~/run/gpu # pip show torch
Name: torch
Version: 1.13.1
Summary: Tensors and Dynamic neural networks in Python with strong GPU acceleration
Home-page: https://pytorch.org/
Author: PyTorch Team
Author-email: packages@pytorch.org
License: BSD-3
Location: /usr/local/lib/python3.10/dist-packages
Requires: nvidia-cublas-cu11, nvidia-cuda-nvrtc-cu11, nvidia-cuda-runtime-cu11, nvidia-cudnn-cu11, typing-extensions
Required-by: fastai, ohmeow-blurr, sentence-transformers, torchvision

root@Ubuntu-2204-jammy-amd64-base ~/run/gpu # pip install fastai==2.7.13
Collecting fastai==2.7.13
  Downloading fastai-2.7.13-py3-none-any.whl (232 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 232.2/232.2 KB 8.0 MB/s eta 0:00:00
Requirement already satisfied: pyyaml in /usr/lib/python3/dist-packages (from fastai==2.7.13) (5.4.1)
Requirement already satisfied: pillow>=9.0.0 in /usr/local/lib/python3.10/dist-packages (from fastai==2.7.13) (10.2.0)
Requirement already satisfied: scipy in /usr/local/lib/python3.10/dist-packages (from fastai==2.7.13) (1.12.0)
Requirement already satisfied: matplotlib in /usr/local/lib/python3.10/dist-packages (from fastai==2.7.13) (3.8.3)

...... (removed all of the Requirement already satisfied: lines for brevity)

Installing collected packages: fastai
  Attempting uninstall: fastai
    Found existing installation: fastai 2.7.14
    Uninstalling fastai-2.7.14:
      Successfully uninstalled fastai-2.7.14
Successfully installed fastai-2.7.13
WARNING: Running pip as the 'root' user can result in broken permissions and conflicting behaviour with the system package manager. It is recommended to use a virtual environment instead: https://pip.pypa.io/warnings/venv

root@Ubuntu-2204-jammy-amd64-base ~/run/gpu # python3
Python 3.10.12 (main, Nov 20 2023, 15:14:05) [GCC 11.4.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from fastai.text.all import *
>>> sent = load_learner('model_3.pkl', cpu=False).to_fp16()
>>> sent.predict('hello')
((0.01348114013671875,), tensor([0.0135]), tensor([0.0135]))
>>> 

Expected behavior
It either does the prediction, or it 2.7.14 marks torch 2.2 as being required (presumably that'd also have fixed it, since 2.7.14 brought torch 2.2 support, but I did not test this).

Error with full stack trace

Place between these lines with triple backticks:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python3.10/dist-packages/fastai/learner.py", line 320, in predict
    dl = self.dls.test_dl([item], rm_type_tfms=rm_type_tfms, num_workers=0)
  File "/usr/local/lib/python3.10/dist-packages/fastai/data/core.py", line 526, in test_dl
    return self.valid.new(test_ds, **kwargs)
  File "/usr/local/lib/python3.10/dist-packages/fastai/text/data.py", line 218, in new
    return super().new(dataset=dataset, res=res, **kwargs)
  File "/usr/local/lib/python3.10/dist-packages/fastai/data/core.py", line 94, in new
    res = super().new(dataset, cls, do_setup=False, **kwargs)
  File "/usr/local/lib/python3.10/dist-packages/fastai/data/load.py", line 144, in new
    bs=self.bs, shuffle=self.shuffle, drop_last=self.drop_last, indexed=self.indexed, device=self.device)
  File "/usr/local/lib/python3.10/dist-packages/fastcore/basics.py", line 496, in __getattr__
    if attr is not None: return getattr(attr,k)
  File "/usr/local/lib/python3.10/dist-packages/fastai/data/core.py", line 450, in __getattr__
    def __getattr__(self,k): return gather_attrs(self, k, 'tls')
  File "/usr/local/lib/python3.10/dist-packages/fastcore/transform.py", line 173, in gather_attrs
    if not res: raise AttributeError(k)
AttributeError: device
@steinmn
Copy link

steinmn commented Mar 4, 2024

Same behaviour seen on my setup with torch 2.2. Could the issue be related to the model being loaded having originally been generated with older library versions?

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

No branches or pull requests

2 participants