facebookresearch / pytorch3d

PyTorch3D is FAIR's library of reusable components for deep learning with 3D data
https://pytorch3d.org/
Other
8.7k stars 1.3k forks source link

Could not build wheels for pytorch3d #1767

Closed sanjyot21 closed 6 months ago

sanjyot21 commented 6 months ago

🐛 Bugs / Unexpected behaviors

I was executing the installation of PyTorch3D code in google colab when I encountered the following error facing from 2-3 days while running on T4 GPU.

  1. Installtion Code provided by PyTorch3D community:
    import os
    import sys
    import torch
    need_pytorch3d=False
    try:
    import pytorch3d
    except ModuleNotFoundError:
    need_pytorch3d=True
    if need_pytorch3d:
    if torch.__version__.startswith("2.1.") and sys.platform.startswith("linux"):
        # We try to install PyTorch3D via a released wheel.
        pyt_version_str=torch.__version__.split("+")[0].replace(".", "")
        version_str="".join([
            f"py3{sys.version_info.minor}_cu",
            torch.version.cuda.replace(".",""),
            f"_pyt{pyt_version_str}"
        ])
        !pip install fvcore iopath
        !pip install --no-index --no-cache-dir pytorch3d -f https://dl.fbaipublicfiles.com/pytorch3d/packaging/wheels/{version_str}/download.html
    else:
        # We try to install PyTorch3D from source.
        !pip install 'git+https://github.com/facebookresearch/pytorch3d.git@stable'
  2. Code ran for like more than 17 minutes and then ended up giving this error below:

    Collecting git+https://github.com/facebookresearch/pytorch3d.git@stable
    Cloning https://github.com/facebookresearch/pytorch3d.git (to revision stable) to /tmp/pip-req-build-6t7m7yqt
    Running command git clone --filter=blob:none --quiet https://github.com/facebookresearch/pytorch3d.git /tmp/pip-req-build-6t7m7yqt
    Running command git checkout -q 2f11ddc5ee7d6bd56f2fb6744a16776fab6536f7
    Resolved https://github.com/facebookresearch/pytorch3d.git to commit 2f11ddc5ee7d6bd56f2fb6744a16776fab6536f7
    Preparing metadata (setup.py) ... done
    Collecting fvcore (from pytorch3d==0.7.5)
    Downloading fvcore-0.1.5.post20221221.tar.gz (50 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 50.2/50.2 kB 2.0 MB/s eta 0:00:00
    Preparing metadata (setup.py) ... done
    Collecting iopath (from pytorch3d==0.7.5)
    Downloading iopath-0.1.10.tar.gz (42 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 42.2/42.2 kB 6.3 MB/s eta 0:00:00
    Preparing metadata (setup.py) ... done
    Requirement already satisfied: numpy in /usr/local/lib/python3.10/dist-packages (from fvcore->pytorch3d==0.7.5) (1.25.2)
    Collecting yacs>=0.1.6 (from fvcore->pytorch3d==0.7.5)
    Downloading yacs-0.1.8-py3-none-any.whl (14 kB)
    Requirement already satisfied: pyyaml>=5.1 in /usr/local/lib/python3.10/dist-packages (from fvcore->pytorch3d==0.7.5) (6.0.1)
    Requirement already satisfied: tqdm in /usr/local/lib/python3.10/dist-packages (from fvcore->pytorch3d==0.7.5) (4.66.2)
    Requirement already satisfied: termcolor>=1.1 in /usr/local/lib/python3.10/dist-packages (from fvcore->pytorch3d==0.7.5) (2.4.0)
    Requirement already satisfied: Pillow in /usr/local/lib/python3.10/dist-packages (from fvcore->pytorch3d==0.7.5) (9.4.0)
    Requirement already satisfied: tabulate in /usr/local/lib/python3.10/dist-packages (from fvcore->pytorch3d==0.7.5) (0.9.0)
    Requirement already satisfied: typing_extensions in /usr/local/lib/python3.10/dist-packages (from iopath->pytorch3d==0.7.5) (4.10.0)
    Collecting portalocker (from iopath->pytorch3d==0.7.5)
    Downloading portalocker-2.8.2-py3-none-any.whl (17 kB)
    Building wheels for collected packages: pytorch3d, fvcore, iopath
    error: subprocess-exited-with-error
    
    × python setup.py bdist_wheel did not run successfully.
    │ exit code: 1
    ╰─> See above for output.
    
    note: This error originates from a subprocess, and is likely not a problem with pip.
    Building wheel for pytorch3d (setup.py) ... error
    ERROR: Failed building wheel for pytorch3d
    Running setup.py clean for pytorch3d
    Building wheel for fvcore (setup.py) ... done
    Created wheel for fvcore: filename=fvcore-0.1.5.post20221221-py3-none-any.whl size=61400 sha256=0649c908b480024424dbc5aa50634befc95b5a683f1a058a3dbc52bf5bab3095
    Stored in directory: /root/.cache/pip/wheels/01/c0/af/77c1cf53a1be9e42a52b48e5af2169d40ec2e89f7362489dd0
    Building wheel for iopath (setup.py) ... done
    Created wheel for iopath: filename=iopath-0.1.10-py3-none-any.whl size=31532 sha256=0b2f8cc28e3418c0478df00e4768d3015952be63cc94aeb51c20175b858bb773
    Stored in directory: /root/.cache/pip/wheels/9a/a3/b6/ac0fcd1b4ed5cfeb3db92e6a0e476cfd48ed0df92b91080c1d
    Successfully built fvcore iopath
    Failed to build pytorch3d
    ERROR: Could not build wheels for pytorch3d, which is required to install pyproject.toml-based projects

I want solution to overcome this error by running the code on T4 GPU Processor in Google Colab. Also, I would like to mention that while i ran the same code on CPU in Google Colab it ran for like 29 minutes but ended up successful execution. But during the same session if ran the object renderring code, it take estimation time to run code as 14 hours for 2000 iterations.

bottler commented 6 months ago

The code is building from source because it doesn't see the expected PyTorch. Colab has just updated from PyTorch 2.1. to Pytorch 2.2.1, and that code only looks for a built wheel if torch.__version__.startswith("2.1.").

If you change the "2.1." to "2.2." in that line it will install a built wheel and so the whole cell should evaluate quickly.

In this repo, I have just moved the stable tag to the latest version v0.7.6 which has the "2.2.", so anyone going to the tutorials from the buttons on pytorch3d.org will not have the same problem any more. (stable is meant to be the latest release. I delayed moving it for 0.7.6 because I saw colab had been slow to update.)

We plan to change the notebook code so that they don't need to be updated in this way, hopefully soon.

sanjyot21 commented 6 months ago

I would like to thank you for the provided solution and ask you for the updation of code on tutorial page. :)

bottler commented 6 months ago

Thanks, updated.