-
Notifications
You must be signed in to change notification settings - Fork 29.5k
Add MLCD model #36182
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
Add MLCD model #36182
Conversation
Hi, Pavel @qubvel. Hope this message finds you well. It appears that our PR failed on the final step during CI. From the error messages, it looks like the issue stems from the Rt-Detr tests rather than problems within our code. Could you please guide us on how to disable or skip the tests for other models so we can successfully complete the CI process for our PR? Thanks! |
Hi Pavel and Arthur, @qubvel @Rocketknight1 : Could you please take a moment to review the pull request? Your insights would be immensely appreciated and would greatly contribute to ensuring the quality of the changes. We're truly grateful for your help! Thank you so much! |
Gentle ping @qubvel, but let me know if you want me to take any part of the review! |
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.
Hey @tanhuajie! Sorry for the delay and thanks a lot for working on the model addition to transformers
, great work, and already looks super clean!
I see the model is built on pretty standard modules, so it would be incredibly helpful if you could reuse library modules with inheritance using our new modular
tool.
- https://huggingface.co/docs/transformers/modular_transformers
- see other models such as gemma/ijepa/siglip2 (
modular_*.py
file)
See other comments below!
Hey @qubvel. I think it's done now. 🤗 Let me know if you have any feedback when you have a moment. |
run-slow: mlcd |
This comment contains run-slow, running the specified jobs: This comment contains run-slow, running the specified jobs: models: ['models/mlcd'] |
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.
Thanks for addressing comments 🤗
cc @ArthurZucker for review when you have bandwidth |
Dear @ArthurZucker , I hope this message finds you well! I just wanted to kindly follow up and ask if you could help review this whenever you have the time. Please don’t hesitate to let me know if there’s anything I can provide to assist. I truly appreciate your time and support! |
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.
Marvelous thanks all for the great PR! 🤗
class MLCDConfig(MLCDVisionConfig): | ||
pass |
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.
this is weird to me, we should not have two configs that are exactly the same
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.
Hi, @ArthurZucker. The reason we provided a dummy MLCDConfig
class is that when using the modular
tool to create our custom MLCDEncoder
by inheriting from CLIPEncoder
, it automatically generates an unexpected MLCDConfig
class. This generated configuration is identical to MLCDVisualConfig
in all aspects except for the name. Therefore, we included the dummy MLCDConfig
to handle this case.
If this approach isn't preferred, we can alternatively use the overwrite method to eliminate the dummy MLCDConfig
and retain only MLCDVisualConfig
. Here's how to implement it:
class MLCDEncoder(CLIPEncoder):
"""
Transformer encoder consisting of `config.num_hidden_layers` self attention layers. Each layer is a
[`MLCDEncoderLayer`].
Args:
config: MLCDVisualConfig
"""
def __init__(self, config: MLCDVisualConfig):
super().__init__(config)
This modification explicitly specifies MLCDVisualConfig
as the expected configuration type. 🤗
self.num_key_value_groups = config.num_key_value_groups | ||
self.is_causal = False | ||
|
||
def forward( |
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.
very nice!
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.
Very nice! Kudos 🤗
Hey, @tanhuajie let's resolve conflicts with main, and we are good to merge it! |
Great, I'll resolve the conflicts right away. 🤗 |
Hi @qubvel, I've resolved the conflicts, removed the dummy |
run-slow: mlcd |
This comment contains run-slow, running the specified jobs: This comment contains run-slow, running the specified jobs: models: ['models/mlcd'] |
Thanks a lot for iterating on the model addition! Gerat work 🤗 |
def get_input_embeddings(self) -> nn.Module: | ||
return self.vision_model.embeddings.patch_embedding | ||
|
||
@add_start_docstrings_to_model_forward(MLCD_VISION_INPUTS_DOCSTRING) |
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.
CI complains:
ValueError: The deployment of the documentation will fail because of the following errors:
The docstring of MLCDVisionModel.forward comports the following issue(s) and needs fixing:
- The return block is empty.
Should @replace_return_docstrings(output_type=BaseModelOutputWithPooling, config_class="MLCDVisionConfig")
be added?
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.
Thank you for the reminder. I'll take a look at how to resolve the issue you mentioned.
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.
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.
Thanks for a fix ❤️
* Add MLCD model * Update codes for auto-mapping * Add test scripts for MLCD * Update doc for MLCD model * Fix import error * Fix import error * Fix CI error for attention_outputs * Fix code style for CI * Fix code style for CI * Fix code style for CI * Fix code style for CI * Fix code style for CI * Fix CI error for initialization * Fix code style for CI * Fix code style for CI * Reformat codes and docs for CI test * Reformat codes and docs for CI test * Remove unused attributes for CI test * Fix style for CI test * List MLCD in flash_attn doc * Fix: typos, modulars, refactors from suggestions * Refactoring convert_mlcd_weights_to_hf.py from suggestions * Fix: docs conflicts * Fix error for CI test * Fix style for CI test * Add integration test for MLCD * Refactoring by class inheritance * Fix: refactor attention interface, adjust codes * Fix: merging conflicts * Fix: merging conflicts * Fix: style for CI test * Fix: style for CI test * Fix: set test_resize_embeddings to be False * Fix: initializer for CI test * Fix: conflicts, CI test, warning and refactoring * Fix: merging conflicts * Refactor * Update docs * Fix mistakes * Remove unused args and fix multi-gpu error * Revert position_embeddings * Solve conflicts * Solve conflicts * Remove dummy * Update _init_weights * Update _init_weights * Update _init_weights for CI test
* Add MLCD model * Update codes for auto-mapping * Add test scripts for MLCD * Update doc for MLCD model * Fix import error * Fix import error * Fix CI error for attention_outputs * Fix code style for CI * Fix code style for CI * Fix code style for CI * Fix code style for CI * Fix code style for CI * Fix CI error for initialization * Fix code style for CI * Fix code style for CI * Reformat codes and docs for CI test * Reformat codes and docs for CI test * Remove unused attributes for CI test * Fix style for CI test * List MLCD in flash_attn doc * Fix: typos, modulars, refactors from suggestions * Refactoring convert_mlcd_weights_to_hf.py from suggestions * Fix: docs conflicts * Fix error for CI test * Fix style for CI test * Add integration test for MLCD * Refactoring by class inheritance * Fix: refactor attention interface, adjust codes * Fix: merging conflicts * Fix: merging conflicts * Fix: style for CI test * Fix: style for CI test * Fix: set test_resize_embeddings to be False * Fix: initializer for CI test * Fix: conflicts, CI test, warning and refactoring * Fix: merging conflicts * Refactor * Update docs * Fix mistakes * Remove unused args and fix multi-gpu error * Revert position_embeddings * Solve conflicts * Solve conflicts * Remove dummy * Update _init_weights * Update _init_weights * Update _init_weights for CI test
What does this PR do?
This PR adds MLCD model from DeepGlint-AI Team.
Fixes #36181
Before submitting
Pull Request section?
to it if that's the case.
documentation guidelines, and
here are tips on formatting docstrings.
Who can review?
@amyeroberts @qubvel @ArthurZucker
Quick Test