-
Notifications
You must be signed in to change notification settings - Fork 32.1k
[Ministral 3] Add ministral 3 #42498
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
ArthurZucker
merged 40 commits into
huggingface:main
from
patrickvonplaten:add_ministral_3
Dec 1, 2025
Merged
Changes from all commits
Commits
Show all changes
40 commits
Select commit
Hold shift + click to select a range
00b364c
Up
patrickvonplaten 05db608
WIP
patrickvonplaten b852600
WIP
patrickvonplaten 723db43
WIP
patrickvonplaten ce3015d
Apply suggestions from code review
patrickvonplaten 2d4578a
Merge branch 'main' into add_ministral_3
patrickvonplaten 8470dca
Update src/transformers/models/ministral3/configuration_ministral3.py
patrickvonplaten b7100b0
Merge branch 'main' of github.com:huggingface/transformers into add_m…
ArthurZucker d551a48
fix most tests
ArthurZucker 4f2331f
update docsting
ArthurZucker 4d550ae
fixup
ArthurZucker d9d8aa6
typo in the ocnfig
ArthurZucker 580e2f1
make the last 3 tests pass
ArthurZucker d2331f2
fix auto
ArthurZucker 44f1f30
nits
ArthurZucker 19c2af3
WIP
patrickvonplaten 0c5eb8f
Merge branch 'main' of github.com:huggingface/transformers into add_m…
ArthurZucker 7481a4a
Merge branch 'add_ministral_3' of https://github.com/patrickvonplaten…
patrickvonplaten 668de82
Merge branch 'add_ministral_3' of github.com:patrickvonplaten/transfo…
ArthurZucker 2cd4f15
WIP
patrickvonplaten 5cb33cf
Merge branch 'add_ministral_3' of https://github.com/patrickvonplaten…
patrickvonplaten 128d37c
WIP
patrickvonplaten 0640a36
per tensor
MekkCyber 4048042
WIP
patrickvonplaten 0154cd0
Merge branch 'add_ministral_3' of https://github.com/patrickvonplaten…
patrickvonplaten 67b1619
WIP
patrickvonplaten 142f794
WIP
patrickvonplaten 70f89d0
style
ArthurZucker de7888c
Merge branch 'add_ministral_3' of github.com:patrickvonplaten/transfo…
ArthurZucker 3ee6f61
Merge branch 'main' of github.com:huggingface/transformers into add_m…
ArthurZucker 547ac70
fixup
ArthurZucker b212ea0
WIP
patrickvonplaten b020d3b
WIP
patrickvonplaten 5b813a6
WIP
patrickvonplaten 2e4e5ae
WIP
patrickvonplaten 4aad125
hack for now
MekkCyber 2b41984
add todo
MekkCyber c1528a4
fixup
ArthurZucker 730d489
WIP
patrickvonplaten f46a88a
WIP
patrickvonplaten 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,114 @@ | ||
| <!--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. | ||
|
|
||
| --> | ||
|
|
||
|
|
||
| # Ministral3 | ||
|
|
||
| ## Overview | ||
|
|
||
| A balanced model in the Ministral 3 family, Ministral 3 8B is a powerful, efficient tiny language model with vision capabilities. | ||
|
|
||
| This model is the instruct post-trained version, fine-tuned for instruction tasks, making it ideal for chat and instruction based use cases. | ||
|
|
||
| The Ministral 3 family is designed for edge deployment, capable of running on a wide range of hardware. | ||
|
|
||
| Key features: | ||
| - Vision: Enables the model to analyze images and provide insights based on visual content, in addition to text. | ||
| - Multilingual: Supports dozens of languages, including English, French, Spanish, German, Italian, Portuguese, Dutch, Chinese, Japanese, Korean, Arabic. | ||
| - System Prompt: Maintains strong adherence and support for system prompts. | ||
| - Agentic: Offers best-in-class agentic capabilities with native function calling and JSON outputting. | ||
| - Edge-Optimized: Delivers best-in-class performance at a small scale, deployable anywhere. | ||
| - Apache 2.0 License: Open-source license allowing usage and modification for both commercial and non-commercial purposes. | ||
| - Large Context Window: Supports a 256k context window. | ||
|
|
||
| ## Usage examples | ||
|
|
||
| ```py | ||
| import torch | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's verified that this example works |
||
| from transformers import Mistral3ForConditionalGeneration, MistralCommonBackend | ||
|
|
||
|
|
||
| model_id = "mistralai/Ministral-3-3B-Instruct-2512" | ||
|
|
||
| tokenizer = MistralCommonBackend.from_pretrained(model_id) | ||
| model = Mistral3ForConditionalGeneration.from_pretrained( | ||
| model_id, torch_dtype=torch.bfloat16, device_map="auto" | ||
| ) | ||
|
|
||
| image_url = "https://static.wikia.nocookie.net/essentialsdocs/images/7/70/Battle.png/revision/latest?cb=20220523172438" | ||
|
|
||
| messages = [ | ||
| { | ||
| "role": "user", | ||
| "content": [ | ||
| { | ||
| "type": "text", | ||
| "text": "What action do you think I should take in this situation? List all the possible actions and explain why you think they are good or bad.", | ||
| }, | ||
| {"type": "image_url", "image_url": {"url": image_url}}, | ||
| ], | ||
| }, | ||
| ] | ||
|
|
||
| tokenized = tokenizer.apply_chat_template(messages, return_tensors="pt", return_dict=True) | ||
|
|
||
| tokenized["input_ids"] = tokenized["input_ids"].to(device="cuda") | ||
| tokenized["pixel_values"] = tokenized["pixel_values"].to(dtype=torch.bfloat16, device="cuda") | ||
| image_sizes = [tokenized["pixel_values"].shape[-2:]] | ||
|
|
||
| output = model.generate( | ||
| **tokenized, | ||
| image_sizes=image_sizes, | ||
| max_new_tokens=512, | ||
| )[0] | ||
|
|
||
| decoded_output = tokenizer.decode(output[len(tokenized["input_ids"][0]):]) | ||
| print(decoded_output) | ||
| ``` | ||
|
|
||
|
|
||
| ## Ministral3Config | ||
|
|
||
| [[autodoc]] Ministral3Config | ||
|
|
||
| ## Ministral3PreTrainedModel | ||
|
|
||
| [[autodoc]] Ministral3PreTrainedModel | ||
| - forward | ||
|
|
||
| ## Ministral3Model | ||
|
|
||
| [[autodoc]] Ministral3Model | ||
| - forward | ||
|
|
||
| ## Ministral3ForCausalLM | ||
|
|
||
| [[autodoc]] Ministral3ForCausalLM | ||
|
|
||
| ## Ministral3ForSequenceClassification | ||
|
|
||
| [[autodoc]] Ministral3ForSequenceClassification | ||
|
|
||
| ## Ministral3ForTokenClassification | ||
|
|
||
| [[autodoc]] Ministral3ForTokenClassification | ||
|
|
||
| ## Ministral3ForQuestionAnswering | ||
|
|
||
| [[autodoc]] Ministral3ForQuestionAnswering | ||
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
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,27 @@ | ||
| # Copyright 2025 Mistral AI and The HuggingFace Inc. 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_ministral3 import * | ||
| from .modeling_ministral3 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.
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.
Based.