-
Notifications
You must be signed in to change notification settings - Fork 33.9k
Add support for MiniMax-M2 #42028
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
Merged
Merged
Add support for MiniMax-M2 #42028
Changes from 17 commits
Commits
Show all changes
46 commits
Select commit
Hold shift + click to select a range
5363916
update: init m2
261fe5c
update: docs and config
ac4613c
update: init minimax-m2 test
3421fe7
update: fix tests
3a5df7a
update: use partial_rotary_factor
cb17f62
update: some fix
f6775d8
fix: import Unpack from processing_utils
73904ee
update: apply suggestions from code review
rogeryoungh 6b7e397
update: remove MiniMaxM2DecoderLayer and MiniMaxM2MLP
1565721
update: remove use_qk_norm
fa09301
update: remove unused use_qk_norm
11fdb58
update: update config and attention
93b7598
update: add to tokenization_auto and remove unused test
5de5179
Merge branch 'main' into minimax-m2
rogeryoungh f5219ca
update: fix decoder layer and experts
ef9a1f9
update: fix docs
a0eea92
update: make ci happy
2dbfc3b
refactor: use mapping
640fb9f
update: remove unused comments
8fe4d2b
Merge branch 'main' into minimax-m2
rogeryoungh 17c68c8
Merge branch 'main' into minimax-m2
rogeryoungh 8ba23a6
update: fix rope_params and router
8a76b78
update: remove rope_theta
bcc0aa1
update: test_load_balancing_loss
5a82172
Merge branch 'main' into minimax-m2
rogeryoungh 47c84e2
update: docs
fdb6807
update: fix default theta
1f07a00
update to proper default values, proper config rope, simplified modular
vasqu 25a8b5c
fix docs
vasqu 7ea9a2b
modular fixup
vasqu 13ed0be
Merge branch 'main' into minimax-m2
vasqu 9eebced
review comments
vasqu 668dbef
Merge branch 'main' into minimax-m2
vasqu 90acf7c
update slow tests
vasqu e4463e1
style
vasqu fde9591
fp32 strict
vasqu 7b6824f
revert the flag
vasqu dda58d9
Merge branch 'main' into minimax-m2
vasqu 04c0b5f
Merge branch 'main' into minimax-m2
vasqu 8703235
sync with latest changes
vasqu 53c19ac
fixup buffer init
vasqu 28f26fd
add cache exception to minimax m2 as we have a naming clash
vasqu cca9ee7
fix dtype issue in gate
vasqu 3d6d671
Merge branch 'main' into minimax-m2
vasqu b867712
lift fp8 test restriction and apply new linter rules
vasqu 252d02d
update docs
vasqu File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,82 @@ | ||
| <!--Copyright 2025 the HuggingFace Team. All rights reserved. | ||
|
|
||
| Licensed under the Apache License, Version 2.0 (the "License"); | ||
| you may not use this file except in compliance with the License. | ||
| You may obtain a copy of the License at | ||
|
|
||
| http://www.apache.org/licenses/LICENSE-2.0 | ||
|
|
||
| Unless required by applicable law or agreed to in writing, software | ||
| distributed under the License is distributed on an "AS IS" BASIS, | ||
| 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. | ||
|
|
||
|
|
||
| ⚠️ Note that this file is in Markdown but contain specific syntax for our doc-builder (similar to MDX) that may not be rendered properly in your Markdown viewer. | ||
|
|
||
| --> | ||
|
|
||
|
|
||
| # MiniMax-M2 | ||
|
|
||
| ## Overview | ||
|
|
||
| MiniMax-M2 is a compact, fast, and cost-effective MoE model (230 billion total parameters with 10 billion active parameters) built for elite performance in coding and agentic tasks, all while maintaining powerful general intelligence. With just 10 billion activated parameters, MiniMax-M2 provides the sophisticated, end-to-end tool use performance expected from today's leading models, but in a streamlined form factor that makes deployment and scaling easier than ever. | ||
|
|
||
| For more details refer to the [release blog post](https://www.minimax.io/news/minimax-m2). | ||
|
|
||
| ## Usage examples | ||
|
|
||
| ```python | ||
| from transformers import AutoTokenizer, AutoModelForCausalLM, GenerationConfig | ||
|
|
||
| model = AutoModelForCausalLM.from_pretrained("MiniMaxAI/MiniMax-M2", device_map="auto") | ||
|
|
||
| tokenizer = AutoTokenizer.from_pretrained("MiniMaxAI/MiniMax-M2") | ||
|
|
||
| generation_config = GenerationConfig.from_pretrained("MiniMaxAI/MiniMax-M2") | ||
|
|
||
| messages = [ | ||
| {"role": "user", "content": "What is your favourite condiment?"}, | ||
| {"role": "assistant", "content": "Well, I'm quite partial to a good squeeze of fresh lemon juice. It adds just the right amount of zesty flavour to whatever I'm cooking up in the kitchen!"}, | ||
| {"role": "user", "content": "Do you have mayonnaise recipes?"} | ||
| ] | ||
|
|
||
| model_inputs = tokenizer.apply_chat_template(messages, return_tensors="pt", add_generation_prompt=True).to("cuda") | ||
|
|
||
| generated_ids = model.generate(model_inputs, max_new_tokens=100, generation_config=generation_config) | ||
|
|
||
| response = tokenizer.batch_decode(generated_ids)[0] | ||
|
|
||
| print(response) | ||
| ``` | ||
|
|
||
| ## MiniMaxM2Config | ||
|
|
||
| [[autodoc]] MiniMaxM2Config | ||
|
|
||
| ## MiniMaxM2ForCausalLM | ||
|
|
||
| [[autodoc]] MiniMaxM2ForCausalLM | ||
| - forward | ||
|
|
||
| ## MiniMaxM2ForQuestionAnswering | ||
|
|
||
| [[autodoc]] MiniMaxM2ForQuestionAnswering | ||
| - forward | ||
|
|
||
| ## MiniMaxM2Model | ||
|
|
||
| [[autodoc]] MiniMaxM2Model | ||
| - forward | ||
|
|
||
| ## MiniMaxM2ForSequenceClassification | ||
|
|
||
| [[autodoc]] MiniMaxM2ForSequenceClassification | ||
| - forward | ||
|
|
||
| ## MiniMaxM2ForTokenClassification | ||
|
|
||
| [[autodoc]] MiniMaxM2ForTokenClassification | ||
| - forward |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| # coding=utf-8 | ||
| # Copyright 2025 the HuggingFace Team. All rights reserved. | ||
| # | ||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| # you may not use this file except in compliance with the License. | ||
| # You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # 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 typing import TYPE_CHECKING | ||
|
|
||
| from ...utils import _LazyModule | ||
| from ...utils.import_utils import define_import_structure | ||
|
|
||
|
|
||
| if TYPE_CHECKING: | ||
| from .configuration_minimax_m2 import * | ||
| from .modeling_minimax_m2 import * | ||
| else: | ||
| import sys | ||
|
|
||
| _file = globals()["__file__"] | ||
| sys.modules[__name__] = _LazyModule(__name__, _file, define_import_structure(_file), module_spec=__spec__) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.