wilson1yan / VideoGPT

MIT License
962 stars 115 forks source link

unknown error #35

Closed BoccheseGiacomo closed 1 year ago

BoccheseGiacomo commented 1 year ago

when i try to import the packages, i get this error:

ImportError: cannot import name 'get_num_classes' from 'torchmetrics.utilities.data' (/opt/conda/lib/python3.7/site-packages/torchmetrics/utilities/data.py)

i'm running the program on the kaggle laboratory. can anyone help me? thanks

wilson1yan commented 1 year ago

Is this from executing import videogpt or something similar? What versions are your packages (e.g. torch, pytorch-lightning, torchmetrics)? It might also help to paste the full error log you're getting

BoccheseGiacomo commented 1 year ago

during the execution of these two lines: !conda install --yes -c pytorch pytorch=1.7.1 torchvision cudatoolkit=11.0
!pip install git+https://github.com/wilson1yan/VideoGPT.git

i don't get any error but only the following warning: WARNING: Running pip as the 'root' user can result in broken permissions and conflicting behaviour with the system package manager. It is recommended to use a virtual environment instead: https://pip.pypa.io/warnings/venv class="ansi-yellow-fg">

then , i get the error executing the line: from videogpt import load_vqvae i get the error: ImportError Traceback (most recent call last) /tmp/ipykernel_17/323323888.py in 1 from torchvision.io import read_video ----> 2 from videogpt import load_vqvae 3 #from videogpt.data import preprocess

/opt/conda/lib/python3.7/site-packages/videogpt/init.py in 1 ----> 2 from .vqvae import VQVAE 3 from .gpt import VideoGPT 4 from .data import VideoData 5 from .download import load_vqvae, load_videogpt, load_i3d_pretrained, download

/opt/conda/lib/python3.7/site-packages/videogpt/vqvae.py in 3 import numpy as np 4 ----> 5 import pytorch_lightning as pl 6 import torch 7 import torch.nn as nn

/opt/conda/lib/python3.7/site-packages/pytorch_lightning/init.py in 18 _PROJECT_ROOT = os.path.dirname(_PACKAGE_ROOT) 19 ---> 20 from pytorch_lightning import metrics # noqa: E402 21 from pytorch_lightning.callbacks import Callback # noqa: E402 22 from pytorch_lightning.core import LightningDataModule, LightningModule # noqa: E402

/opt/conda/lib/python3.7/site-packages/pytorch_lightning/metrics/init.py in 13 # limitations under the License. 14 ---> 15 from pytorch_lightning.metrics.classification import ( # noqa: F401 16 Accuracy, 17 AUC,

/opt/conda/lib/python3.7/site-packages/pytorch_lightning/metrics/classification/init.py in 12 # See the License for the specific language governing permissions and 13 # limitations under the License. ---> 14 from pytorch_lightning.metrics.classification.accuracy import Accuracy # noqa: F401 15 from pytorch_lightning.metrics.classification.auc import AUC # noqa: F401 16 from pytorch_lightning.metrics.classification.auroc import AUROC # noqa: F401

/opt/conda/lib/python3.7/site-packages/pytorch_lightning/metrics/classification/accuracy.py in 16 from torchmetrics import Accuracy as _Accuracy 17 ---> 18 from pytorch_lightning.metrics.utils import deprecated_metrics 19 20

/opt/conda/lib/python3.7/site-packages/pytorch_lightning/metrics/utils.py in 20 from torchmetrics.utilities.data import dim_zero_mean as _dim_zero_mean 21 from torchmetrics.utilities.data import dim_zero_sum as _dim_zero_sum ---> 22 from torchmetrics.utilities.data import get_num_classes as _get_num_classes 23 from torchmetrics.utilities.data import select_topk as _select_topk 24 from torchmetrics.utilities.data import to_categorical as _to_categorical

ImportError: cannot import name 'get_num_classes' from 'torchmetrics.utilities.data' (/opt/conda/lib/python3.7/site-packages/torchmetrics/utilities/data.py)

hope this can help understanding the problem. now i check the versions

BoccheseGiacomo commented 1 year ago

torch==1.7.1+cu110 torchaudio==0.7.2 torchmetrics==0.9.3 torchtext==0.8.1 torchvision==0.8.2+cu110 pytorch-ignite==0.4.9 pytorch-lightning==1.3.3

jaxlib==0.3.15+cuda11.cudnn805

wilson1yan commented 1 year ago

Okay, it seems to work for me with torchmetrics==0.3.2. Perhaps try that version?

BoccheseGiacomo commented 1 year ago

now i've tried it, and i get other errors: in the download of the packages: *ERROR: pip's dependency resolver does not currently take into account all the packages that are installed. This behaviour is the source of the following dependency conflicts. pytorch-lightning 1.7.2 requires torch>=1.9., but you have torch 1.7.1+cu110 which is incompatible. fairscale 0.4.6 requires torch>=1.8.0, but you have torch 1.7.1+cu110 which is incompatible. allennlp 2.10.0 requires protobuf==3.20.0, but you have protobuf 3.19.4 which is incompatible. allennlp 2.10.0 requires torch<1.12.0,>=1.10.0, but you have torch 1.7.1+cu110 which is incompatible. Successfully installed torch-1.7.1+cu110 torchaudio-0.7.2 torchvision-0.8.2+cu110 WARNING: Running pip as the 'root' user can result in broken permissions and conflicting behaviour with t**

