-
Notifications
You must be signed in to change notification settings - Fork 2.6k
[None][feat] Support Mistral Large3 LLM part #9820
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
Changes from all commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
77fcd5f
add mistral large 3 codes
byshiue e5bf6fd
fix bug of mistral checkpoint loader
byshiue ef30609
[WIP] add mistral large 3 model definition
byshiue 31cf365
[WIP] fix bugs of mistral large 3 ckpt loader
byshiue fedb33e
[WIP] fix bug of mistral large3 llm part
byshiue c7fd6a0
[WIP] update document
byshiue dcee6eb
[WIP] remove debug file
byshiue 793be03
[WIP] add checkpoint_format into eval.py
byshiue 32f26eb
[WIP] refine codes
byshiue c7f80a9
[WIP] add mistral large 3 into CI tests
byshiue f618f4d
[WIP] clean codes and refine config_loader of mistral
byshiue 135fb6d
[WIP] refine codes about CI and evaluation
byshiue 77f16a0
[WIP] fix few bugs
byshiue ef7aa71
[READY] fix code format
byshiue fcf15b7
[DOC] quick update for document
byshiue 7c0633f
[FIX] fix issues by bot comments
byshiue b36858a
[FIX] fix bug of code format
byshiue 62fa048
[FIX] fix minor bugs
byshiue cd00eff
[FIX] minor changes based on comment
byshiue 4443c3a
[FIX] minor changes based on comment
byshiue b523e10
[FIX] adust CI settings
byshiue 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,53 @@ | ||
| # Mistral Large V3 | ||
|
|
||
| * Setup the model path | ||
|
|
||
| ```bash | ||
| export mistral_large_3_model_path=<mistral_large_3_model_path> | ||
| ``` | ||
|
|
||
| ## LLM-only run | ||
|
|
||
| * Run the Mistral Large V3 by `quickstart_advanced.py` | ||
|
|
||
| ```bash | ||
| mpirun -n 1 --allow-run-as-root --oversubscribe python3 examples/llm-api/quickstart_advanced.py \ | ||
| --model_dir ${mistral_large_3_model_path} \ | ||
| --tp_size 4 \ | ||
|
jdebache marked this conversation as resolved.
|
||
| --moe_ep_size 4 \ | ||
| --max_tokens 100 \ | ||
| --checkpoint_format mistral \ | ||
| --moe_backend TRTLLM | ||
| ``` | ||
|
|
||
| * Launch the trtllm-serve and send a request | ||
|
|
||
| ```bash | ||
| echo " | ||
| backend: pytorch | ||
| tensor_parallel_size: 4 | ||
| moe_expert_parallel_size: 4 | ||
| enable_attention_dp: false | ||
| kv_cache_config: | ||
| enable_block_reuse: true | ||
|
byshiue marked this conversation as resolved.
|
||
| checkpoint_format: mistral | ||
| " > serve.yml | ||
| mpirun -n 1 --allow-run-as-root --oversubscribe python3 -m tensorrt_llm.commands.serve serve \ | ||
| ${mistral_large_3_model_path} \ | ||
| --host localhost --port 8001 --backend pytorch \ | ||
| --extra_llm_api_options serve.yml \ | ||
| --tokenizer ${mistral_large_3_model_path} \ | ||
| 2>&1 | tee serve_debug.log & | ||
|
|
||
| curl http://localhost:8001/v1/completions \ | ||
| -H "Content-Type: application/json" \ | ||
| -d '{ | ||
| "model": "${mistral_large_3_model_path}", | ||
| "prompt": "The capital of France is", | ||
| "max_tokens": 16, | ||
| "top_k": 16 | ||
| }' | ||
|
|
||
| # The result would be like | ||
| {"id":"cmpl-7e342c1d722d4226a1bf3ed35d762c35","object":"text_completion","created":1764061351,"model":"${mistral_large_3_model_path}","choices":[{"index":0,"text":"The capital of France is **Paris**.\n\nParis is the largest city in France and","token_ids":null,"logprobs":null,"context_logits":null,"finish_reason":"length","stop_reason":null,"disaggregated_params":null,"avg_decoded_tokens_per_iter":1.0}],"usage":{"prompt_tokens":7,"total_tokens":23,"completion_tokens":16,"prompt_tokens_details":{"cached_tokens":1}},"prompt_token_ids":null} | ||
|
byshiue marked this conversation as resolved.
|
||
| ``` | ||
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
Empty file.
75 changes: 75 additions & 0 deletions
75
tensorrt_llm/_torch/models/checkpoints/mistral/checkpoint_loader.py
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,75 @@ | ||
| from tensorrt_llm._torch.models.checkpoints.base_config_loader import BaseConfigLoader | ||
|
byshiue marked this conversation as resolved.
|
||
| from tensorrt_llm._torch.models.checkpoints.base_weight_loader import BaseWeightLoader | ||
| from tensorrt_llm._torch.models.checkpoints.base_weight_mapper import BaseWeightMapper | ||
| from tensorrt_llm._torch.models.checkpoints.hf.checkpoint_loader import HfCheckpointLoader | ||
| from tensorrt_llm._torch.models.checkpoints.mistral.config_loader import MistralConfigLoader | ||
| from tensorrt_llm._torch.models.modeling_utils import register_checkpoint_loader | ||
|
|
||
|
|
||
| @register_checkpoint_loader("mistral") | ||
| class MistralCheckpointLoader(HfCheckpointLoader): | ||
| def __init__( | ||
| self, | ||
| *, | ||
| weight_loader: BaseWeightLoader | None = None, | ||
| weight_mapper: BaseWeightMapper | None = None, | ||
| config_loader: BaseConfigLoader | None = None, | ||
| ): | ||
| super().__init__( | ||
| weight_loader=weight_loader, weight_mapper=weight_mapper, config_loader=config_loader | ||
| ) | ||
| self._checkpoint_format = "mistral" | ||
| self.mm_module_mapping = { | ||
| "vision_encoder": "vision_tower", | ||
| "pre_mm_projector_norm": "multi_modal_projector.norm", | ||
| "vision_language_adapter": "multi_modal_projector", | ||
| "patch_merger": "multi_modal_projector.patch_merger", | ||
| } | ||
|
|
||
| def preprocess_weights(self, weights: dict) -> dict: | ||
| """ | ||
| Aggregate weights by module | ||
| """ | ||
| hf_weights = {} | ||
|
|
||
| for key, value in weights.items(): | ||
| modules = key.split(".") | ||
|
|
||
| if modules[0] not in self.mm_module_mapping.keys(): | ||
| hf_weights["language_model." + key] = value | ||
|
|
||
| else: | ||
| modules[0] = self.mm_module_mapping[modules[0]] | ||
| hf_weights[".".join(modules)] = value | ||
|
|
||
| return hf_weights | ||
|
|
||
| def inverse_nvfp4_global_scales(self, weights): | ||
|
byshiue marked this conversation as resolved.
|
||
| for key in weights.keys(): | ||
| if "global_scale" in key: | ||
| weights[key] = 1.0 / weights[key] | ||
|
|
||
| def load_weights(self, checkpoint_dir: str, **kwargs): | ||
| weights = super().weight_loader.load_weights(checkpoint_dir, **kwargs) | ||
| weights = self.preprocess_weights(weights) | ||
| # The definition of global_scale is different in Mistral, need to inverse the scale | ||
| self.inverse_nvfp4_global_scales(weights) | ||
| return weights | ||
|
|
||
| def get_default_config_loader(self) -> MistralConfigLoader: | ||
| return MistralConfigLoader() | ||
|
|
||
|
|
||
| @register_checkpoint_loader("mistral_large_3") | ||
| class MistralLarge3CheckpointLoader(MistralCheckpointLoader): | ||
| def __init__( | ||
| self, | ||
| *, | ||
| weight_loader: BaseWeightLoader | None = None, | ||
| weight_mapper: BaseWeightMapper | None = None, | ||
| config_loader: BaseConfigLoader | None = None, | ||
| ): | ||
| super().__init__( | ||
| weight_loader=weight_loader, weight_mapper=weight_mapper, config_loader=config_loader | ||
| ) | ||
| self._checkpoint_format = "mistral_large_3" | ||
Oops, something went wrong.
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.