aehrc / cvt2distilgpt2

Improving Chest X-Ray Report Generation by Leveraging Warm-Starting
GNU General Public License v3.0
62 stars 5 forks source link

'type' object is not subscriptable #2

Open jainnipun11 opened 2 years ago

jainnipun11 commented 2 years ago

After I ran "!python3 main.py --task mimic_cxr_jpg_chen". I got the following error:

warnings.warn(f"Workstation configuration for {socket.gethostname()} does not exist. Using default "

TypeError: 'type' object is not subscriptable

Please guide me through this. Thank you.

anicolson commented 2 years ago

Hi @jainnipun11,

I think I have found the cause of the issue. The return typing hints on this line are incompatible with python 3.7 (but work fine with python 3.9): https://github.com/aehrc/cvt2distilgpt2/blob/13d450ac3509e0d671f2aed701d57d01e2d73618/transmodal/network/cvt.py#L77

e.g., if we have tmp.py:

from typing import Optional, Union, Any

def forward(images) -> Union[dict[str, float], dict[str, Union[float, Any]]]:
        return None

The following error occurs with python 3.7, but not with python 3.9

compute-i1 ~$ module load python/3.7.11
Loading python/3.7.11
  Unloading conflict: python/3.9.4
compute-i1 ~$ python3 tmp.py
Traceback (most recent call last):
  File "tmp.py", line 4, in <module>
    def forward(images) -> Union[dict[str, float], dict[str, Union[float, Any]]]:
TypeError: 'type' object is not subscriptable
compute-i1 ~$ module load python/3.9.4
Loading python/3.9.4
  Unloading conflict: python/3.7.11
compute-i1 ~$ python3 tmp.py
compute-i1 ~$

So, I have removed the return typing hints for that function: https://github.com/aehrc/cvt2distilgpt2/blob/77656703a67b03c4ea415fbaab4766c1218c479e/transmodal/network/cvt.py#L77

If you can check if this worked, that would be great and please let me know of any further issues after this.

Thanks, Aaron.

jainnipun11 commented 2 years ago

Hey Aaron, I modified according to you and now I got this error:

/content/drive/MyDrive/cvt2distilgpt2/transmodal/utils.py:39: UserWarning: Workstation configuration for 5f6e9f0cc0f3 does not exist. Using default configuration: num_workers=5, total_gpus=1, total_memory=16 warnings.warn(f"Workstation configuration for {socket.gethostname()} does not exist. Using default "

TypeError: expected str, bytes or os.PathLike object, not NoneType

Thanks.

anicolson commented 2 years ago

Hi @jainnipun11,

Can you confirm that you have downloaded the files for distilgpt2 from https://huggingface.co/distilgpt2/tree/main and have placed them in https://github.com/aehrc/cvt2distilgpt2/tree/main/checkpoints/distilgpt2?

I have made some updates to check for path issues. Can you please pull the latest version and test?

And if problems persist, can you please try python 3.8 or 3.9??

Hope this helps, Aaron.

jainnipun11 commented 2 years ago

Hey Aaron,

I followed all your path instructions and I have stored the 4 files inside the recommended folder. Now, I updated the python version to python 3.9.1, and this is the result:

/content/drive/MyDrive/cvt2distilgpt2/transmodal/utils.py:39: UserWarning: Workstation configuration for ad62cbeafeaa does not exist. Using default configuration: num_workers=5, total_gpus=1, total_memory=16 warnings.warn(f"Workstation configuration for {socket.gethostname()} does not exist. Using default "

TypeError: expected str, bytes or os.PathLike object, not NoneType

anicolson commented 2 years ago

Hi @jainnipun11,

It seems that you did not pull the latest version of the repo.

In your error, AutoTokenizer is on line 87

File "/content/drive/MyDrive/cvt2distilgpt2/transmodal/config.py", line 87, in get_config
config["tokenizer"] = AutoTokenizer.from_pretrained(

Whereas, in the latest repo, it is on line 93: https://github.com/aehrc/cvt2distilgpt2/blob/618bdba5de308d9cb2059c75158464b7ec5b408f/transmodal/config.py#L93

Please pull the latest repo and we can go from there.

Aaron.

jainnipun11 commented 2 years ago

Hey Aaron. This time around I am encountering a different error altogether. I am using Python 3.9. Installed all the requirements using this.

Traceback (most recent call last): File "/content/drive/MyDrive/cvt2distilgpt2/main.py", line 9, in from transmodal.ext.collect_env_details import main as collect_env_details File "/content/drive/MyDrive/cvt2distilgpt2/transmodal/ext/collect_env_details.py", line 30, in import pytorch_lightning # noqa: E402 File "/usr/local/lib/python3.9/site-packages/pytorch_lightning/init.py", line 20, in from pytorch_lightning.callbacks import Callback # noqa: E402 File "/usr/local/lib/python3.9/site-packages/pytorch_lightning/callbacks/init.py", line 14, in from pytorch_lightning.callbacks.base import Callback File "/usr/local/lib/python3.9/site-packages/pytorch_lightning/callbacks/base.py", line 26, in from pytorch_lightning.utilities.types import STEP_OUTPUT File "/usr/local/lib/python3.9/site-packages/pytorch_lightning/utilities/types.py", line 25, in from torchmetrics import Metric File "/usr/local/lib/python3.9/site-packages/torchmetrics/init.py", line 14, in from torchmetrics import functional # noqa: E402 File "/usr/local/lib/python3.9/site-packages/torchmetrics/functional/init.py", line 14, in from torchmetrics.functional.audio.pit import permutation_invariant_training, pit, pit_permutate File "/usr/local/lib/python3.9/site-packages/torchmetrics/functional/audio/init.py", line 14, in from torchmetrics.functional.audio.pit import permutation_invariant_training, pit, pit_permutate # noqa: F401 File "/usr/local/lib/python3.9/site-packages/torchmetrics/functional/audio/pit.py", line 24, in from torchmetrics.utilities.imports import _SCIPY_AVAILABLE File "/usr/local/lib/python3.9/site-packages/torchmetrics/utilities/imports.py", line 92, in _TRANSFORMERS_AUTO_AVAILABLE = _module_available("transformers.models.auto") File "/usr/local/lib/python3.9/site-packages/torchmetrics/utilities/imports.py", line 36, in _module_available return find_spec(module_path) is not None File "/usr/local/lib/python3.9/importlib/util.py", line 114, in find_spec raise ValueError('{}.spec is None'.format(name))

ValueError: transformers.models.auto.spec is None

anicolson commented 2 years ago

Hi @jainnipun11,

Try this: https://github.com/huggingface/transformers/issues/15212

jainnipun11 commented 2 years ago

Hey Aaron! I referred the repository you suggested, it resolved the issue I was encountering earlier, but again the return type error occured.

/content/drive/MyDrive/cvt2distilgpt2/transmodal/utils.py:39: UserWarning: Workstation configuration for b563c33267e1 does not exist. Using default configuration: num_workers=5, total_gpus=1, total_memory=16 warnings.warn(f"Workstation configuration for {socket.gethostname()} does not exist. Using default "

Thank you. Nipun

anicolson commented 2 years ago

Hi Nipun,

I will look into this tomorrow, but in the meantime could you please try this GPT2 example in the same environment and let me know if it works? https://huggingface.co/docs/transformers/model_doc/gpt2#transformers.GPT2LMHeadModel.forward.example

Thanks for your patience, Aaron.