[PushToHub] Make it possible to upload folders #23920
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
What does this PR do?
For some models, it may be that we have several files with the same name, e.g. for the new InstructBLIP model (#23460), the processor consists of 2 tokenizers (because the model internally uses 2 different text models). Both of these tokenizers require files with the same name, like
tokenizer_config.json
.Hence, it would be nice to create subfolders in the model repos to store for instance all files of one particular tokenizer (similar to how the Diffusers library does this). For InstructBLIP, I created a separate
qformer_tokenizer
folder for this as can be seen here. I had to adapt thesave_pretrained
andfrom_pretrained
methods ofInstructBlipProcessor
to save the files to a separate "qformer_tokenizer" folder, and read them back in. I guess those are very specific to InstructBLIP given that the name of the folder is pretty custom.However,
push_to_hub
currently doesn't support uploading folders with files. This PR adds this functionality.