Code is not portable

#4
by fferroni - opened

Hello,

Thank you for the release.

If I run the following:

from transformers import AutoModel

model = AutoModel.from_pretrained("OpenGVLab/InternVideo2-Stage2_6B", trust_remote_code=True).eval()

from an arbitrary script, it will download the weights and code correctly to the hugging face cache, but it will then fail with

/data/huggingface/modules/transformers_modules/modeling_internvideo2.py:3277: in build_text_encoder
    text_encoder = build_bert(
/data/huggingface/modules/transformers_modules/modeling_internvideo2.py:2371: in build_bert
    bert_config = BertConfig.from_json_file(model_config.text_encoder.config)
/usr/local/lib/python3.10/dist-packages/transformers/configuration_utils.py:819: in from_json_file
    config_dict = cls._dict_from_json_file(json_file)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
/usr/local/lib/python3.10/dist-packages/transformers/modeling_utils.py:3832: in from_pretrained
    model = cls(config, *model_args, **model_kwargs)
/data/huggingface/modules/transformers_modules/OpenGVLab/InternVideo2-Stage2_6B/fd8ef758daf132d4738325d39546dd76ce26911d/modeling_internvideo2.py:3163: in __init__
    self.text_encoder = self.build_text_encoder()
/data/huggingface/modules/transformers_modules/OpenGVLab/InternVideo2-Stage2_6B/fd8ef758daf132d4738325d39546dd76ce26911d/modeling_internvideo2.py:3277: in build_text_encoder
    text_encoder = build_bert(
/data/huggingface/modules/transformers_modules/OpenGVLab/InternVideo2-Stage2_6B/fd8ef758daf132d4738325d39546dd76ce26911d/modeling_internvideo2.py:2371: in build_bert
    bert_config = BertConfig.from_json_file(model_config.text_encoder.config)
/usr/local/lib/python3.10/dist-packages/transformers/configuration_utils.py:819: in from_json_file
    config_dict = cls._dict_from_json_file(json_file)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

cls = <class 'transformers_modules.OpenGVLab.InternVideo2-Stage2_6B.fd8ef758daf132d4738325d39546dd76ce26911d.modeling_internvideo2.BertConfig'>, json_file = 'configs/config_bert_large.json'

    @classmethod
    def _dict_from_json_file(cls, json_file: Union[str, os.PathLike]):
>       with open(json_file, "r", encoding="utf-8") as reader:
E       FileNotFoundError: [Errno 2] No such file or directory: 'configs/config_bert_large.json'

/usr/local/lib/python3.10/dist-packages/transformers/configuration_utils.py:824: FileNotFoundError

I suspect that the code in the HF repo assumes that the python script is being executed at the root of the folder (I suppose this is ok for testing, but makes it not very portable)

Sign up or log in to comment