*ERROR: pip's dependency resolver does not currently take into account all the packages that are installed. This behaviour is the source of the following dependency conflicts. pytorch-lightning 1.7.2 requires torch>=1.9., but you have torch 1.7.1+cu110 which is incompatible. pytorch-lightning 1.7.2 requires torchmetrics>=0.7.0, but you have torchmetrics 0.3.2 which is incompatible.**

ERROR: pip's dependency resolver does not currently take into account all the packages that are installed. This behaviour is the source of the following dependency conflicts. dask-cudf 21.10.1 requires cupy-cuda114, which is not installed. pandas-profiling 3.1.0 requires markupsafe~=2.0.1, but you have markupsafe 2.1.1 which is incompatible. gcsfs 2022.5.0 requires fsspec==2022.5.0, but you have fsspec 2022.7.1 which is incompatible. flax 0.6.0 requires rich~=11.1, but you have rich 12.1.0 which is incompatible. dask-cudf 21.10.1 requires dask==2021.09.1, but you have dask 2022.2.0 which is incompatible. dask-cudf 21.10.1 requires distributed==2021.09.1, but you have distributed 2022.2.0 which is incompatible. allennlp 2.10.0 requires protobuf==3.20.0, but you have protobuf 3.19.4 which is incompatible. allennlp 2.10.0 requires torch<1.12.0,>=1.10.0, but you have torch 1.7.1+cu110 which is incompatible.

but it tried to install the packages and it managed to do it. Then , during the run of: from videogpt import load_vqvae i get the error: **ModuleNotFoundError Traceback (most recent call last) /tmp/ipykernel_18/323323888.py in 1 from torchvision.io import read_video ----> 2 from videogpt import load_vqvae 3 #from videogpt.data import preprocess

/opt/conda/lib/python3.7/site-packages/videogpt/init.py in 1 ----> 2 from .vqvae import VQVAE 3 from .gpt import VideoGPT 4 from .data import VideoData 5 from .download import load_vqvae, load_videogpt, load_i3d_pretrained, download

/opt/conda/lib/python3.7/site-packages/videogpt/vqvae.py in 3 import numpy as np 4 ----> 5 import pytorch_lightning as pl 6 import torch 7 import torch.nn as nn

/opt/conda/lib/python3.7/site-packages/pytorch_lightning/init.py in 19 20 from pytorch_lightning import metrics # noqa: E402 ---> 21 from pytorch_lightning.callbacks import Callback # noqa: E402 22 from pytorch_lightning.core import LightningDataModule, LightningModule # noqa: E402 23 from pytorch_lightning.trainer import Trainer # noqa: E402

/opt/conda/lib/python3.7/site-packages/pytorch_lightning/callbacks/init.py in 24 from pytorch_lightning.callbacks.pruning import ModelPruning 25 from pytorch_lightning.callbacks.quantization import QuantizationAwareTraining ---> 26 from pytorch_lightning.callbacks.stochastic_weight_avg import StochasticWeightAveraging 27 from pytorch_lightning.callbacks.timer import Timer 28

/opt/conda/lib/python3.7/site-packages/pytorch_lightning/callbacks/stochastic_weight_avg.py in 24 import pytorch_lightning as pl 25 from pytorch_lightning.callbacks.base import Callback ---> 26 from pytorch_lightning.trainer.optimizers import _get_default_scheduler_config 27 from pytorch_lightning.utilities import _TORCH_GREATER_EQUAL_1_6, rank_zero_info, rank_zero_warn 28 from pytorch_lightning.utilities.exceptions import MisconfigurationException

