huggingface / transformers

🤗 Transformers: State-of-the-art Machine Learning for Pytorch, TensorFlow, and JAX.
https://huggingface.co/transformers
Apache License 2.0
134.75k stars 26.95k forks source link

Cannot use local files for AutoModelForVision2Seq when using BLIP3 #32927

Closed dibbla closed 2 months ago

dibbla commented 2 months ago

System Info

Who can help?

@zucchini-nlp @ArthurZucker @amyeroberts

Information

Tasks

Reproduction

I am using the latest Salesforce/xgen-mm-phi3-mini-base-r-v1 for image captioning. To reproduce,

  1. Download all the file (the entire directory of Salesforce/xgen-mm-phi3-mini-base-r-v1) from huggingface link.
  2. Run the following code to load LOCAL model (I just put it under /root)
    
    from transformers import AutoModelForVision2Seq, AutoTokenizer, AutoImageProcessor
    import json
    import PIL
    import IPython.display as display
    import torch

model_name_or_path = "/root/xgen-mm-phi3-mini-base-r-v1.5/" model = AutoModelForVision2Seq.from_pretrained(model_name_or_path, trust_remote_code=True)



### Expected behavior

It just start to launch a long download process and I don't see why the local files are used.
zucchini-nlp commented 2 months ago

Hey @dibbla !

I just tried your script and it didn't trigger any downloading process, the only process was loading checkpoint shards. Can you make sure that the given directory exists and has the model checkpoints in it

dibbla commented 2 months ago

Hey @dibbla !

I just tried your script and it didn't trigger any downloading process, the only process was loading checkpoint shards. Can you make sure that the given directory exists and has the model checkpoints in it

Thanks for the fast reply @zucchini-nlp

I just confirmed that the directory does contain the model files.

Code:

from transformers import AutoModelForVision2Seq, AutoTokenizer, AutoImageProcessor
import json
import PIL
import IPython.display as display
import torch
import os

model_name_or_path = "/root/xgen-mm-phi3-mini-base-r-v1.5/"
print(os.listdir(model_name_or_path))
model = AutoModelForVision2Seq.from_pretrained(model_name_or_path, trust_remote_code=True)

What I observe (it starts download):

['model-00002-of-00004.safetensors', 'added_tokens.json', 'image_processing_blip_3.py', 'README.md', 'preprocessor_config.json', 'icl_examples', 'special_tokens_map.json', 'model-00001-of-00004.safetensors', 'model-00003-of-00004.safetensors', 'generation_config.json', 'demo.ipynb', 'tokenizer.json', '.huggingface', '.gitattributes', 'config.json', 'model.safetensors.index.json', 'modeling_xgenmm.py', 'test_samples', 'tokenizer_config.json', 'model-00004-of-00004.safetensors']
model.safetensors:  14%|██████████████▌                                                                                           | 482M/3.51G [00:09<48:00, 1.05MB/s]

Is there any differences between my directory and yours?

zucchini-nlp commented 2 months ago

Hmm, yes, I have the same files under the directory. It is weird, can you verify that the loading goes through this path and ensures that the passed model_id is a path?

https://github.com/huggingface/transformers/blob/3bb7b05229466ce820f76dadb250a848e7eb22e7/src/transformers/modeling_utils.py#L3430-L3436

dibbla commented 2 months ago

Hmm, yes, I have the same files under the directory. It is weird, can you verify that the loading goes through this path and ensures that the passed model_id is a path?

https://github.com/huggingface/transformers/blob/3bb7b05229466ce820f76dadb250a848e7eb22e7/src/transformers/modeling_utils.py#L3430-L3436

Hi @zucchini-nlp

Problem solved, though not knowing why 🤔

I downloaded the main branch of transformers and install it from source, and things work fine. I also noticed that this issue affects not only blip3 but other models using transformers' autopipelines. It may have to do with the environment setting given I am using a VM.

Closing this issue and I might comment if I have time to further investigate