- Notifications
You must be signed in to change notification settings - Fork 3.1k
Add new mistral #7425
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 new mistral #7425
Changes from all commits
Commits
Show all changes
27 commits Select commit Hold shift + click to select a range
a57e222 mistral model init commit
wtmlon e250362 code save
wtmlon 6029e66 add dump code
wtmlon b1c3cf8 mistral support lora,prefix,multi-gpu
wtmlon 251552f bug fix
wtmlon 5c1db6f add flash attention
wtmlon a5d3603 mistral sliding windows attention (attention_mask version)
wtmlon ab191c5 Merge branch 'develop' of https://github.com/PaddlePaddle/PaddleNLP i…
wtmlon c97d018 llm json fix
wtmlon 8160bbb bug fix
wtmlon 4baa81b ci code save
wtmlon 436567c mistral ci, attention mask
wtmlon c4e66e1 remove redundant comment
wtmlon e6768a6 remove print
wtmlon b6024b9 empty commit
wtmlon 8d3a702 update
wtmlon fafbb5b add init py
wtmlon 9e267e6 Merge branch 'develop' of https://github.com/PaddlePaddle/PaddleNLP i…
wtmlon f02a644 bugfix
wtmlon 6d74157 remove swa strategy
wtmlon 111f186 Merge branch 'develop' of https://github.com/PaddlePaddle/PaddleNLP i…
wtmlon c52f203 update
wtmlon 5e31287 lora support
wtmlon 4705a60 update
wtmlon 81a388c add tp cross entropy
wtmlon 7a6d780 support zero padding
wtmlon cdbd0eb update README.md
wtmlon 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,20 @@ | ||
| # Mistral | ||
| | ||
| ## 1. 模型介绍 | ||
| | ||
| **支持模型权重:** | ||
| | ||
| | Model | | ||
| |--------------------------------------| | ||
| | mistralai/Mistral-7B-Instruct-v0.3 | | ||
| | mistralai/Mistral-7B-v0.1 | | ||
| | ||
| | ||
| | ||
| 使用方法: | ||
| | ||
| ```python | ||
| from paddlenlp.transformers import AutoModelForCausalLM, AutoTokenizer | ||
| model = AutoModelForCausalLM.from_pretrained("mistralai/Mistral-7B-Instruct-v0.3") | ||
| tokenizer = AutoTokenizer.from_pretrained("mistralai/Mistral-7B-Instruct-v0.3") | ||
| ``` |
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,38 @@ | ||
| { | ||
| "model_name_or_path": "mistralai/Mistral-7B-Instruct-v0.3", | ||
| "train_dataset_path": "./dpo_data/train.jsonl", | ||
| "dev_dataset_path": "./dpo_data/train.jsonl", | ||
| "output_dir": "./checkpoints/dpo_ckpts", | ||
| "per_device_train_batch_size": 1, | ||
| "gradient_accumulation_steps": 8, | ||
| "per_device_eval_batch_size": 1, | ||
| "num_train_epochs": 1, | ||
| "max_steps": 100, | ||
| "learning_rate": 1e-06, | ||
| "warmup_steps": 10, | ||
| "logging_steps": 1, | ||
| "evaluation_strategy": "steps", | ||
| "save_strategy": "steps", | ||
| "eval_steps": 100, | ||
| "save_steps": 500, | ||
| "max_seq_len": 4096, | ||
| "max_prompt_len": 2048, | ||
| "bf16": true, | ||
| "fp16_opt_level": "O2", | ||
| "do_train": true, | ||
| "do_eval": true, | ||
| "disable_tqdm": true, | ||
| "load_best_model_at_end": true, | ||
| "tensor_parallel_degree": 8, | ||
| "sharding_parallel_degree": 1, | ||
| "sharding": "stage1", | ||
| "use_flash_attention": true, | ||
| "recompute": false, | ||
| "recompute_granularity": "full", | ||
| "dpo_beta": 0.1, | ||
| "benchmark": false, | ||
| "dpo_loss_type": "sigmoid", | ||
| "dpo_label_smoothing": 0.0, | ||
| "unified_checkpoint": true, | ||
| "autotuner_benchmark":false | ||
| } |
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,32 @@ | ||
| { | ||
| "model_name_or_path": "mistralai/Mistral-7B-Instruct-v0.3", | ||
| "dataset_name_or_path": "./data", | ||
| "output_dir": "./checkpoints/mistral_lora_ckpts", | ||
| "per_device_train_batch_size": 4, | ||
| "gradient_accumulation_steps": 4, | ||
| "per_device_eval_batch_size": 8, | ||
| "eval_accumulation_steps":16, | ||
| "num_train_epochs": 3, | ||
| "learning_rate": 3e-04, | ||
| "warmup_steps": 30, | ||
| "logging_steps": 1, | ||
| "evaluation_strategy": "epoch", | ||
| "save_strategy": "epoch", | ||
| "src_length": 1024, | ||
| "max_length": 2048, | ||
| "bf16": true, | ||
| "fp16_opt_level": "O2", | ||
| "do_train": true, | ||
| "do_eval": true, | ||
| "disable_tqdm": true, | ||
| "recompute": true, | ||
| "load_best_model_at_end": true, | ||
| "eval_with_do_generation": false, | ||
| "metric_for_best_model": "accuracy", | ||
| "save_total_limit": 1, | ||
| "tensor_parallel_degree": 1, | ||
| "pipeline_parallel_degree": 1, | ||
| "use_flash_attention": true, | ||
| "zero_padding": true, | ||
| "lora": true | ||
| } |
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,30 @@ | ||
| { | ||
| "model_name_or_path": "mistralai/Mistral-7B-Instruct-v0.3", | ||
| "dataset_name_or_path": "./data", | ||
| "output_dir": "./checkpoints/mistral_pt_ckpts", | ||
| "per_device_train_batch_size": 4, | ||
| "gradient_accumulation_steps": 4, | ||
| "per_device_eval_batch_size": 8, | ||
| "eval_accumulation_steps":16, | ||
| "num_train_epochs": 3, | ||
| "learning_rate": 3e-02, | ||
| "warmup_steps": 30, | ||
| "logging_steps": 1, | ||
| "evaluation_strategy": "epoch", | ||
| "save_strategy": "epoch", | ||
| "src_length": 1024, | ||
| "max_length": 2048, | ||
| "bf16": true, | ||
| "fp16_opt_level": "O2", | ||
| "do_train": true, | ||
| "do_eval": true, | ||
| "disable_tqdm": true, | ||
| "load_best_model_at_end": true, | ||
| "eval_with_do_generation": false, | ||
| "metric_for_best_model": "accuracy", | ||
| "recompute": false, | ||
| "save_total_limit": 1, | ||
| "tensor_parallel_degree": 1, | ||
| "pipeline_parallel_degree": 1, | ||
| "prefix_tuning": true | ||
| } |
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,30 @@ | ||
| { | ||
| "model_name_or_path": "mistralai/Mistral-7B-Instruct-v0.3", | ||
| "dataset_name_or_path": "./data", | ||
| "output_dir": "./checkpoints/mistral_sft_ckpts", | ||
| "per_device_train_batch_size": 4, | ||
| "gradient_accumulation_steps": 4, | ||
| "per_device_eval_batch_size": 8, | ||
| "eval_accumulation_steps":16, | ||
| "num_train_epochs": 3, | ||
| "learning_rate": 3e-05, | ||
| "warmup_steps": 30, | ||
| "logging_steps": 1, | ||
| "evaluation_strategy": "epoch", | ||
| "save_strategy": "epoch", | ||
| "src_length": 1024, | ||
| "max_length": 2048, | ||
| "bf16": true, | ||
| "fp16_opt_level": "O2", | ||
| "do_train": true, | ||
| "do_eval": true, | ||
| "disable_tqdm": true, | ||
| "load_best_model_at_end": true, | ||
| "eval_with_do_generation": false, | ||
| "metric_for_best_model": "accuracy", | ||
| "recompute": true, | ||
| "save_total_limit": 1, | ||
| "zero_padding": true, | ||
| "tensor_parallel_degree": 8, | ||
| "pipeline_parallel_degree": 1 | ||
| } |
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 |
|---|---|---|
| | @@ -50,6 +50,7 @@ def get_convert_example(model): | |
| "opt", | ||
| "qwen", | ||
| "mixtral", | ||
| "mistral", | ||
| "gemma", | ||
| "qwen2", | ||
| "qwen2_moe", | ||
| | ||
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,15 @@ | ||
| # Copyright (c) 2023 PaddlePaddle Authors. 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 .configuration import MistralConfig | ||
| from .modeling import MistralForCausalLM | ||
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,69 @@ | ||
| # Copyright (c) 2023 PaddlePaddle Authors. 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. | ||
| """ Mistral model configuration""" | ||
| | ||
| from ..configuration_utils import PretrainedConfig | ||
| | ||
| | ||
| class MistralConfig(PretrainedConfig): | ||
| model_type = "mistral" | ||
| keys_to_ignore_at_inference = ["past_key_values"] | ||
| | ||
| def __init__( | ||
| self, | ||
| vocab_size=32000, | ||
| hidden_size=4096, | ||
| intermediate_size=14336, | ||
| num_hidden_layers=32, | ||
| num_attention_heads=32, | ||
| num_key_value_heads=8, | ||
| hidden_act="silu", | ||
| max_position_embeddings=4096 * 32, | ||
| initializer_range=0.02, | ||
| rms_norm_eps=1e-6, | ||
| use_cache=True, | ||
| pad_token_id=None, | ||
| bos_token_id=1, | ||
| eos_token_id=2, | ||
| tie_word_embeddings=False, | ||
| rope_theta=10000.0, | ||
| sliding_window=4096, | ||
| **kwargs, | ||
| ): | ||
| self.vocab_size = vocab_size | ||
| self.max_position_embeddings = max_position_embeddings | ||
| self.hidden_size = hidden_size | ||
| self.intermediate_size = intermediate_size | ||
| self.num_hidden_layers = num_hidden_layers | ||
| self.num_attention_heads = num_attention_heads | ||
| self.sliding_window = sliding_window | ||
| | ||
| # for backward compatibility | ||
| if num_key_value_heads is None: | ||
| num_key_value_heads = num_attention_heads | ||
| | ||
| self.num_key_value_heads = num_key_value_heads | ||
| self.hidden_act = hidden_act | ||
| self.initializer_range = initializer_range | ||
| self.rms_norm_eps = rms_norm_eps | ||
| self.use_cache = use_cache | ||
| self.rope_theta = rope_theta | ||
| | ||
| super().__init__( | ||
| pad_token_id=pad_token_id, | ||
| bos_token_id=bos_token_id, | ||
| eos_token_id=eos_token_id, | ||
| tie_word_embeddings=tie_word_embeddings, | ||
| **kwargs, | ||
| ) |
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.
mistral为什么没有tokenizer文件
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.
官方的 mistral 直接用的 LlamaTokenizer:https://huggingface.co/mistralai/Mistral-7B-v0.3/blob/b67d6a03ca097c5122fa65904fce0413500bf8c8/tokenizer_config.json#L6183