-
Notifications
You must be signed in to change notification settings - Fork 14
local eval add mindformers model #110
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?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,33 @@ | ||||||
| from ais_bench.benchmark.models.local_models.mindformers_model import MindFormerModel | ||||||
|
|
||||||
| models = [ | ||||||
| dict( | ||||||
| attr="local", # local or service | ||||||
| type=MindFormerModel, # transformers < 4.33.0 用这个,优先AutoModelForCausalLM.from_pretrained加载模型,失败则用AutoModel.from_pretrained加载 | ||||||
| abbr='mindformer-model', | ||||||
| path='THUDM/chatglm-6b', # path to model dir, current value is just a example | ||||||
| checkpoint = 'THUDM/your_checkpoint', # path to checkpoint file, current value is just a example | ||||||
| yaml_cfg_file = 'THUDM/your.yaml', | ||||||
| tokenizer_path='THUDM/chatglm-6b', # path to tokenizer dir, current value is just a example | ||||||
| model_kwargs=dict( # 模型参数参考 huggingface.co/docs/transformers/v4.50.0/en/model_doc/auto#transformers.AutoModel.from_pretrained | ||||||
| device_map='npu', | ||||||
| ), | ||||||
| tokenizer_kwargs=dict( # tokenizer参数参考 huggingface.co/docs/transformers/v4.50.0/en/internal/tokenization_utils#transformers.PreTrainedTokenizerBase | ||||||
| padding_side='right', | ||||||
| ), | ||||||
| generation_kwargs = dict( # 后处理参数参考huggingface.co/docs/transformers/main_classes/test_generation | ||||||
| temperature = 0.5, | ||||||
| top_k = 10, | ||||||
| top_p = 0.95, | ||||||
| do_sample = True, | ||||||
| seed = None, | ||||||
| repetition_penalty = 1.03, | ||||||
| ), | ||||||
| run_cfg = dict(num_gpus=1, num_procs=1), # 多卡/多机多卡 参数,使用torchrun拉起任务 | ||||||
muqing-li marked this conversation as resolved.
Show resolved
Hide resolved
muqing-li marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
| run_cfg = dict(num_gpus=1, num_procs=1), # 多卡/多机多卡 参数,使用torchrun拉起任务 | |
| run_cfg = dict(num_gpus=1, num_procs=1), # 多卡/多机多卡 参数,使用 msrun 拉起任务 |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -35,6 +35,7 @@ class BaseModel: | |
| """ | ||
|
|
||
| is_api: bool = False | ||
| launcher: str = "torchrun" | ||
|
|
||
| def __init__(self, | ||
| path: str, | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,316 @@ | ||||||||||||||||||||||||||||||||||
| import os, sys | ||||||||||||||||||||||||||||||||||
muqing-li marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||||||||||||||||||||||
| from typing import Dict, List, Optional, Union | ||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||
| from typing import Dict, List, Optional, Union | |
| from typing import Dict, List, Optional |
muqing-li marked this conversation as resolved.
Show resolved
Hide resolved
muqing-li marked this conversation as resolved.
Show resolved
Hide resolved
muqing-li marked this conversation as resolved.
Show resolved
Hide resolved
Copilot
AI
Feb 11, 2026
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.
os, sys, and torch are imported but never used in this module, which adds noise and can introduce unnecessary dependency constraints. Please remove unused imports to keep the wrapper minimal.
| import os, sys | |
| from typing import Dict, List, Optional, Union | |
| import numpy as np | |
| import torch | |
| from typing import Dict, List, Optional, Union | |
| import numpy as np |
Copilot
AI
Feb 11, 2026
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.
APITemplateParser is imported but not used. If MindFormerModel should use a template parser, wire it up explicitly; otherwise remove the import to avoid confusion.
| from ais_bench.benchmark.models import APITemplateParser |
muqing-li marked this conversation as resolved.
Show resolved
Hide resolved
muqing-li marked this conversation as resolved.
Show resolved
Hide resolved
muqing-li marked this conversation as resolved.
Show resolved
Hide resolved
muqing-li marked this conversation as resolved.
Show resolved
Hide resolved
muqing-li marked this conversation as resolved.
Show resolved
Hide resolved
muqing-li marked this conversation as resolved.
Show resolved
Hide resolved
muqing-li marked this conversation as resolved.
Show resolved
Hide resolved
muqing-li marked this conversation as resolved.
Show resolved
Hide resolved
Copilot
AI
Feb 11, 2026
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 assert len(messages) == 1 for input validation is fragile because assertions can be disabled with Python optimizations, and it produces an unhelpful failure for users. Please raise a regular exception (e.g., ValueError/ParameterValueError) with a clear message when mode == 'mid' is used with batch inputs.
| assert len(messages) == 1 | |
| tokens = self.tokenizer(messages, padding=False, truncation=False, return_tensors='np') | |
| input_ids = tokens['input_ids'] | |
| if input_ids.shape[-1] > self.max_seq_len: | |
| input_ids = np.concatenate([input_ids[:, : self.max_seq_len // 2], input_ids[:, - self.max_seq_len // 2:]], axis=-1) | |
| if len(messages) != 1: | |
| raise ValueError( | |
| f"mode 'mid' does not support batch inputs: expected 1 message, got {len(messages)}." | |
| ) | |
| tokens = self.tokenizer(messages, padding=False, truncation=False, return_tensors='np') | |
| input_ids = tokens['input_ids'] | |
| if input_ids.shape[-1] > self.max_seq_len: | |
| input_ids = np.concatenate( | |
| [input_ids[:, : self.max_seq_len // 2], input_ids[:, - self.max_seq_len // 2:]], | |
| axis=-1, | |
| ) |
muqing-li marked this conversation as resolved.
Show resolved
Hide resolved
Copilot
AI
Feb 11, 2026
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 error message says the output dict is missing 'sequence', but the code actually looks for the 'sequences' key. This mismatch will mislead debugging; update the message (or the key) so they are consistent.
| raise ValueError("Model output dictionary is missing 'sequence' key.") | |
| raise ValueError("Model output dictionary is missing 'sequences' key.") |
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 inline comment for
type=MindFormerModelmentions Transformers (<4.33.0) and HuggingFace loading behavior, which is unrelated to MindFormers and can confuse users. Please update the comment to describe MindFormers-specific behavior/requirements (e.g., that it usesyaml_cfg_file+ MindFormers checkpoint loading).