-
Notifications
You must be signed in to change notification settings - Fork 89
feat(transformers): add Florence2 (v4.57.1) #1453
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
base: master
Are you sure you want to change the base?
Conversation
Summary of ChangesHello @alien-0119, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request significantly expands the capabilities of the Highlights
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code Review
This pull request introduces the Florence-2 model and includes a significant refactoring of the underlying BART model to align with newer features from the Hugging Face Transformers library, such as improved cache management and attention mechanisms. The changes are extensive and mostly look good.
I've identified a critical issue in the BartForCausalLM implementation where the configuration object is modified in-place, which could lead to bugs if the config is reused. I've also found a couple of medium-severity issues: a misleading error message in the BART decoder and an unused parameter in the new Florence-2 model code.
Overall, this is a great contribution. Addressing these points will improve the robustness and clarity of the code.
| def __init__(self, config): | ||
| config = copy.deepcopy(config) | ||
| config.is_decoder = True | ||
| config.is_encoder_decoder = False | ||
| super().__init__(config) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The config object is modified in-place. This is dangerous as it can lead to unexpected behavior if the config object is reused for instantiating other models. A deep copy of the configuration should be made to avoid side effects, as was done in the previous version.
Please also add import copy back to the top of the file.
| def __init__(self, config): | |
| config = copy.deepcopy(config) | |
| config.is_decoder = True | |
| config.is_encoder_decoder = False | |
| super().__init__(config) | |
| def __init__(self, config): | |
| config = copy.deepcopy(config) | |
| config.is_decoder = True | |
| config.is_encoder_decoder = False | |
| super().__init__(config) |
| if (input_ids is None) ^ (inputs_embeds is not None): | ||
| raise ValueError("You cannot specify both decoder_input_ids and decoder_inputs_embeds at the same time") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The error message is misleading. It refers to decoder_input_ids and decoder_inputs_embeds, but the check is performed on input_ids and inputs_embeds. Additionally, the message only mentions one of the failure conditions (specifying both), while the logic also fails if neither is specified. A more accurate error message would improve clarity.
| if (input_ids is None) ^ (inputs_embeds is not None): | |
| raise ValueError("You cannot specify both decoder_input_ids and decoder_inputs_embeds at the same time") | |
| if (input_ids is None) == (inputs_embeds is None): | |
| raise ValueError("You have to specify either `input_ids` or `inputs_embeds`, but not both and not neither.") |
| self.row_embeddings = mint.nn.Embedding(num_pos, embedding_dim // 2) | ||
| self.column_embeddings = mint.nn.Embedding(num_pos, embedding_dim - (embedding_dim // 2)) | ||
|
|
||
| def construct(self, pixel_values, pixel_mask=None): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What does this PR do?
Adds # (feature)
Add Florence2 model and fast ut.
Usage Example:
Performance:
Experiments were tested on Ascend Atlas 800T A2 machines with mindspore 2.7.0 pynative mode.
Before submitting
What's New. Here are thedocumentation guidelines
Who can review?
Anyone in the community is free to review the PR once the tests have passed. Feel free to tag
members/contributors who may be interested in your PR.
@xxx