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

fix for custom pipeline configuration #29004

Merged

Conversation

not-lain
Copy link
Contributor

@not-lain not-lain commented Feb 13, 2024

What does this PR do?

fixes configuration file not pointing at a remote repo with custom pipeline architecture

Fixes #28907

Before submitting

  • This PR fixes a typo or improves the docs (you can dismiss the other checks if that's the case).
  • Did you read the contributor guideline,
    Pull Request section?
  • Was this discussed/approved via a Github issue or the forum? Please add a link
    to it if that's the case.
  • Did you make sure to update the documentation with your changes? Here are the
    documentation guidelines, and
    here are tips on formatting docstrings.
  • Did you write any new necessary tests?

Who can review?

@Rocketknight1

@not-lain
Copy link
Contributor Author

@Rocketknight1 could you review this one too ?
fixed the tests (i forgor to update my branch :D )

@Rocketknight1
Copy link
Member

Sure, I'll try to take a look at this one and the pipeline upload one!

@not-lain
Copy link
Contributor Author

cc @Rocketknight1 any review on this one

@HuggingFaceDocBuilderDev

The docs for this PR live here. All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update.

Copy link
Member

@Rocketknight1 Rocketknight1 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I reviewed this and I'm going to approve it on the basis that I think it fixes some specific issues and doesn't break anything that currently works, but I think we need much more clarity in the docs and our conceptual model of custom pipelines in future - this was quite a hard PR to review because I wasn't really sure what behaviour our library was "supposed" to have in these cases.

See my comment here for more.

@Rocketknight1
Copy link
Member

cc @ArthurZucker for core maintainer review

@not-lain
Copy link
Contributor Author

cc @Rocketknight1 @ArthurZucker
I made this video to explain why this is important https://youtu.be/2LPJ_1QuK90

@not-lain
Copy link
Contributor Author

it also explains the fundamentals of the transformers library on how to load the custom architecture from a repo that has the architecture defined on another one, which is a workaround i used before on this .

it's pretty much always depends on the config.json which is why it's essential to fix it

Copy link
Collaborator

@ArthurZucker ArthurZucker left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My main question is why don't we update the save_pretrained part as well to make sure what we already have the correct module?
We can keep your changes for the previous checkpoints, and make sure new ones have the full path (like it is the case for tokenizer and model code path)
Also let's maybe add a test close to https://github.com/huggingface/transformers/blob/d03de1c1070cee0fb7b9358669abc3f68ef56b75/tests/pipelines/test_pipelines_common.py#L709 to make sure we can load a custom pipeline from not-laion when it was pushed from laion!

feature_extractor_dict["auto_map"] = add_model_info_to_auto_map(
feature_extractor_dict["auto_map"], pretrained_model_name_or_path
)
if not is_local:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just curious as to why we only do it if not local whereas before we did it for local and not local? 🤗

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what does is_local mean ?

if i call a model using this

path = "./folder1/folder2/folder3"
from transformers import AutoModelForImageClassification
model = AutoModelForImageClassification.from_pretrained(path, trust_remote_code=True)

if the path exists in my pc then we load from there

what if the is_local is false ?

then in this case we call the model from the hub and add the tag

is the tag added when we are only calling a custom model from huggingface ?

yes, there is no need to add the tag if we are calling the model from the local pc

hope this answers your questions 🤗

@not-lain
Copy link
Contributor Author

not-lain commented Mar 4, 2024

@ArthurZucker in this pr the configuration tag is added when we are calling the model not when we are saving it which is why it is funadamentally different from the other pr.

check more about the config.json in this repo and then try loading the model and check the config after calling it for more details

# Load model directly
from transformers import AutoModelForImageClassification
model = AutoModelForImageClassification.from_pretrained("not-lain/29004", trust_remote_code=True)
model.config

i know it's pretty weird but this is how the transformers library is working rn.

as for the tests

@not-lain
Copy link
Contributor Author

not-lain commented Mar 5, 2024

@ArthurZucker
your confusion is on me, i have wrongly mentioned the issue, now after checking the code and experimenting more i now know the configuration is being changed when we are calling the model and not when we are saving/pushing

again apologies for the confusion

EDIT
the issue still stands for cases such as finetuning and others since we will push wrongly annotated config to a new repo meaning the new repo will have a broken pipeline.
I will also try to add dummy tests soon.

Copy link
Collaborator

@ArthurZucker ArthurZucker left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's wait for the test to do another round of review!

@not-lain
Copy link
Contributor Author

not-lain commented Mar 6, 2024

cc @ArthurZucker
this should be ready for review

@not-lain
Copy link
Contributor Author

not-lain commented Mar 7, 2024

@ArthurZucker @Rocketknight1
could you review #29172 first, since i need the push_to_hub feature from there added to the main branch to add more coverage to the tests just to be safe.

i'll update the tests on this pull request right after, sending lots of hugs 🤗🤗

@ArthurZucker
Copy link
Collaborator

Sorry on our late answers here! I was off for a while !

@not-lain
Copy link
Contributor Author

@ArthurZucker hope you had fun ✨✨, anyways I have updated the tests to be more straight forward and to the point, do let me know if you have any reviews on this

@not-lain
Copy link
Contributor Author

not-lain commented Apr 8, 2024

@ArthurZucker there's no need to wait for 29172 anymore since in 323b50d I switched to using the model to push to another repo (case finetuned model with custom pipeline), also friendly pinging for a review

@not-lain
Copy link
Contributor Author

Hi @ArthurZucker
Any reviews on this PR?

@not-lain
Copy link
Contributor Author

@ArthurZucker friendly tagging you here

@not-lain
Copy link
Contributor Author

hey @ArthurZucker , hope you're doing well.
can I get a review on this PR ?

@ArthurZucker
Copy link
Collaborator

Wow I am sorry @not-lain really my bad here

Copy link
Collaborator

@ArthurZucker ArthurZucker left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems to work well, I think overall I just don't like that we have to duplicate the logic everywhere but that's not on you!
Thanks for your continuous contribution to the library and the ecosytem! And sorry for being so late here

@ArthurZucker ArthurZucker merged commit c11ac78 into huggingface:main May 20, 2024
20 checks passed
@not-lain
Copy link
Contributor Author

@ArthurZucker it's ok, you have been busy with lots of stuff including llama-3 and I know things are hectic on your side, just remember to take a break once in a while.
Also thanks a lot for the review, and I wish you a wonderful day ✨

itazap pushed a commit that referenced this pull request May 24, 2024
* fix for custom pipeline configuration

* fix for custom pipelines

* remove extra exception

* added test for custom pipelines extra tag

* format with ruff

* limit extra tag for first time only

* format with ruff

* improve tests for custom pipelines
zucchini-nlp pushed a commit to zucchini-nlp/transformers that referenced this pull request Jun 11, 2024
* fix for custom pipeline configuration

* fix for custom pipelines

* remove extra exception

* added test for custom pipelines extra tag

* format with ruff

* limit extra tag for first time only

* format with ruff

* improve tests for custom pipelines
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

Successfully merging this pull request may close these issues.

wrongly annotated configuration when saving a model that has a custom pipeline
4 participants