yezhengSTAT / scVI-3D

GNU General Public License v3.0
5 stars 2 forks source link

torch>=1.8.0 and 'type' object is not subscriptable #12

Open mdozmorov opened 1 month ago

mdozmorov commented 1 month ago

Hi Ye,

hamy12398, my student, and I are trying to make scVI-3D working. We are encountering the same issue on different computers.

First, installation has torch version incompatibility. We got this error:

conda create -n schic-scvi-3d python=3.8
conda activate schic-scvi-3d
conda install scvi-tools -c conda-forge
pip install -r python-requirements.txt
...
    The user requested torch==1.4.0
    scvi-tools 0.14.5 depends on torch>=1.8.0

To fix this you could try to:
1. loosen the range of package versions you've specified
2. remove package versions to allow pip attempt to solve the dependency conflict
ERROR: ResolutionImpossible: for help visit https://pip.pypa.io/en/latest/topics/dependency-resolution/#dealing-with-dependency-conflicts

It is fixed by changing torch>=1.8.0 in python-requirements.txt. Everything installs without errors. But running the actual demo command gives an error. I'm not sure what to do here, could you, please, help?

python scripts/scVI-3D.py -b 10 -c "whole" -r 1000000 -i "demoData" -o "results" -cs "supplementaryData/demoData_summary.txt" -g "supplementaryData/hg19.chrom.sizes" -br -n 100 -gpu -p 10 -pca 50 -up -tp -v
...
scVI-3D.py 22 <module>
import scvi

__init__.py 10 <module>
from . import autotune, data, model, external, utils

__init__.py 1 <module>
from ._manager import TuneAnalysis, TunerManager

_manager.py 22 <module>
from scvi.model.base import BaseModelClass

__init__.py 2 <module>
from ._amortizedlda import AmortizedLDA

_amortizedlda.py 14 <module>
from scvi.module import AmortizedLDAPyroModule

__init__.py 1 <module>
from ._amortizedlda import AmortizedLDAPyroModule

_amortizedlda.py 14 <module>
from scvi.module.base import PyroBaseModuleClass, auto_move_data

