Skip to content

Can't recreate a mamba environment with pixi (getting ModuleNotFoundError: No module named 'torch') #1880

Closed

Description

@asmith26

Checks

  • I have checked that this issue has not already been reported.

  • I have confirmed this bug exists on the latest version of pixi, using pixi --version.

Reproducible example

Create a pixi.toml (I'm essentially trying to create an env for florence2):

[project]
authors = ["me <[email protected]>"]
channels = ["nvidia", "conda-forge"]
description = "Add a short description here"
name = "florence2"
platforms = ["linux-64"]
version = "0.1.0"

[dependencies]
python = "*"
cuda-toolkit = "*"
cuda = "*"

[pypi-dependencies]
jupyterlab = "*"
transformers = "*"
datasets = "*"
matplotlib = "*"
torch = "*"
torchvision = "*"
requests = "*"
timm = "*"
flash-attn = "*"
einops = "*"
accelerate = "*"
pillow = "*"

Then running pixi install yields:

  ⠴ default:linux-64     [00:00:03] resolving flash-attn==2.6.3                                           × failed to solve the pypi requirements of 'default' 'linux-64'
  ├─▶ failed to resolve pypi dependencies
  ├─▶ Failed to download and build `flash-attn==2.6.3`
  ├─▶ Failed to build: `flash-attn==2.6.3`
  ╰─▶ Build backend failed to determine extra requires with `build_wheel()` with exit status: 1
      --- stdout:
      
      --- stderr:
      Traceback (most recent call last):
        File "<string>", line 14, in <module>
        File "~/pixi_cache/uv-cache/environments-v0/.tmp6AntAq/lib/python3.12/site-
      packages/setuptools/build_meta.py", line 332, in get_requires_for_build_wheel
          return self._get_build_requires(config_settings, requirements=[])
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
        File "~/pixi_cache/uv-cache/environments-v0/.tmp6AntAq/lib/python3.12/site-
      packages/setuptools/build_meta.py", line 302, in _get_build_requires
          self.run_setup()
        File "~/pixi_cache/uv-cache/environments-v0/.tmp6AntAq/lib/python3.12/site-
      packages/setuptools/build_meta.py", line 502, in run_setup
          super().run_setup(setup_script=setup_script)
        File "~/pixi_cache/uv-cache/environments-v0/.tmp6AntAq/lib/python3.12/site-
      packages/setuptools/build_meta.py", line 318, in run_setup
          exec(code, locals())
        File "<string>", line 21, in <module>
      ModuleNotFoundError: No module named 'torch'
      ---

Issue description

Possibly related to #1834

Expected behavior

I originally created the environment with mamba and it successfully installs/runs. Here is the exported environment.yaml

name: florence2
channels:
  - nvidia
  - conda-forge
dependencies:
  - _libgcc_mutex=0.1=conda_forge
  - _openmp_mutex=4.5=2_gnu
  - _sysroot_linux-64_curr_repodata_hack=3=h69a702a_16
  - binutils_impl_linux-64=2.40=ha1999f0_7
  - binutils_linux-64=2.40=hb3c18ed_0
  - bzip2=1.0.8=h4bc722e_7
  - ca-certificates=2024.7.4=hbcca054_0
  - cuda=12.6.0=0
  - cuda-cccl=12.6.37=0
  - cuda-cccl_linux-64=12.6.37=0
  - cuda-command-line-tools=12.6.0=0
  - cuda-compiler=12.6.0=0
  - cuda-crt-dev_linux-64=12.6.20=ha770c72_0
  - cuda-crt-tools=12.6.20=ha770c72_0
  - cuda-cudart=12.6.37=0
  - cuda-cudart-dev=12.6.37=0
  - cuda-cudart-dev_linux-64=12.6.37=0
  - cuda-cudart-static=12.6.37=0
  - cuda-cudart-static_linux-64=12.6.37=0
  - cuda-cudart_linux-64=12.6.37=0
  - cuda-cuobjdump=12.6.20=0
  - cuda-cupti=12.6.37=0
  - cuda-cupti-dev=12.6.37=0
  - cuda-cuxxfilt=12.6.20=0
  - cuda-driver-dev=12.6.37=0
  - cuda-driver-dev_linux-64=12.6.37=0
  - cuda-gdb=12.6.37=0
  - cuda-libraries=12.6.0=0
  - cuda-libraries-dev=12.6.0=0
  - cuda-nsight=12.6.20=0
  - cuda-nvcc=12.6.20=0
  - cuda-nvcc-dev_linux-64=12.6.20=he91c749_0
  - cuda-nvcc-impl=12.6.20=h85509e4_0
  - cuda-nvcc-tools=12.6.20=he02047a_0
  - cuda-nvcc_linux-64=12.6.20=0
  - cuda-nvdisasm=12.6.20=0
  - cuda-nvml-dev=12.6.37=2
  - cuda-nvprof=12.6.37=0
  - cuda-nvprune=12.6.20=0
  - cuda-nvrtc=12.6.20=0
  - cuda-nvrtc-dev=12.6.20=0
  - cuda-nvtx=12.6.37=0
  - cuda-nvvm-dev_linux-64=12.6.20=ha770c72_0
  - cuda-nvvm-impl=12.6.20=he02047a_0
  - cuda-nvvm-tools=12.6.20=he02047a_0
  - cuda-nvvp=12.6.37=0
  - cuda-opencl=12.6.37=0
  - cuda-opencl-dev=12.6.37=0
  - cuda-profiler-api=12.6.37=0
  - cuda-runtime=12.6.0=0
  - cuda-sanitizer-api=12.6.34=0
  - cuda-toolkit=12.6.0=0
  - cuda-tools=12.6.0=0
  - cuda-version=12.6=3
  - cuda-visual-tools=12.6.0=0
  - gcc_impl_linux-64=13.3.0=hfea6d02_0
  - gcc_linux-64=13.3.0=hc28eda2_0
  - gds-tools=1.11.0.15=0
  - gmp=6.3.0=hac33072_2
  - gxx_impl_linux-64=13.3.0=hdbfa832_0
  - gxx_linux-64=13.3.0=h6834431_0
  - kernel-headers_linux-64=3.10.0=h4a8ded7_16
  - ld_impl_linux-64=2.40=hf3520f5_7
  - libcublas=12.6.0.22=0
  - libcublas-dev=12.6.0.22=0
  - libcufft=11.2.6.28=0
  - libcufft-dev=11.2.6.28=0
  - libcufile=1.11.0.15=0
  - libcufile-dev=1.11.0.15=0
  - libcurand=10.3.7.37=0
  - libcurand-dev=10.3.7.37=0
  - libcusolver=11.6.4.38=0
  - libcusolver-dev=11.6.4.38=0
  - libcusparse=12.5.2.23=0
  - libcusparse-dev=12.5.2.23=0
  - libexpat=2.6.2=h59595ed_0
  - libffi=3.4.2=h7f98852_5
  - libgcc-devel_linux-64=13.3.0=h84ea5a7_100
  - libgcc-ng=14.1.0=h77fa898_0
  - libgomp=14.1.0=h77fa898_0
  - libnpp=12.3.1.23=0
  - libnpp-dev=12.3.1.23=0
  - libnsl=2.0.1=hd590300_0
  - libnvfatbin=12.6.20=0
  - libnvfatbin-dev=12.6.20=0
  - libnvjitlink=12.6.20=0
  - libnvjitlink-dev=12.6.20=0
  - libnvjpeg=12.3.3.23=0
  - libnvjpeg-dev=12.3.3.23=0
  - libsanitizer=13.3.0=heb74ff8_0
  - libsqlite=3.46.0=hde9e2c9_0
  - libstdcxx-devel_linux-64=13.3.0=h84ea5a7_100
  - libstdcxx-ng=14.1.0=hc0a3c3a_0
  - libuuid=2.38.1=h0b41bf4_0
  - libxcrypt=4.4.36=hd590300_1
  - libzlib=1.3.1=h4ab18f5_1
  - ncurses=6.5=h59595ed_0
  - nsight-compute=2024.1.1.4=0
  - openssl=3.3.1=h4bc722e_2
  - pip=24.2=pyhd8ed1ab_0
  - python=3.12.5=h2ad013b_0_cpython
  - readline=8.2=h8228510_1
  - setuptools=72.2.0=pyhd8ed1ab_0
  - sysroot_linux-64=2.17=h4a8ded7_16
  - tk=8.6.13=noxft_h4845f30_101
  - wheel=0.44.0=pyhd8ed1ab_0
  - xz=5.2.6=h166bdaf_0
  - pip:
      - accelerate==0.33.0
      - aiohappyeyeballs==2.4.0
      - aiohttp==3.10.5
      - aiosignal==1.3.1
      - attrs==24.2.0
      - certifi==2024.7.4
      - charset-normalizer==3.3.2
      - datasets==2.21.0
      - dill==0.3.8
      - einops==0.8.0
      - filelock==3.15.4
      - flash-attn==2.6.3
      - frozenlist==1.4.1
      - fsspec==2024.6.1
      - huggingface-hub==0.24.6
      - idna==3.7
      - jinja2==3.1.4
      - markupsafe==2.1.5
      - mpmath==1.3.0
      - multidict==6.0.5
      - multiprocess==0.70.16
      - networkx==3.3
      - numpy==1.26.4
      - nvidia-cublas-cu12==12.1.3.1
      - nvidia-cuda-cupti-cu12==12.1.105
      - nvidia-cuda-nvrtc-cu12==12.1.105
      - nvidia-cuda-runtime-cu12==12.1.105
      - nvidia-cudnn-cu12==9.1.0.70
      - nvidia-cufft-cu12==11.0.2.54
      - nvidia-curand-cu12==10.3.2.106
      - nvidia-cusolver-cu12==11.4.5.107
      - nvidia-cusparse-cu12==12.1.0.106
      - nvidia-nccl-cu12==2.20.5
      - nvidia-nvjitlink-cu12==12.6.20
      - nvidia-nvtx-cu12==12.1.105
      - packaging==24.1
      - pandas==2.2.2
      - pillow==10.4.0
      - psutil==6.0.0
      - pyarrow==17.0.0
      - python-dateutil==2.9.0.post0
      - pytz==2024.1
      - pyyaml==6.0.2
      - regex==2024.7.24
      - requests==2.32.3
      - safetensors==0.4.4
      - six==1.16.0
      - sympy==1.13.2
      - timm==1.0.8
      - tokenizers==0.19.1
      - torch==2.4.0
      - torchvision==0.19.0
      - tqdm==4.66.5
      - transformers==4.44.1
      - triton==3.0.0
      - typing-extensions==4.12.2
      - tzdata==2024.1
      - urllib3==2.2.2
      - xxhash==3.5.0
      - yarl==1.9.4

Activity

  1. added
    bug
    on Aug 21, 2024
  2. changed the title [-]Cant' recreate a mamba environment with pixi (getting `ModuleNotFoundError: No module named 'torch'`)[/-] [+]Can't recreate a mamba environment with pixi (getting `ModuleNotFoundError: No module named 'torch'`)[/+] on Aug 21, 2024
  3. tdejager commented on Aug 22, 2024

    @tdejager
    Contributor

    Yes this is related to this issue, that you mentioned :)

  4. tdejager commented on Aug 22, 2024

    @tdejager
    Contributor

    We are in the process of getting no-build-isolation in :)

  5. tdejager commented on Sep 3, 2024

    @tdejager
    Contributor

    Hey we've now added build-isolation options in main: https://pixi.sh/dev/reference/project_configuration/#no-build-isolation. Should be released really soon, let me know if it works and feel free to re-open if it does not.

  6. asmith26 commented on Sep 6, 2024

    @asmith26
    Author

    Hi @tdejager, thanks for the info and your help. It looks like this has been added (https://github.com/prefix-dev/pixi/releases/tag/v0.29.0), so I've updated my pixi version, removed my old env, and updated my pixi.toml file as follows:

    $ pixi self-update
    ✔ pixi is already up-to-date (version 0.29.0)
    
    $ rm -fr pixi.lock  .pixi/
    
    $ cat pixi.toml 
    [project]
    authors = ["me <[email protected]>"]
    channels = ["nvidia", "conda-forge"]
    description = "Add a short description here"
    name = "florence2"
    platforms = ["linux-64"]
    version = "0.1.0"
    
    [dependencies]
    python = "*"
    cuda-toolkit = "*"
    cuda = "*"
    setuptools = "*"   # Seemed to have to add this
    
    [pypi-options]
    no-build-isolation = ["torch", "flash-attn"]  # also tried just "torch" and just "flash-attn"
    
    [pypi-dependencies]
    jupyterlab = "*"
    transformers = "*"
    datasets = "*"
    matplotlib = "*"
    torch = "*"
    torchvision = "*"
    requests = "*"
    timm = "*"
    flash-attn = "*"
    einops = "*"
    accelerate = "*"
    pillow = "*"

    Unfortunately I seem to be getting:

    pixi install
      × default: error installing/updating PyPI dependencies
      ├─▶ Failed to prepare distributions
      ├─▶ Failed to fetch wheel: flash-attn==2.6.3
      ├─▶ Build backend failed to build wheel through `build_wheel()` with exit status: 1
      │   --- stdout:
      │   
      │   --- stderr:
      │   Traceback (most recent call last):
      │     File "<string>", line 11, in <module>
      │     File "~/gitRepos/florence2/.pixi/envs/default/lib/python3.12/site-packages/setuptools/build_meta.py",
      │   line 420, in build_wheel
      │       return self._build_with_temp_dir(
      │              ^^^^^^^^^^^^^^^^^^^^^^^^^^
      │     File "~/gitRepos/florence2/.pixi/envs/default/lib/python3.12/site-packages/setuptools/build_meta.py",
      │   line 402, in _build_with_temp_dir
      │       self.run_setup()
      │     File "~/gitRepos/florence2/.pixi/envs/default/lib/python3.12/site-packages/setuptools/build_meta.py",
      │   line 502, in run_setup
      │       super().run_setup(setup_script=setup_script)
      │     File "~/gitRepos/florence2/.pixi/envs/default/lib/python3.12/site-packages/setuptools/build_meta.py",
      │   line 318, in run_setup
      │       exec(code, locals())
      │     File "<string>", line 21, in <module>
      │   ModuleNotFoundError: No module named 'torch'
      │   ---
      ╰─▶ This error likely indicates that flash-attn==2.6.3 depends on torch, but doesn't declare it as
          a build dependency. If flash-attn==2.6.3 is a first-party package, consider adding torch to its
          `build-system.requires`. Otherwise, `uv pip install torch` into the environment and re-run with
          `--no-build-isolation`.

    Not sure if you can see anything obvious I'm missing? Thanks again!

  7. tdejager commented on Sep 6, 2024

    @tdejager
    Contributor

    Hi @asmith26 thanks for testing it out! So, I had to fiddle a bit because I'm on apple silicon and have a hard time reproducing anything cuda related. But I think this should work (minimal version):

    [project]
    authors = ["me <[email protected]>"]
    channels = ["conda-forge"]
    description = "Add a short description here"
    name = "florence2"
    platforms = ["linux-64"]
    version = "0.1.0"
    
    [dependencies]
    python = "*"
    setuptools = "*" 
    pytorch = "*" # need pytorch from conda which maps to torch on pypi
    cuda-toolkit = "*"
    cuda = "*"
    
    [pypi-options]
    no-build-isolation = ["flash-attn"]  # also tried just "torch" and just "flash-attn"
    
    [pypi-dependencies]
    flash-attn = "*"

    The important thing is to use pytorch from conda, the conda prefix (installation directory) is created before installing the pypi dependencies and essentially supplies the torch version for the PyPI build.

    edit:
    According to @baszalmstra we can even forego the nvidia channel, lets give that a try:

  8. tdejager commented on Sep 6, 2024

    @tdejager
    Contributor

    I'm re-opening until we consider this working.

  9. asmith26 commented on Sep 6, 2024

    @asmith26
    Author

    Many thanks for all your help/time @tdejager! I've got it working, and for completeness here are various combinations (checked all are using cuda with pixi run python -c "import torch; print(torch.cuda.is_available())":

    # pixi.toml - conda
    
    [project]
    name = "florence2"
    authors = ["me <[email protected]>"]
    description = "Add a short description here"
    channels = ["pytorch", "nvidia", "conda-forge"]
    platforms = ["linux-64"]
    version = "0.1.0"
    
    [dependencies]
    python = ">=3.11"
    pytorch = "*"
    torchvision = "*"
    pytorch-cuda = "*"
    cuda-toolkit = "*"
    
    [pypi-options]
    no-build-isolation = ["flash-attn"]
    
    [pypi-dependencies]
    flash-attn = "*"
    # pixi.toml - pypi
    
    [project]
    name = "florence2"
    authors = ["me <[email protected]>"]
    description = "Add a short description here"
    channels = ["conda-forge"]
    platforms = ["linux-64"]
    version = "0.1.0"
    
    [dependencies]
    python = ">=3.12"
    cuda-toolkit = "*"
    
    [pypi-options]
    extra-index-urls = ["https://download.pytorch.org/whl/cu124"]
    no-build-isolation = ["flash-attn"]
    
    [pypi-dependencies]
    torch = "*"
    torchvision = "*"
    flash-attn = "*"
    # pyproject.toml - conda
    
    [project]
    authors = [{name = "name", email = "[email protected]"}]
    dependencies = []
    description = "Add a short description here"
    name = "florence2"
    requires-python = ">= 3.11"
    version = "0.1.0"
    
    [tool.pixi]
    project = {channels = ["pytorch", "nvidia", "conda-forge"], platforms = ["linux-64"]}
    dependencies = {python = ">=3.11", pytorch = "*", torchvision = "*", pytorch-cuda = "*", cuda-toolkit = "*"}
    pypi-options = {no-build-isolation = ["flash-attn"]}
    pypi-dependencies = {florence2 = {path=".", editable=true}, flash-attn = "*"}
    # pyproject.toml - pypi
    
    [project]
    authors = [{name = "name", email = "[email protected]"}]
    dependencies = []
    description = "Add a short description here"
    name = "florence2"
    requires-python = ">= 3.12"
    version = "0.1.0"
    
    [tool.pixi]
    project = {channels = ["conda-forge"], platforms = ["linux-64"]}
    dependencies = {python = ">=3.12"}
    pypi-options = {extra-index-urls = ["https://download.pytorch.org/whl/cu124"], no-build-isolation = ["flash-attn"]}
    pypi-dependencies = {florence2 = {path=".", editable=true}, torch = "*",  torchvision = "*", flash-attn = "*"}

    Thanks again!

  10. asmith26 commented on Sep 6, 2024

    @asmith26
    Author

    I have noticed one thing: if I spin up a fresh cloud VM, when running pixi install with the above pypi examples I hit the above ModuleNotFoundError: No module named 'torch'.

    However, if I remove the flash-attn = "*" and run pixi install, the environment installs successfully - if I then re-add the flash-attn = "*" and run pixi install, I get my desired environment with torch and flash-attn.

    Also interestingly, if I then (on the same/already running VM), copy my latest pyproject.toml (with the flash-attn dependency) to another new folder and run pixi install, it works successfully (without having to got through the process above of remove flash-attn -> pixi install -> readd flash-attn - > pixi install).

    This feels like a bug? I can write a clearer step-by-step reproduction of this if helpful?

  11. tdejager commented on Sep 7, 2024

    @tdejager
    Contributor

    That's interesting! Does this also happen if you run a 'pixi clean' and pixi cache clean' and 'rm pixi.lock' to reproduce locally as well?

  12. asmith26 commented on Sep 7, 2024

    @asmith26
    Author

    Hi @tdejager, can confirm that on a machine where I have the following pyproject.toml working successfully:

    [project]
    authors = [{name = "name", email = "[email protected]"}]
    dependencies = []
    description = "Add a short description here"
    name = "florence2"
    requires-python = ">= 3.12"
    version = "0.1.0"
    
    [tool.pixi]
    project = {channels = ["conda-forge"], platforms = ["linux-64"]}
    system-requirements = {cuda = "12.1", linux = "4.4.0"}
    dependencies = {python = ">=3.12", setuptools = "*"}
    pypi-options = {extra-index-urls = ["https://download.pytorch.org/whl/cu121"], no-build-isolation = ["flash-attn"]}
    pypi-dependencies = {florence2 = {path=".", editable=true}, torch = "*",  torchvision = "*", flash-attn = "*"}

    If I then run the following, I get ModuleNotFoundError: No module named 'torch':

    $ pixi clean
    $ pixi clean cache
    $ rm pixi.lock
    
    $ pixi install  # errors with  `ModuleNotFoundError: No module named 'torch'`
  13. tdejager commented on Sep 8, 2024

    @tdejager
    Contributor

    Hey @asmith26 that example has torch as a pypi-dependency again :) So it will not work for the same reasons as before.

  14. asmith26 commented on Sep 8, 2024

    @asmith26
    Author

    Cool, I'll proceed with with the conda version, although it does seem strange that the pypi version works if I first install torch, and then later install flash-attn.

    Many thanks again for all your help @tdejager! :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugpypi

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions