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

Can't install PyTorch3D with Github actions #1810

Closed andrewharp closed 3 months ago

andrewharp commented 3 months ago

🐛 Bugs / Unexpected behaviors

I can install pytorch3d locally (in a fresh pip env (edit: provided by conda, important later)) if I do this:

pip install torch==2.2.0
pip install git+https://github.com/facebookresearch/pytorch3d.git@f34104cf6ebefacd7b7e07955ee7aaa823e616ac

However the same operations fail when run in the context of a Github action:

        File "/tmp/pip-build-env-1a4p2xfk/overlay/lib/python3.10/site-packages/setuptools/build_meta.py", line 311, in run_setup
          exec(code, locals())
        File "<string>", line 15, in <module>
      ModuleNotFoundError: No module named 'torch'

Instructions To Reproduce the Issue:

Put the following in .github/workflows as a .yaml file (and change the branch name if necessary):

name: Test Pytorch3d

on:
  push:
    branches: [ dev ]
    tags:
      - 'v*'

jobs:
  publish:
    runs-on: ubuntu-latest

    steps:
    - uses: actions/checkout@v2

    - name: Set up Python
      uses: actions/setup-python@v2
      with:
        python-version: '3.10'

    - name: Install pytorch3d
      run: |
        pip install torch==2.2.0
        pip install git+https://github.com/facebookresearch/pytorch3d.git@f34104cf6ebefacd7b7e07955ee7aaa823e616ac

Links: Failing action .yaml Failed run

Even though I install torch first, and then pytorch3d, pytorch3d's setup can't find torch. It doesn't matter if I install them in the same command either.

This seems related to #1673 and #1419 which prevents PyTorch3D from being installed under Poetry due to the installer expecting torch to be present but no mention of the dependency being found in the package info.

Every other combination that I've tried including Pytorch3d fails; I'm not sure how to work around this short of forking pytorch3d and inserting a dependency on torch to keep pip from getting confused.

andrewharp commented 3 months ago

I see that this comment says that you can use a prebuilt whl with explicit torch and pytorch3d versions, however I haven't yet been able to find an index of them.

INSTALL.md only mentions prebuilt binaries for PyTorch 1.11.0; is this information current or do additional builds for later PyTorch and Python versions exist?

andrewharp commented 3 months ago

I've also tried Conda, but it doesn't look like the PyTorch3D Conda package supports PyTorch 2.2.0.

workflow Failed run

edit: The Conda build works if I bump the PyTorch version down to 2.1.2 and Python up to 3.11, so this could be a partial workaround that would let me test some aspects of my build. Though a working pip install would still be ideal as I think I chose those versions for a reason (will have to check).

andrewharp commented 3 months ago

I tried combining conda+pip and managed to get it to work with my desired Python+PyTorch versions. I was using Conda on my local machine but not on GitHub initially (just used the default python env), so this could start to explain the difference in behavior.

If anybody else runs into similar problems, try something like this:

name: Test Pytorch3d with Conda

on:
  push:
    branches: [ dev ]
    tags:
      - 'v*'

jobs:
  publish:
    runs-on: ubuntu-latest

    defaults:
      run:
        shell: bash -l {0}

    steps:
    - uses: actions/checkout@v2

    - name: Set up Miniconda
      uses: conda-incubator/setup-miniconda@v2
      with:
        auto-update-conda: true
        python-version: '3.10'
        activate-environment: myenv
        auto-activate-base: false

    - name: Install dependencies
      run: |
        pip install torch==2.2.0
        pip install git+https://github.com/facebookresearch/pytorch3d.git@stable

    - name: Check versions
      run: |
        python -c "import pytorch3d; print(pytorch3d.__version__)"

Still not sure if the difference in behavior is expected, so will leave this open.

bottler commented 3 months ago

The latest PyTorch3D does not have builds for PyTorch 2.2 (except the special pip package). PyTorch 2.2 is newer than the latest release of PyTorch3D I think. This is likely to be fixed sometime with a new release of PyTorch3D. You can build from source if you want. There's nothing new to track here.

andrewharp commented 3 months ago

It still fails with pip on github actions using Python 3.11, PyTorch 2.1.2, and PyTorch3D 0.7.6: Failed run yaml

This is the combination that installs successfully with Conda on github actions, so I believe this behavior might be unexpected.

bottler commented 3 months ago

I'm not sure why the torch import is failing. It may be that pip install from git in Python 3.11 has new behaviour which wants packages to be PEP-517 compliant, which would not work for pytorch3d, or it may be that something strange happened with the torch install. You could try inserting a python -c "import torch" before the failing line.

Razbolt commented 2 months ago

Hey, I have a similar problem and created a new issue in #1831. Apparently, I am not the only one they have a problem with, but I didn't understand from this conversation which version of the torch I should have. When I list everything, I see that the torch is 2.2.0 and that I could not install the PyTorch3D. @bottler

Thank you