__init__.py 1 <module>
from ._base_module import (

_base_module.py 15 <module>
from flax.training import train_state

train_state.py 19 <module>
import optax

__init__.py 17 <module>
from optax import contrib

__init__.py 21 <module>
from optax.contrib.dadapt_adamw import dadapt_adamw

dadapt_adamw.py 45 <module>
betas: tuple[float, float] = (0.9, 0.999),

TypeError:
'type' object is not subscriptable
yezhengSTAT commented 1 month ago

Prof. Dozmorov,

Sincerely apologize for the troubles using scVI-3D and my very late reply due to a series of deadlines!!

Indeed, a lot of dependency packages have been updated dramatically and a lot of functions are depreciated. Upon a few attempts, I found updating scVI-3D to accommodate all the changes is not easily fixed. For a temporary solution, I found the following conda environment seems to work but I haven't tested it on all the data. I also found there is another user who recently successfully ran the demo data and hopefully, I can also learn his practice.

Please do let me know how it goes and I will also keep you posted when the updated version is released.

Thanks, Ye

name: schic-scvi-3d-202405
channels:
  - conda-forge
  - defaults
  - bioconda
  - anaconda
dependencies:
  - python==3.8
  - scvi-tools==0.14.5
  - scanpy>=1.7.1
  - anndata>=0.7.5
  - matplotlib==3.6.0
  - pytorch-lightning==1.3
  - pytorch==1.8.0
  - torchmetrics==0.6.0
Accompany0313 commented 1 month ago

You can also try adjusting the version of scikit-learn to 0.24.2 to see if that works

hamy12398 commented 1 month ago

I have tried the new environment schic-scvi-3d-202405.yml in order below

micromamba create -f scVI-3D_environment.yml

pip install numpy==1.20.3
pip install scanpy==1.4.6
pip install pandas==1.2.4
pip install anndata==0.7.5
pip install scvi-tools==0.14.5
pip install joblib==1.1.0
pip install matplotlib==3.1.1
pip install umap==0.3.10

pip install --upgrade scanpy
pip install --upgrade "matplotlib>=3.4"
pip install scikit-learn==0.24.2

I gave me the result of 'cell_info_summary_sorted.txt' but no other files. I also receive some error:

/Users/mynguyen/micromamba/envs/schic-scvi-3d-202405/lib/python3.8/site-packages/setuptools_scm/_integration/setuptools.py:31: RuntimeWarning: ERROR: setuptools==59.5.0 is used in combination with setuptools_scm>=8.x

Your build configuration is incomplete and previously worked by accident! setuptools_scm requires setuptools>=61

Suggested workaround if applicable:

I also tried to fix the error of'setuptools_scm', then I got this error: Global seed set to 0 Traceback (most recent call last): File "scripts/scVI-3D.py", line 22, in import scvi File "/Users/mynguyen/micromamba/envs/schic-scvi-3d-202405/lib/python3.8/site-packages/scvi/init.py", line 10, in from . import data, model, external, utils File "/Users/mynguyen/micromamba/envs/schic-scvi-3d-202405/lib/python3.8/site-packages/scvi/model/init.py", line 1, in from ._amortizedlda import AmortizedLDA File "/Users/mynguyen/micromamba/envs/schic-scvi-3d-202405/lib/python3.8/site-packages/scvi/model/_amortizedlda.py", line 7, in import pyro File "/Users/mynguyen/micromamba/envs/schic-scvi-3d-202405/lib/python3.8/site-packages/pyro/init.py", line 4, in import pyro.poutine as poutine File "/Users/mynguyen/micromamba/envs/schic-scvi-3d-202405/lib/python3.8/site-packages/pyro/poutine/init.py", line 4, in from .handlers import ( File "/Users/mynguyen/micromamba/envs/schic-scvi-3d-202405/lib/python3.8/site-packages/pyro/poutine/handlers.py", line 60, in from .collapse_messenger import CollapseMessenger File "/Users/mynguyen/micromamba/envs/schic-scvi-3d-202405/lib/python3.8/site-packages/pyro/poutine/collapse_messenger.py", line 7, in from pyro.distributions.distribution import COERCIONS File "/Users/mynguyen/micromamba/envs/schic-scvi-3d-202405/lib/python3.8/site-packages/pyro/distributions/init.py", line 4, in import pyro.distributions.torch_patch # noqa F403 File "/Users/mynguyen/micromamba/envs/schic-scvi-3d-202405/lib/python3.8/site-packages/pyro/distributions/torch_patch.py", line 10, in assert torch.version.startswith("1.") AssertionError

I also tried to install scikit-learn 0.24.2 as suggestion above. I got this error:

Traceback (most recent call last): File "scripts/scVI-3D.py", line 22, in import scvi File "/Users/mynguyen/micromamba/envs/schic-scvi-3d-202405/lib/python3.8/site-packages/scvi/init.py", line 10, in from . import data, model, external, utils File "/Users/mynguyen/micromamba/envs/schic-scvi-3d-202405/lib/python3.8/site-packages/scvi/model/init.py", line 1, in from ._amortizedlda import AmortizedLDA File "/Users/mynguyen/micromamba/envs/schic-scvi-3d-202405/lib/python3.8/site-packages/scvi/model/_amortizedlda.py", line 7, in import pyro File "/Users/mynguyen/micromamba/envs/schic-scvi-3d-202405/lib/python3.8/site-packages/pyro/init.py", line 4, in import pyro.poutine as poutine File "/Users/mynguyen/micromamba/envs/schic-scvi-3d-202405/lib/python3.8/site-packages/pyro/poutine/init.py", line 4, in from .handlers import ( File "/Users/mynguyen/micromamba/envs/schic-scvi-3d-202405/lib/python3.8/site-packages/pyro/poutine/handlers.py", line 60, in from .collapse_messenger import CollapseMessenger File "/Users/mynguyen/micromamba/envs/schic-scvi-3d-202405/lib/python3.8/site-packages/pyro/poutine/collapse_messenger.py", line 7, in from pyro.distributions.distribution import COERCIONS File "/Users/mynguyen/micromamba/envs/schic-scvi-3d-202405/lib/python3.8/site-packages/pyro/distributions/init.py", line 4, in import pyro.distributions.torch_patch # noqa F403 File "/Users/mynguyen/micromamba/envs/schic-scvi-3d-202405/lib/python3.8/site-packages/pyro/distributions/torch_patch.py", line 10, in assert torch.version.startswith("1.") AssertionError

I am not too sure what I should do next. Could you help me to have a look? I appreciate your assistance.

mdozmorov commented 1 month ago

@hamy12398, pull the latest changes. The installation works, thank you all for helping.

conda env create -f scVI-3D_conda_environment.yml -y
conda activate schic-scvi-3d

But running the demo results in another error. I checked conda-installed python is used. It may be a separate issue or should be directed to the scanpy authors, but is there an easy fix?

python scripts/scVI-3D.py -b 10 -c "whole" -r 1000000 -i "demoData" -o "results" -cs "supplementaryData/demoData_summary.txt" -g "supplementaryData/hg19.chrom.sizes" -br -n 100 -gpu -p 10 -pca 50 -up -tp -v
Traceback (most recent call last):
  File "scripts/scVI-3D.py", line 18, in <module>
    import scanpy as sc
  File "/opt/miniconda3/envs/schic-scvi-3d/lib/python3.8/site-packages/scanpy/__init__.py", line 45, in <module>
    from . import datasets, experimental, external, get, logging, metrics, queries
  File "/opt/miniconda3/envs/schic-scvi-3d/lib/python3.8/site-packages/scanpy/datasets/__init__.py", line 5, in <module>
    from ._datasets import (
  File "/opt/miniconda3/envs/schic-scvi-3d/lib/python3.8/site-packages/scanpy/datasets/_datasets.py", line 15, in <module>
    from ..readwrite import read, read_visium
  File "/opt/miniconda3/envs/schic-scvi-3d/lib/python3.8/site-packages/scanpy/readwrite.py", line 1015
    ) as t,
      ^
SyntaxError: invalid syntax
yezhengSTAT commented 1 month ago

Sorry for the continuing trouble. I guess I should fix the Scanpy and anndata versions as well.

- scanpy==1.9.8
- anndata==0.7.5

(On my side, scanpy installed version is 1.7.1 but more recent successful practice from another user used scanpy==1.9.8: https://github.com/yezhengSTAT/scVI-3D/issues/11#issuecomment-2106708518)

Please let me know if it still does not work.

mdozmorov commented 1 month ago

We really try to make it work, but I'm running out of ideas. First, conda env create -f scVI-3D_conda_environment.yml -y never finishes, I waited maybe 3-4 days. micromamba env create -f scVI-3D_conda_environment.yml -y installs the environment on a GPU node, but running the example gives (after some progress):

Traceback (most recent call last):
  File "scripts/scVI-3D.py", line 743, in <module>
    res = Parallel(n_jobs=coreN,backend='multiprocessing')(delayed(normalize)(bandM, cellInfo, chromSelect, bandDist, nLatent, batchFlag, gpuFlag) for bandM, chromSelect, bandDist in bandMiter)
  File "/lustre/home/mdozmorov/micromamba/envs/schic-scvi-3d/lib/python3.8/site-packages/joblib/parallel.py", line 2007, in __call__
    return output if self.return_generator else list(output)
  File "/lustre/home/mdozmorov/micromamba/envs/schic-scvi-3d/lib/python3.8/site-packages/joblib/parallel.py", line 1650, in _get_outputs
    yield from self._retrieve()
  File "/lustre/home/mdozmorov/micromamba/envs/schic-scvi-3d/lib/python3.8/site-packages/joblib/parallel.py", line 1754, in _retrieve
    self._raise_error_fast()
  File "/lustre/home/mdozmorov/micromamba/envs/schic-scvi-3d/lib/python3.8/site-packages/joblib/parallel.py", line 1789, in _raise_error_fast
    error_job.get_result(self.timeout)
  File "/lustre/home/mdozmorov/micromamba/envs/schic-scvi-3d/lib/python3.8/site-packages/joblib/parallel.py", line 745, in get_result
    return self._return_or_raise()
  File "/lustre/home/mdozmorov/micromamba/envs/schic-scvi-3d/lib/python3.8/site-packages/joblib/parallel.py", line 763, in _return_or_raise
    raise self._result
AssertionError: Torch not compiled with CUDA enabled

Removing the -gpu option proceeds a bit further but gives another error:

UMAP visualization.
Traceback (most recent call last):
  File "scripts/scVI-3D.py", line 813, in <module>
    cbar.set_ticklabels(list(colorDict.keys()))
  File "/lustre/home/mdozmorov/micromamba/envs/schic-scvi-3d/lib/python3.8/site-packages/matplotlib/_api/deprecation.py", line 384, in wrapper
    return func(*inner_args, **inner_kwargs)
  File "/lustre/home/mdozmorov/micromamba/envs/schic-scvi-3d/lib/python3.8/site-packages/matplotlib/colorbar.py", line 928, in set_ticklabels
    self._long_axis().set_ticklabels(ticklabels, minor=minor, **kwargs)
  File "/lustre/home/mdozmorov/micromamba/envs/schic-scvi-3d/lib/python3.8/site-packages/matplotlib/axis.py", line 1890, in set_ticklabels
    raise ValueError(
ValueError: The number of FixedLocator locations (6), usually from a call to set_ticks, does not match the number of ticklabels (4).

Anything else we can try?

yezhengSTAT commented 1 month ago

So sorry to hear that the installation is still not successful. Let me try on AWS tomorrow in case our institution's server is not generalizable.

Meanwhile, if your analysis target is to normalize scHi-C data for application study, I would recommend first running BandNorm (https://github.com/sshen82/BandNorm), which is usually faster and does a very decent job of removing noise and has a nice cell-type separation.

Otherwise, another user (https://github.com/yezhengSTAT/scVI-3D/issues/11#issuecomment-2106708518) who is successful in running scVI-3D also kindly shared the conda environment in use. Maybe that also worth trying.

Apologize for the trouble, again.

Ye

yezhengSTAT commented 1 month ago

Prof. Dozmorov,

Sorry for the delay. I tried on a clean environment on AWS Ubuntu of 2 cpu and 8Gb RAM, which can run the demo data successfully using CPU parallel running. Attached are the server parameters (lscpu) and the job running log.

lscpu.txt scVI-3D_cpu_version.txt

Let me get back to you regarding the GPU setting.

Thanks, Ye

mdozmorov commented 1 month ago

Thank you, Ye. I actually managed to install the environment as described in (https://github.com/yezhengSTAT/scVI-3D/issues/11#issuecomment-2106708518) and the demo command is still running. Probably stuck at Terminating: fork() called from a process already using GNU OpenMP, this is unsafe.. We'll try on AWS.

yezhengSTAT commented 1 month ago

I just realized the two txt files I attached yesterday contain many messy symbols due to file format transformation. I have cleaned them up for easy reading.

For the GPU usage, indeed, it is quite tricky as the software is built using relatively old pytorch modules. I requested the following machine on AWS, which comes with a PyTorch conda environment of version 1.10:

Deep Learning AMI GPU PyTorch 1.10.0 (Ubuntu 18.04) 20220927

The following script contains how I installed the other packages. The key is to use pip install --no-deps to install scvi, pytorch-lighting and torchmetrics so that they won't upgrade each other's version.

scVI-3D_GPU.txt

Here is the full running log. scVI-3D_GPU_log.txt