facebookresearch / mmf

A modular framework for vision & language multimodal research from Facebook AI Research (FAIR)
https://mmf.sh/
Other
5.5k stars 939 forks source link

Absolute paths in VisualBERT configuration file #784

Closed Yulmart closed 1 year ago

Yulmart commented 3 years ago

❓ Questions and Help

My team and I were using the visual_bert.pretrained.coco model and ran into the following error.

PermissionError                           Traceback (most recent call last)
~/Desktop/ece496-capstone/env/lib/python3.8/site-packages/transformers/modeling_utils.py in from_pretrained(cls, pretrained_model_name_or_path, *model_args, **kwargs)
    918                 # Load from URL or cache if already cached
--> 919                 resolved_archive_file = cached_path(
    920                     archive_file,

~/Desktop/ece496-capstone/env/lib/python3.8/site-packages/transformers/file_utils.py in cached_path(url_or_filename, cache_dir, force_download, proxies, resume_download, user_agent, extract_compressed_file, force_extract, local_files_only)
    942         # URL, so get it from the cache (downloading if necessary)
--> 943         output_path = get_from_cache(
    944             url_or_filename,

~/Desktop/ece496-capstone/env/lib/python3.8/site-packages/transformers/file_utils.py in get_from_cache(url, cache_dir, force_download, proxies, etag_timeout, resume_download, user_agent, local_files_only)
   1051 
-> 1052     os.makedirs(cache_dir, exist_ok=True)
   1053 

/usr/lib/python3.8/os.py in makedirs(name, mode, exist_ok)
    212         try:
--> 213             makedirs(head, exist_ok=exist_ok)
    214         except FileExistsError:

/usr/lib/python3.8/os.py in makedirs(name, mode, exist_ok)
    212         try:
--> 213             makedirs(head, exist_ok=exist_ok)
    214         except FileExistsError:

/usr/lib/python3.8/os.py in makedirs(name, mode, exist_ok)
    212         try:
--> 213             makedirs(head, exist_ok=exist_ok)
    214         except FileExistsError:

/usr/lib/python3.8/os.py in makedirs(name, mode, exist_ok)
    212         try:
--> 213             makedirs(head, exist_ok=exist_ok)
    214         except FileExistsError:

/usr/lib/python3.8/os.py in makedirs(name, mode, exist_ok)
    212         try:
--> 213             makedirs(head, exist_ok=exist_ok)
    214         except FileExistsError:

/usr/lib/python3.8/os.py in makedirs(name, mode, exist_ok)
    212         try:
--> 213             makedirs(head, exist_ok=exist_ok)
    214         except FileExistsError:

/usr/lib/python3.8/os.py in makedirs(name, mode, exist_ok)
    222     try:
--> 223         mkdir(name, mode)
    224     except OSError:

PermissionError: [Errno 13] Permission denied: '/private'

During handling of the above exception, another exception occurred:

OSError                                   Traceback (most recent call last)
<ipython-input-10-42cd85b62e5b> in <module>
----> 1 demo = MMFDemo()

<ipython-input-8-f6b4b40dbdb4> in __init__(self)
     42   def __init__(self):
     43     self._init_processors()
---> 44     self.visual_bert = registry.get_model_class(
     45             "visual_bert"
     46         ).from_pretrained(

~/Desktop/ece496-capstone/mmf/mmf/models/base_model.py in from_pretrained(cls, model_name_or_path, *args, **kwargs)
    307         instance = cls(config)
    308         instance.is_pretrained = True
--> 309         instance.build()
    310         incompatible_keys = instance.load_state_dict(checkpoint, strict=False)
    311 

~/Desktop/ece496-capstone/mmf/mmf/models/visual_bert.py in build(self)
    402     def build(self):
    403         if self.training_head_type == "pretraining":
--> 404             self.model = VisualBERTForPretraining(self.config)
    405         else:
    406             self.model = VisualBERTForClassification(self.config)

~/Desktop/ece496-capstone/mmf/mmf/models/visual_bert.py in __init__(self, config)
    172             )
    173         else:
--> 174             self.bert = VisualBERTBase.from_pretrained(
    175                 self.config.bert_model_name,
    176                 config=self.bert_config,

~/Desktop/ece496-capstone/env/lib/python3.8/site-packages/transformers/modeling_utils.py in from_pretrained(cls, pretrained_model_name_or_path, *model_args, **kwargs)
    933                     f"- or '{pretrained_model_name_or_path}' is the correct path to a directory containing a file named one of {WEIGHTS_NAME}, {TF2_WEIGHTS_NAME}, {TF_WEIGHTS_NAME}.\n\n"
    934                 )
--> 935                 raise EnvironmentError(msg)
    936 
    937             if resolved_archive_file == archive_file:

OSError: Can't load weights for 'bert-base-uncased'. Make sure that:

- 'bert-base-uncased' is a correct model identifier listed on 'https://huggingface.co/models'

- or 'bert-base-uncased' is the correct path to a directory containing a file named one of pytorch_model.bin, tf_model.h5, model.ckpt.

We noticed that the cached model configuration file ~/.cache/torch/mmf/data/models/visual_bert.pretrained.coco.defaults/config.yaml contains absolute paths that were causing the PermissionError. For example, there was an entry for cache_dir: /private/home/vedanuj/.cache/torch/mmf. After changing these paths, the error went away. However. I'm not sure if this is a bug or if it's intended to be this way. Are we expected to change and override such paths whenever we download models?

vedanuj commented 3 years ago

Hi @Yulmart .. can you share the command you used to run?

Yulmart commented 3 years ago

Hi @Yulmart .. can you share the command you used to run?

Hey, this is the code that we ran.

visual_bert = registry.get_model_class("visual_bert").from_pretrained("visual_bert.pretrained.coco")
junqi-jiang commented 3 years ago

Hi, don't know if this has been resolved, but I solved this issue by modifying the config file that came with the downloaded pretrained checkpoint. Find that config.yaml under your default cache folder and change any attributes with 'home/private/xxx/...' to your own directories.

Yulmart commented 3 years ago

Hey @junqi-jiang, thanks for the followup. We ended up changing the attributes manually as well.

HireTheHero commented 2 years ago

Hi, met the same issue when trying below;

from mmf.models.vilbert import ViLBERT
model = ViLBERT.from_pretrained("vilbert.finetuned.hateful_memes.direct")

In my case I did the manual fixes as below to ~/.cache/torch/mmf/data/models/vilbert.finetuned.hateful_memes.direct/config.yaml;

dataset_config:
  hateful_memes:
    # data_dir: /private/home/vedanuj/.cache/torch/mmf/data/datasets
    data_dir: /absolute/path/to/.cache/torch/mmf/data/datasets

env:
  # cache_dir: /private/home/vedanuj/.cache/torch/mmf
  cache_dir: /absolute/path/to/.cache/torch/mmf
  dataset_zoo: configs/zoo/datasets.yaml
  model_zoo: configs/zoo/models.yaml
  # data_dir: /private/home/vedanuj/.cache/torch/mmf/data
  data_dir: /absolute/path/to/.cache/torch/mmf/data
  # save_dir: /private/home/vedanuj/projects/save_dir
  save_dir: /absolute/path/to/save_dir