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

Error importing xformers after building from source #641

Closed
brucethemoose opened this issue Jan 12, 2023 · 8 comments
Closed

Error importing xformers after building from source #641

brucethemoose opened this issue Jan 12, 2023 · 8 comments
Labels
bug Something isn't working

Comments

@brucethemoose
Copy link

brucethemoose commented Jan 12, 2023

🐛 Bug

After building xformers from source with this command: pip install -v -U git+https://github.com/facebookresearch/xformers.git@main#egg=xformers

It installs and builds successfully, but errors out when trying to import on Pytorch 1.13.1:

❯ python
Python 3.10.9 (main, Dec 24 2022, 22:19:02) [GCC 12.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import xformers
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/alpha/.local/lib/python3.10/site-packages/xformers/__init__.py", line 10, in <module>
    from . import _cpp_lib
  File "/home/alpha/.local/lib/python3.10/site-packages/xformers/_cpp_lib.py", line 127, in <module>
    _build_metadata = _register_extensions()
  File "/home/alpha/.local/lib/python3.10/site-packages/xformers/_cpp_lib.py", line 114, in _register_extensions
    with open(cpp_lib_json, "r") as fp:
FileNotFoundError: [Errno 2] No such file or directory: '/home/alpha/.local/lib/python3.10/site-packages/xformers/cpp_lib.json'
>>> import torch
>>> print (torch.__version__)
1.13.1
>>>

And (after being built again) Pytorch 2.0:

Python 3.10.9 (main, Dec 24 2022, 22:19:02) [GCC 12.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import xformers
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/alpha/.local/lib/python3.10/site-packages/xformers/__init__.py", line 10, in <module>
    from . import _cpp_lib
  File "/home/alpha/.local/lib/python3.10/site-packages/xformers/_cpp_lib.py", line 127, in <module>
    _build_metadata = _register_extensions()
  File "/home/alpha/.local/lib/python3.10/site-packages/xformers/_cpp_lib.py", line 114, in _register_extensions
    with open(cpp_lib_json, "r") as fp:
FileNotFoundError: [Errno 2] No such file or directory: '/home/alpha/.local/lib/python3.10/site-packages/xformers/cpp_lib.json'
>>> import torch
>>> print(torch.__version__)
2.0.0.dev20230112+cu118

I tried building for Pytorch 1.13.1 installed via the Arch Linux repos and Pytorch 2.0 cu118 from pip.

Builds as recently as... 2 days ago, I think, seem to work fine. I suppose I will try rolling a few commits back.

           .-------------------------:                    alpha@Asus-GA401IV
          .+=========================.                    ------------------
         :++===++==================-       :++-           OS: CachyOS Linux x86_64
        :*++====+++++=============-        .==:           Host: ROG Zephyrus G14 GA401IV_GA401IV (1.0)
       -*+++=====+***++==========:                        Kernel: 6.1.4-1-cachyos-lto
      =*++++========------------:                         Uptime: 1 hour, 24 mins
     =*+++++=====-                     ...                Packages: 1250 (pacman)
   .+*+++++=-===:                    .=+++=:              Shell: fish 3.5.1
  :++++=====-==:                     -*****+              Resolution: 3840x2160 @ 60Hz
 :++========-=.                      .=+**+.              DE: KDE Plasma 5.26.5
.+==========-.                          .                 WM: KWin (Wayland)
 :+++++++====-                                .--==-.     WM Theme: Breeze
  :++==========.                             :+++++++:    Theme: Lightly (CachyOSNord) [QT], cachyos-nor]
   .-===========.                            =*****+*+    Icons: breeze-dark [QT], breeze-dark [GTK2/3/4]
    .-===========:                           .+*****+:    Font: Noto Sans (10pt) [QT], Noto Sans (10pt) ]
      -=======++++:::::::::::::::::::::::::-:  .---:      Cursor: capitaine (24px)
       :======++++====+++******************=.             Terminal: alacritty
        :=====+++==========++++++++++++++*-               Terminal Font: monospace (12pt)
         .====++==============++++++++++*-                CPU: AMD Ryzen 9 4900HS (16) @ 3 GHz
          .===+==================+++++++:                 GPU: AMD Renoir
           .-=======================+++:                  GPU: NVIDIA GeForce RTX 2060 Max-Q
             ..........................                   Memory: 11.51 GiB / 15.05 GiB (76%)
                                                          Disk (/): 110 GiB / 139 GiB (79%)
                                                          Disk (/home/alpha/Storage): 301 GiB / 344 GiB )
                                                          Disk (/run/media/alpha/External): 140 GiB / 93]
                                                          Disk (/windows): 296 GiB / 434 GiB (68%) [Remo]
                                                          Battery: 100% [Not charging]
                                                          Locale: en_US.UTF-8

Additional context

Note that I can't use precompiled xformers wheels from pip install --pre xformers on my platform. Not sure if this is because I am using CUDA 11.8, or because they are not matched to my version(s) of PyTorch. Maybe y'all should make a stable "main" and a "dev" branch for those of us who have to build xformers from source?

@brucethemoose
Copy link
Author

OK so looking through what the wheel installed:

    /home/alpha/.local/lib/python3.10/site-packages/xformers-0.0.16+2166360.d20230112.dist-info/*
    /home/alpha/.local/lib/python3.10/site-packages/xformers/*
    /home/alpha/.local/xformers/cpp_lib.json

It seems that cpp_lib.json ended up in the wrong place?

@brucethemoose
Copy link
Author

brucethemoose commented Jan 12, 2023

Yeah, a simple copy to the right directory seems to have fixed it:

❯ cp /home/alpha/.local/xformers/cpp_lib.json /home/alpha/.local/lib/python3.10/site-packages/xformers/cpp_lib.json

~/clone/sd-scripts main
❯ python
Python 3.10.9 (main, Dec 24 2022, 22:19:02) [GCC 12.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import xformers
>>> import xformers.ops

🤷

@danthe3rd
Copy link
Contributor

Thansk a lot for the debugging & workaround! Indeed this seems to be the case for a few users - we want to push a fix tomorrow.

@danthe3rd danthe3rd added the bug Something isn't working label Jan 12, 2023
@danthe3rd danthe3rd pinned this issue Jan 12, 2023
@arpowers
Copy link

stuck on this, just curious if there is a way to install a version of xformers that's not the main dev branch? Its not clear from readme.

@danthe3rd
Copy link
Contributor

You can also git clone manually (make sure to include --recursive flag to git clone), then checkout the commit you want, and pip install . from inside the directory.
Alternatively, you might want to use pip wheels ("pip install --pre -U xformers") - requires pytorch==1.13.1

@danthe3rd danthe3rd mentioned this issue Jan 13, 2023
7 tasks
@bonlime
Copy link

bonlime commented Jan 13, 2023

Had the same issue, rolling back to 0.0.15 solved it

@danthe3rd
Copy link
Contributor

Should be fixed now after 6a988dd
We'll need to wait ~1h or so to have updated builds in conda/pip as well

@danthe3rd
Copy link
Contributor

pip wheels with the fix are now available - closing

@danthe3rd danthe3rd unpinned this issue Jan 13, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants