Cannot import fastai2 in jupyter notebook using poetry

Hi there,

I am pretty much new to using machine learning libraries and fastai in particular. I have been following the free online course and wanted to create my first project following some of the steps given in the book. I am currently using poetry´s latest version (1.3.2) and python 3.9.6, and since I was having some problems finding a way to neatly add pytorch, decided just to simply use poetry add fastai2 -D, as to also use the latest version of fastai.

After letting poetry solve the dependencies on its own I also added jupyter the same way: poetry add jupyter -D, and afterwards, activated the shell, launched jupyter and created a new project. Finally I tried importing fastai2 similarly as how it is imported in the class:

from fastai2.vision.widgets import *

but then I am getting the following error:

RuntimeError: tensor.H is only supported on matrices (2-D tensors). Got 1-D tensor.

I tried looking in the forums and stackoverflow about this problem but there does not seem to be any solution to it. I did check this this forum entry which seemingly points towards a possible compatibility issue between fastai2 and torch v1.16 and v1.13 (my version happens to be v1.13.1, see bellow for my whole depency list, although as stated before, I simply let poetry solve them). I am not sure this answer might work out and it does not really work for me as I also could not find a clean way of installing a desired version of pytorch, reason for which I simply installed fastai2 and let poetry install whichever version of pytorch it considered necessary.

Also regarding this solution, I am not even sure forcing poetry to install a higher version as the one it installed by default might be a good idea, as I guess it did not download the latest version but the one it did for a reason (not sure, just assuming, I really am a beginner at all this, sorry). Should I just on purpose downgrade to fastai instead of using fastai2? Does not seem to be a smart decision as I would guess the latest version must have more functionalities and error fixes (?)

Thank you so much for your help, really hope someone can help me out as fast as possible. I will add the full error-log and my dependency list below as to not make the post too long.

The whole error-log:

---------------------------------------------------------------------------
RuntimeError                              Traceback (most recent call last)
Cell In[3], line 1
----> 1 from fastai2.vision.widgets import *

File ~\anti-counterfeiting\.venv\lib\site-packages\fastai2\vision\widgets.py:7
      3 __all__ = ['HBox', 'VBox', 'widgets', 'Button', 'Checkbox', 'Dropdown', 'Layout', 'Box', 'Output', 'Label',
      4            'FileUpload', 'widget', 'carousel', 'ImagesCleaner', 'ImageClassifierCleaner']
      6 # Cell
----> 7 from ..torch_basics import *
      8 from ..data.all import *
      9 from .core import *

File ~\anti-counterfeiting\.venv\lib\site-packages\fastai2\torch_basics.py:4
      2 from .imports import *
      3 from .torch_imports import *
----> 4 from .torch_core import *
      5 from .layers import *

File ~\anti-counterfeiting\.venv\lib\site-packages\fastai2\torch_core.py:312
    309         if isinstance(f, (MethodWrapperType, BuiltinFunctionType, BuiltinMethodType, MethodType, FunctionType)):
    310             setattr(TensorBase, fn, get_f(fn))
--> 312 _patch_tb()
    314 # Cell
    315 class TensorCategory(TensorBase): pass

File ~\anti-counterfeiting\.venv\lib\site-packages\fastai2\torch_core.py:308, in _patch_tb()
    306 for fn in dir(t):
    307     if fn in skips: continue
--> 308     f = getattr(t, fn)
    309     if isinstance(f, (MethodWrapperType, BuiltinFunctionType, BuiltinMethodType, MethodType, FunctionType)):
    310         setattr(TensorBase, fn, get_f(fn))

RuntimeError: tensor.H is only supported on matrices (2-D tensors). Got 1-D tensor.

Well, first, you need to use fastai, not fastai2. so pip install fastai -U. There could be many fixes in fastai that weren’t in fastai2, considering it was the beta for the new fastai version and hasn’t been updated in 2.5 years

2 Likes

List of packages:

anyio                    3.6.2     High level compatibility layer for multi...
argon2-cffi              21.3.0    The secure Argon2 password hashing algor...
argon2-cffi-bindings     21.2.0    Low-level CFFI bindings for Argon2
arrow                    1.2.3     Better dates & times for Python
asttokens                2.2.1     Annotate AST trees with source code posi...
attrs                    22.2.0    Classes Without Boilerplate
backcall                 0.2.0     Specifications for callback functions pa...
beautifulsoup4           4.11.2    Screen-scraping library
bleach                   6.0.0     An easy safelist-based HTML-sanitizing t...
blis                     0.7.9     The Blis BLAS-like linear algebra librar...
catalogue                2.0.8     Super lightweight function registries fo...
certifi                  2022.12.7 Python package for providing Mozilla's C...
cffi                     1.15.1    Foreign Function Interface for Python ca...
charset-normalizer       3.1.0     The Real First Universal Charset Detecto...
click                    8.1.3     Composable command line interface toolkit
colorama                 0.4.6     Cross-platform colored terminal text.
comm                     0.1.2     Jupyter Python Comm implementation, for ...
confection               0.0.4     The sweetest config system for Python
contourpy                1.0.7     Python library for calculating contours ...
cycler                   0.11.0    Composable style cycles
cymem                    2.0.7     Manage calls to calloc/free through Cython
debugpy                  1.6.6     An implementation of the Debug Adapter P...
decorator                5.1.1     Decorators for Humans
defusedxml               0.7.1     XML bomb protection for Python stdlib mo...
executing                1.2.0     Get the currently executing AST node of ...
fastai2                  0.0.30    Version 2 of the fastai library
fastcore                 1.5.28    Python supercharged for fastai development
fastjsonschema           2.16.3    Fastest Python implementation of JSON sc...
fastprogress             1.0.3     A nested progress with plotting options ...
fonttools                4.39.0    Tools to manipulate font files
fqdn                     1.5.1     Validates fully-qualified domain names a...
idna                     3.4       Internationalized Domain Names in Applic...
importlib-metadata       6.0.0     Read metadata from Python packages
importlib-resources      5.12.0    Read resources from Python packages
ipykernel                6.21.3    IPython Kernel for Jupyter
ipython                  8.11.0    IPython: Productive Interactive Computing
ipython-genutils         0.2.0     Vestigial utilities from IPython
ipywidgets               8.0.4     Jupyter interactive widgets
isoduration              20.11.0   Operations with ISO 8601 durations
jedi                     0.18.2    An autocompletion tool for Python that c...
jinja2                   3.1.2     A very fast and expressive template engine.
joblib                   1.2.0     Lightweight pipelining with Python funct...
jsonpointer              2.3       Identify specific nodes in a JSON docume...
jsonschema               4.17.3    An implementation of JSON Schema validat...
jupyter                  1.0.0     Jupyter metapackage. Install all the Jup...
jupyter-client           8.0.3     Jupyter protocol implementation and clie...
jupyter-console          6.6.3     Jupyter terminal console
jupyter-core             5.2.0     Jupyter core package. A base package on ...
jupyter-events           0.6.3     Jupyter Event System library
jupyter-server           2.4.0     The backendùi.e. core services, APIs, an...
jupyter-server-terminals 0.4.4     A Jupyter Server Extension Providing Ter...
jupyterlab-pygments      0.2.2     Pygments theme using JupyterLab CSS vari...
jupyterlab-widgets       3.0.5     Jupyter interactive widgets for JupyterLab
kiwisolver               1.4.4     A fast implementation of the Cassowary c...
langcodes                3.3.0     Tools for labeling human languages with ...
markupsafe               2.1.2     Safely add untrusted strings to HTML/XML...
matplotlib               3.7.1     Python plotting package
matplotlib-inline        0.1.6     Inline Matplotlib backend for Jupyter
mistune                  2.0.5     A sane Markdown parser with useful plugi...
murmurhash               1.0.9     Cython bindings for MurmurHash
nbclassic                0.5.3     Jupyter Notebook as a Jupyter Server ext...
nbclient                 0.7.2     A client library for executing notebooks...
nbconvert                7.2.9     Converting Jupyter Notebooks
nbformat                 5.7.3     The Jupyter Notebook format
nest-asyncio             1.5.6     Patch asyncio to allow nested event loops
notebook                 6.5.3     A web-based notebook environment for int...
notebook-shim            0.2.2     A shim layer for notebook traits and config
numpy                    1.24.2    Fundamental package for array computing ...
packaging                23.0      Core utilities for Python packages
pandas                   1.5.3     Powerful data structures for data analys...
pandocfilters            1.5.0     Utilities for writing pandoc filters in ...
parso                    0.8.3     A Python Parser
pathy                    0.10.1    pathlib.Path subclasses for local and cl...
pickleshare              0.7.5     Tiny 'shelve'-like database with concurr...
pillow                   9.4.0     Python Imaging Library (Fork)
pip                      23.0.1    The PyPA recommended tool for installing...
platformdirs             3.1.0     A small Python package for determining a...
preshed                  3.0.8     Cython hash table that trusts the keys a...
prometheus-client        0.16.0    Python client for the Prometheus monitor...
prompt-toolkit           3.0.38    Library for building powerful interactiv...
psutil                   5.9.4     Cross-platform lib for process and syste...
pure-eval                0.2.2     Safely evaluate AST nodes without side e...
pycparser                2.21      C parser in Python
pydantic                 1.10.6    Data validation and settings management ...
pygments                 2.14.0    Pygments is a syntax highlighting packag...
pyparsing                3.0.9     pyparsing module - Classes and methods t...
pyrsistent               0.19.3    Persistent/Functional/Immutable data str...
python-dateutil          2.8.2     Extensions to the standard Python dateti...
python-json-logger       2.0.7     A python library adding a json log forma...
pytz                     2022.7.1  World timezone definitions, modern and h...
pywin32                  305       Python for Window Extensions
pywinpty                 2.0.10    Pseudo terminal support for Windows from...
pyyaml                   6.0       YAML parser and emitter for Python
pyzmq                    25.0.0    Python bindings for 0MQ
qtconsole                5.4.0     Jupyter Qt console
qtpy                     2.3.0     Provides an abstraction layer on top of ...
requests                 2.28.2    Python HTTP for Humans.
rfc3339-validator        0.1.4     A pure python RFC3339 validator
rfc3986-validator        0.1.1     Pure python rfc3986 validator
scikit-learn             1.2.2     A set of python modules for machine lear...
scipy                    1.9.3     Fundamental algorithms for scientific co...
send2trash               1.8.0     Send file to trash natively under Mac OS...
setuptools               67.6.0    Easily download, build, install, upgrade...
six                      1.16.0    Python 2 and 3 compatibility utilities
smart-open               6.3.0     Utils for streaming large files (S3, HDF...
sniffio                  1.3.0     Sniff out which async library your code ...
soupsieve                2.4       A modern CSS selector implementation for...
spacy                    3.5.1     Industrial-strength Natural Language Pro...
spacy-legacy             3.0.12    Legacy registered functions for spaCy ba...
spacy-loggers            1.0.4     Logging utilities for SpaCy
srsly                    2.4.6     Modern high-performance serialization ut...
stack-data               0.6.2     Extract data from python stack frames an...
terminado                0.17.1    Tornado websocket backend for the Xterm....
thinc                    8.1.9     A refreshing functional take on deep lea...
threadpoolctl            3.1.0     threadpoolctl
tinycss2                 1.2.1     A tiny CSS parser
torch                    1.13.1    Tensors and Dynamic neural networks in P...
torchvision              0.14.1    image and video datasets and models for ...
tornado                  6.2       Tornado is a Python web framework and as...
tqdm                     4.65.0    Fast, Extensible Progress Meter
traitlets                5.9.0     Traitlets Python configuration system
typer                    0.7.0     Typer, build great CLIs. Easy to code. B...
typing-extensions        4.5.0     Backported and Experimental Type Hints f...
uri-template             1.2.0     RFC 6570 URI Template Processor
urllib3                  1.26.14   HTTP library with thread-safe connection...
wasabi                   1.1.1     A lightweight console printing and forma...
wcwidth                  0.2.6     Measures the displayed width of unicode ...
webcolors                1.12      A library for working with color names a...
webencodings             0.5.1     Character encoding aliases for legacy we...
websocket-client         1.5.1     WebSocket client for Python with low lev...
widgetsnbextension       4.0.5     Jupyter interactive widgets for Jupyter ...
zipp                     3.15.0    Backport of pathlib-compatible object wr...

Hi Zachary,

Thank you very much for your fast response. So if I am not misunderstanding what you are telling me, fastai is actually the lastest version between fastai and fastai2?

Thank you again so much in advance :slight_smile:

Yes. TBH I am not a fan that fastai2 still exists on Pypi, as this is a very common confusion with users

1 Like

Indeed, very misleading. Thank you again so much, I am reinstalling everything again now and hopefully will have no installation/importing issues.