/opt/conda/lib/python3.7/site-packages/pytorch_lightning/trainer/init.py in 16 """ 17 ---> 18 from pytorch_lightning.trainer.trainer import Trainer 19 from pytorch_lightning.utilities.seed import seed_everything 20

/opt/conda/lib/python3.7/site-packages/pytorch_lightning/trainer/trainer.py in 23 from torch.utils.data import DataLoader 24 ---> 25 from pytorch_lightning.accelerators import Accelerator 26 from pytorch_lightning.callbacks import Callback 27 from pytorch_lightning.core.datamodule import LightningDataModule

/opt/conda/lib/python3.7/site-packages/pytorch_lightning/accelerators/init.py in 11 # See the License for the specific language governing permissions and 12 # limitations under the License. ---> 13 from pytorch_lightning.accelerators.accelerator import Accelerator # noqa F401 14 from pytorch_lightning.accelerators.cpu import CPUAccelerator # noqa F401 15 from pytorch_lightning.accelerators.gpu import GPUAccelerator # noqa F401

/opt/conda/lib/python3.7/site-packages/pytorch_lightning/accelerators/accelerator.py in 23 24 import pytorch_lightning as pl ---> 25 from pytorch_lightning.plugins.precision import ApexMixedPrecisionPlugin, NativeMixedPrecisionPlugin, PrecisionPlugin 26 from pytorch_lightning.plugins.training_type import TrainingTypePlugin 27 from pytorch_lightning.trainer.states import TrainerFn

/opt/conda/lib/python3.7/site-packages/pytorch_lightning/plugins/init.py in 1 from pytorch_lightning.plugins.base_plugin import Plugin # noqa: F401 ----> 2 from pytorch_lightning.plugins.plugins_registry import ( # noqa: F401 3 call_training_type_register_plugins, 4 TrainingTypePluginsRegistry, 5 )

/opt/conda/lib/python3.7/site-packages/pytorch_lightning/plugins/plugins_registry.py in 19 from typing import Any, Callable, Dict, List, Optional 20 ---> 21 from pytorch_lightning.plugins.training_type.training_type_plugin import TrainingTypePlugin 22 from pytorch_lightning.utilities.exceptions import MisconfigurationException 23

/opt/conda/lib/python3.7/site-packages/pytorch_lightning/plugins/training_type/init.py in 9 from pytorch_lightning.plugins.training_type.rpc_sequential import RPCSequentialPlugin # noqa: F401 10 from pytorch_lightning.plugins.training_type.sharded import DDPShardedPlugin # noqa: F401 ---> 11 from pytorch_lightning.plugins.training_type.sharded_spawn import DDPSpawnShardedPlugin # noqa: F401 12 from pytorch_lightning.plugins.training_type.single_device import SingleDevicePlugin # noqa: F401 13 from pytorch_lightning.plugins.training_type.single_tpu import SingleTPUPlugin # noqa: F401

/opt/conda/lib/python3.7/site-packages/pytorch_lightning/plugins/training_type/sharded_spawn.py in 18 19 from pytorch_lightning.core.lightning import LightningModule ---> 20 from pytorch_lightning.plugins.precision.sharded_native_amp import ShardedNativeMixedPrecisionPlugin 21 from pytorch_lightning.plugins.training_type.ddp_spawn import DDPSpawnPlugin 22 from pytorch_lightning.trainer.states import TrainerFn

/opt/conda/lib/python3.7/site-packages/pytorch_lightning/plugins/precision/init.py in 5 from pytorch_lightning.plugins.precision.native_amp import NativeMixedPrecisionPlugin # noqa: F401 6 from pytorch_lightning.plugins.precision.precision_plugin import PrecisionPlugin # noqa: F401 ----> 7 from pytorch_lightning.plugins.precision.sharded_native_amp import ShardedNativeMixedPrecisionPlugin # noqa: F401 8 from pytorch_lightning.plugins.precision.tpu_bfloat import TPUHalfPrecisionPlugin # noqa: F401

/opt/conda/lib/python3.7/site-packages/pytorch_lightning/plugins/precision/sharded_native_amp.py in 19 if _NATIVE_AMP_AVAILABLE and _FAIRSCALE_AVAILABLE: 20 from fairscale.optim import OSS ---> 21 from fairscale.optim.grad_scaler import ShardedGradScaler 22 23

/opt/conda/lib/python3.7/site-packages/fairscale/optim/grad_scaler.py in 12 import torch 13 from torch.cuda import FloatTensor # type: ignore ---> 14 from torch.cuda.amp.common import amp_definitely_not_available 15 from torch.cuda.amp.grad_scaler import GradScaler as TorchGradScaler 16 import torch.distributed as dist

ModuleNotFoundError: No module named 'torch.cuda.amp.common'**.

thank you.

BoccheseGiacomo commented 1 year ago

ok . running it in colab instead of kaggle with the specific verion of torchmetrics works for the import part and loading the model. now i get an assertion error in the part of "cropping the video": video = preprocess(video, resolution, sequence_length).unsqueeze(0).to(device)

AssertionError Traceback (most recent call last) in 6 vqvae = load_vqvae('kinetics_stride2x4x4') 7 video = read_video(video_filename, pts_unit='sec')[0] ----> 8 video = preprocess(video, resolution, sequence_length).unsqueeze(0).to(device) 9 10 #encodings = vqvae.encode(video)

/usr/local/lib/python3.7/dist-packages/videogpt/data.py in preprocess(video, resolution, sequence_length) 83 # temporal crop 84 if sequence_length is not None: ---> 85 assert sequence_length <= t 86 video = video[:sequence_length] 87

AssertionError:

i'm making steps ahead :)

BoccheseGiacomo commented 1 year ago

ok. now i was able to make it work. thank you really!

luccachiang commented 1 year ago

Okay, it seems to work for me with torchmetrics==0.3.2. Perhaps try that version?

Hi, I encountered the same problem when import pytorch_lightning and successfully solved it by 'pip install torchmetrics==0.3.2'. However, importing pytorch_lightning takes a long time, maybe about several minustes. Do you have some idea what is the problem?