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

Donut: fix generate call from local path #31470

Merged
merged 3 commits into from
Jun 18, 2024
Merged

Conversation

gante
Copy link
Member

@gante gante commented Jun 18, 2024

What does this PR do?

Donut has custom logic in generate. Typically, we can detect certain architectures through self.__class__.__name__, to then trigger custom logic. However, to detect donut's original checkpoints, whose model_type and architectures is incorrectly defined (e.g. here), we can't rely on self.__class__.__name__.

The custom logic that was in place relied on the hub path, but that doesn't work for local file paths. This PR fixes it by clawing at the only piece of text saying "donut" in the original config 👀

cc @nbroad1881

@gante gante force-pushed the donut_local_path branch from 2bb7510 to b9787c0 Compare June 18, 2024 10:05
@gante gante marked this pull request as ready for review June 18, 2024 10:05
@gante gante requested a review from amyeroberts June 18, 2024 10:15
# exception: Donut checkpoints have task-specific decoder starts and don't expect a BOS token. Note that the
# original checkpoints can't be detected through `self.__class__.__name__.lower()`, needing custom logic.
elif "donut" in self.__class__.__name__.lower() or (
self.config.model_type == "vision-encoder-decoder" and "donut" in self.config.encoder.model_type.lower()
Copy link
Member Author

Choose a reason for hiding this comment

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

1st or clause: new checkpoints
2nd or clause: original donut checkpoints. self.name_or_path doesn't work for local files, self.config.encoder.model_type does

Copy link
Collaborator

Choose a reason for hiding this comment

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

😬

Copy link
Collaborator

@amyeroberts amyeroberts left a comment

Choose a reason for hiding this comment

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

Thanks for fixing!

Seems like the best fix for a not-ideal hard-to-fix situation.

src/transformers/generation/utils.py Show resolved Hide resolved
# exception: Donut checkpoints have task-specific decoder starts and don't expect a BOS token. Note that the
# original checkpoints can't be detected through `self.__class__.__name__.lower()`, needing custom logic.
elif "donut" in self.__class__.__name__.lower() or (
self.config.model_type == "vision-encoder-decoder" and "donut" in self.config.encoder.model_type.lower()
Copy link
Collaborator

Choose a reason for hiding this comment

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

😬

@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.

Co-authored-by: amyeroberts <22614925+amyeroberts@users.noreply.github.com>
@gante gante merged commit cd71f93 into huggingface:main Jun 18, 2024
21 checks passed
@gante gante deleted the donut_local_path branch June 18, 2024 12:28
itazap pushed a commit that referenced this pull request Jun 18, 2024
* local donut path fix

* engrish

* Update src/transformers/generation/utils.py

Co-authored-by: amyeroberts <22614925+amyeroberts@users.noreply.github.com>

---------

Co-authored-by: amyeroberts <22614925+amyeroberts@users.noreply.github.com>
itazap pushed a commit that referenced this pull request Jun 20, 2024
* local donut path fix

* engrish

* Update src/transformers/generation/utils.py

Co-authored-by: amyeroberts <22614925+amyeroberts@users.noreply.github.com>

---------

Co-authored-by: amyeroberts <22614925+amyeroberts@users.noreply.github.com>
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.

3 participants