Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

'type' object is not subscriptable #2

Open
jainnipun11 opened this issue Jul 28, 2022 · 9 comments
Open

'type' object is not subscriptable #2

jainnipun11 opened this issue Jul 28, 2022 · 9 comments

Comments

@jainnipun11
Copy link

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 "

  • CUDA:
    • GPU:
      • A100-SXM4-40GB
    • available: True
    • version: 11.3
  • Packages:
    • numpy: 1.21.6
    • pyTorch_debug: False
    • pyTorch_version: 1.12.0+cu113
    • pytorch-lightning: 1.5.10
    • tqdm: 4.64.0
  • System:
    • OS: Linux
    • architecture:
      • 64bit
    • processor: x86_64
    • python: 3.7.13
    • version: CE Metrics #1 SMP Sun Apr 24 10:03:06 PDT 2022
      Traceback (most recent call last):
      File "main.py", line 214, in
      main(clargs)
      File "main.py", line 58, in main
      config = get_config(clargs)
      File "/content/drive/MyDrive/cvt2distilgpt2/transmodal/config.py", line 54, in get_config
      config = load_config(clargs)
      File "/content/drive/MyDrive/cvt2distilgpt2/transmodal/config.py", line 26, in load_config
      config = getattr(importlib.import_module(module), "config")()
      File "/usr/lib/python3.7/importlib/init.py", line 127, in import_module
      return _bootstrap._gcd_import(name[level:], package, level)
      File "", line 1006, in _gcd_import
      File "", line 983, in _find_and_load
      File "", line 967, in _find_and_load_unlocked
      File "", line 677, in _load_unlocked
      File "", line 728, in exec_module
      File "", line 219, in _call_with_frames_removed
      File "/content/drive/MyDrive/cvt2distilgpt2/task/mimic_cxr_jpg_chen/config/cvt_21_to_distilgpt2_scst.py", line 1, in
      from config.cvt_21_to_distilgpt2_chexbert import config as external_config
      File "/content/drive/MyDrive/cvt2distilgpt2/config/cvt_21_to_distilgpt2_chexbert.py", line 1, in
      from config.cvt_21_to_distilgpt2 import config as external_config
      File "/content/drive/MyDrive/cvt2distilgpt2/config/cvt_21_to_distilgpt2.py", line 1, in
      from transmodal.network.cvt import spatial_position_feature_size
      File "/content/drive/MyDrive/cvt2distilgpt2/transmodal/network/cvt.py", line 27, in
      class CvT(Module):
      File "/content/drive/MyDrive/cvt2distilgpt2/transmodal/network/cvt.py", line 77, in CvT
      def forward(self, images: torch.FloatTensor) -> Union[dict[str, Tensor], dict[str, Union[Tensor, Any]]]:

TypeError: 'type' object is not subscriptable

Please guide me through this. Thank you.

@anicolson
Copy link
Member

anicolson commented Jul 29, 2022

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):

def forward(self, images: torch.FloatTensor) -> Union[dict[str, Tensor], dict[str, Union[Tensor, Any]]]:

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:

def forward(self, images: torch.FloatTensor):

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
Copy link
Author

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 "

  • CUDA:
    • GPU:
      • Tesla V100-SXM2-16GB
    • available: True
    • version: 11.3
  • Packages:
    • numpy: 1.21.6
    • pyTorch_debug: False
    • pyTorch_version: 1.12.0+cu113
    • pytorch-lightning: 1.5.10
    • tqdm: 4.64.0
  • System:
    • OS: Linux
    • architecture:
      • 64bit
    • processor: x86_64
    • python: 3.7.13
    • version: CE Metrics #1 SMP Sun Apr 24 10:03:06 PDT 2022
      Traceback (most recent call last):
      File "main.py", line 214, in
      main(clargs)
      File "main.py", line 58, in main
      config = get_config(clargs)
      File "/content/drive/MyDrive/cvt2distilgpt2/transmodal/config.py", line 89, in get_config
      local_files_only=True,
      File "/usr/local/lib/python3.7/dist-packages/transformers/models/auto/tokenization_auto.py", line 609, in from_pretrained
      return tokenizer_class_fast.from_pretrained(pretrained_model_name_or_path, *inputs, **kwargs)
      File "/usr/local/lib/python3.7/dist-packages/transformers/tokenization_utils_base.py", line 1812, in from_pretrained
      **kwargs,
      File "/usr/local/lib/python3.7/dist-packages/transformers/tokenization_utils_base.py", line 1836, in _from_pretrained
      **(copy.deepcopy(kwargs)),
      File "/usr/local/lib/python3.7/dist-packages/transformers/tokenization_utils_base.py", line 1950, in _from_pretrained
      tokenizer = cls(*init_inputs, **init_kwargs)
      File "/usr/local/lib/python3.7/dist-packages/transformers/models/gpt2/tokenization_gpt2.py", line 192, in init
      with open(merges_file, encoding="utf-8") as merges_handle:

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

Thanks.

@anicolson
Copy link
Member

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
Copy link
Author

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 "

  • CUDA:
    • GPU:
      • Tesla V100-SXM2-16GB
    • available: True
    • version: 10.2
  • Packages:
    • numpy: 1.22.1
    • pyTorch_debug: False
    • pyTorch_version: 1.10.1+cu102
    • pytorch-lightning: 1.5.8
    • tqdm: 4.62.3
  • System:
    • OS: Linux
    • architecture:
      • 64bit
    • processor: x86_64
    • python: 3.9.1
    • version: CE Metrics #1 SMP Sun Apr 24 10:03:06 PDT 2022
      /content/drive/MyDrive/cvt2distilgpt2/transmodal/ext/cvt/models/cls_cvt.py:558: SyntaxWarning: "is" with a literal. Did you mean "=="?
      or pretrained_layers[0] is '*'
      Traceback (most recent call last):
      File "/content/drive/MyDrive/cvt2distilgpt2/main.py", line 214, in
      main(clargs)
      File "/content/drive/MyDrive/cvt2distilgpt2/main.py", line 58, in main
      config = get_config(clargs)
      File "/content/drive/MyDrive/cvt2distilgpt2/transmodal/config.py", line 87, in get_config
      config["tokenizer"] = AutoTokenizer.from_pretrained(
      File "/usr/local/lib/python3.9/site-packages/transformers/models/auto/tokenization_auto.py", line 550, in from_pretrained
      return tokenizer_class_fast.from_pretrained(pretrained_model_name_or_path, *inputs, **kwargs)
      File "/usr/local/lib/python3.9/site-packages/transformers/tokenization_utils_base.py", line 1747, in from_pretrained
      return cls._from_pretrained(
      File "/usr/local/lib/python3.9/site-packages/transformers/tokenization_utils_base.py", line 1773, in _from_pretrained
      slow_tokenizer = (cls.slow_tokenizer_class)._from_pretrained(
      File "/usr/local/lib/python3.9/site-packages/transformers/tokenization_utils_base.py", line 1882, in _from_pretrained
      tokenizer = cls(*init_inputs, **init_kwargs)
      File "/usr/local/lib/python3.9/site-packages/transformers/models/gpt2/tokenization_gpt2.py", line 186, in init
      with open(merges_file, encoding="utf-8") as merges_handle:

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

@anicolson
Copy link
Member

anicolson commented Aug 3, 2022

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:

config["tokenizer"] = AutoTokenizer.from_pretrained(

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

Aaron.

@jainnipun11
Copy link
Author

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
Copy link
Member

Hi @jainnipun11,

Try this: huggingface/transformers#15212

@jainnipun11
Copy link
Author

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 "

  • CUDA:
    • GPU:
      • Tesla V100-SXM2-16GB
    • available: True
    • version: 10.2
  • Packages:
    • numpy: 1.22.1
    • pyTorch_debug: False
    • pyTorch_version: 1.10.1+cu102
    • pytorch-lightning: 1.5.8
    • tqdm: 4.62.3
  • System:
    • OS: Linux
    • architecture:
      • 64bit
    • processor: x86_64
    • python: 3.9.1
    • version: CE Metrics #1 SMP Sun Apr 24 10:03:06 PDT 2022
      Traceback (most recent call last):
      File "/content/drive/MyDrive/cvt2distilgpt2/main.py", line 214, in
      main(clargs)
      File "/content/drive/MyDrive/cvt2distilgpt2/main.py", line 58, in main
      config = get_config(clargs)
      File "/content/drive/MyDrive/cvt2distilgpt2/transmodal/config.py", line 90, in get_config
      config["tokenizer"] = AutoTokenizer.from_pretrained(
      File "/usr/local/lib/python3.9/site-packages/transformers/models/auto/tokenization_auto.py", line 550, in from_pretrained
      return tokenizer_class_fast.from_pretrained(pretrained_model_name_or_path, *inputs, **kwargs)
      File "/usr/local/lib/python3.9/site-packages/transformers/tokenization_utils_base.py", line 1747, in from_pretrained
      return cls._from_pretrained(
      File "/usr/local/lib/python3.9/site-packages/transformers/tokenization_utils_base.py", line 1773, in _from_pretrained
      slow_tokenizer = (cls.slow_tokenizer_class)._from_pretrained(
      File "/usr/local/lib/python3.9/site-packages/transformers/tokenization_utils_base.py", line 1882, in _from_pretrained
      tokenizer = cls(*init_inputs, **init_kwargs)
      File "/usr/local/lib/python3.9/site-packages/transformers/models/gpt2/tokenization_gpt2.py", line 186, in init
      with open(merges_file, encoding="utf-8") as merges_handle:
      TypeError: expected str, bytes or os.PathLike object, not NoneType

Thank you.
Nipun

@anicolson
Copy link
Member

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants