-
Notifications
You must be signed in to change notification settings - Fork 89
feats(transformers):add flex_olmo model #1442
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 @iugoood, 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 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 flex_olmo model, adapting it for the mindone/transformers library. The changes include adding the model implementation, registering it within the auto-modeling framework, and providing corresponding tests.
My review has identified two critical issues:
- The model implementation depends on
FlexOlmoConfigfrom thetransformerslibrary, but this configuration has not been ported tomindone/transformers. - There is a bug in the
load_balancing_loss_funcwhich will cause the auxiliary loss to be calculated incorrectly.
I have also included a medium-severity suggestion to improve code style by avoiding wildcard imports. Please address the critical issues before merging.
| from ...modeling_rope_utils import ROPE_INIT_FUNCTIONS, dynamic_rope_update | ||
| from ...modeling_utils import ALL_ATTENTION_FUNCTIONS, PreTrainedModel | ||
| from ...processing_utils import Unpack | ||
| from ...utils import TransformersKwargs |
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 FlexOlmoConfig is being imported from the transformers library. To make this implementation self-contained within mindone, the configuration file for FlexOlmo should also be ported and included in this repository, preferably at mindone/transformers/models/flex_olmo/configuration_flex_olmo.py. This change is also needed in the corresponding test file (tests/transformers_tests/models/flex_olmo/test_modeling_flex_olmo.py).
| ) | ||
|
|
||
| # Compute the average probability of routing to these experts | ||
| router_prob_per_expert = mindspore.mint.sum( |
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 appears to be a bug in the calculation of overall_loss. The variable rank is assigned routing_weights.shape[1], and then used to slice tokens_per_expert as tokens_per_expert[:, rank : rank + routing_weights.shape[1]]. This slicing will result in an empty tensor, causing the auxiliary loss to be incorrectly calculated as zero.
The slicing and the rank variable should be removed. The correct calculation should be a direct multiplication, as in the original PyTorch implementation.
| ) | |
| # Compute the average probability of routing to these experts | |
| router_prob_per_expert = mindspore.mint.sum( | |
| overall_loss = mindspore.mint.sum(tokens_per_expert * router_prob_per_expert.unsqueeze(0)) |
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
| from .modeling_flex_olmo import * |
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.
Using a wildcard import (*) can lead to namespace pollution and makes it harder to trace where classes and functions originate. It's better to import names explicitly.
Additionally, this file is missing a final newline, which is a common convention.
| from .modeling_flex_olmo import * | |
| from .modeling_flex_olmo import ( | |
| FlexOlmoForCausalLM, | |
| FlexOlmoModel, | |
| FlexOlmoPreTrainedModel, | |
| ) | |
Add
1 add flex_olmo model
2 add UT
Due to excessive weight causing an out-of-memory (OOM) error on the NPU, only the first 2 layers are being tested.
Usage
Performance
Experiments are tested on Ascend Atlas 800T A2 machines with mindspore 2.6.0.