From d513633bf24c60114b4ec3248b656a281b418166 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=A0=E7=83=A8=E6=A7=9F?= Date: Tue, 5 Aug 2025 19:16:56 +0800 Subject: [PATCH] =?UTF-8?q?[=E5=AE=89=E5=85=A8=E6=95=B4=E6=94=B9]trust=5Fr?= =?UTF-8?q?emote=5Fcode=E9=BB=98=E8=AE=A4=E5=80=BC=E4=B8=BAFalse=EF=BC=8C?= =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E7=9B=B8=E5=85=B3=E5=AE=89=E5=85=A8=E5=A3=B0?= =?UTF-8?q?=E6=98=8E?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 2 +- docs/zh/api_reference/apis/cli_api.md | 10 ++++++---- docs/zh/basic_tutorial/cli.md | 7 ++++--- .../distributed_launch/distributed_launch_ms.md | 4 ++-- docs/zh/basic_tutorial/fused_ops.md | 2 +- docs/zh/basic_tutorial/load_dataset.md | 4 ++-- docs/zh/basic_tutorial/pipeline.md | 14 ++++++++------ docs/zh/best_practice/baichuan_m1.md | 4 ++-- docs/zh/best_practice/deepseek_r1.md | 1 + docs/zh/best_practice/opencompass.md | 1 + docs/zh/task/nlp/text_generation.md | 2 +- examples/features/chat/chat_demo.yaml | 1 - examples/features/deploy/deploy_demo_sdk.py | 3 +-- examples/features/eval/eval_demo.yaml | 1 - examples/features/train/train_rm_lora.yaml | 2 -- examples/glm4/train_sft_lora_glm_4_9b_chat.yaml | 1 - .../internlm2/train_sft_lora_internlm2_7b.yaml | 1 - .../train_sft_full_internlm3_8b_chat.yaml | 1 - .../train_sft_lora_internlm3_8b_chat.yaml | 1 - .../train_sft_qlora_internlm3_8b_chat.yaml | 1 - src/openmind/flow/eval/lmeval.py | 4 ---- 21 files changed, 30 insertions(+), 37 deletions(-) diff --git a/README.md b/README.md index 71b7ddc..bd2b39c 100644 --- a/README.md +++ b/README.md @@ -231,7 +231,7 @@ pipe = pipeline( model="Baichuan/Baichuan2_7b_chat_pt", framework="pt", backend="transformers", - trust_remote_code=True, + trust_remote_code=True, # 为保证代码安全,配置trust_remote_code默认为False,用户需要设置为True,并且确保自己下载的模型和数据的安全性 device="npu:0", ) output = pipe("Give three tips for staying healthy.") diff --git a/docs/zh/api_reference/apis/cli_api.md b/docs/zh/api_reference/apis/cli_api.md index 01149d5..00b47bc 100644 --- a/docs/zh/api_reference/apis/cli_api.md +++ b/docs/zh/api_reference/apis/cli_api.md @@ -387,19 +387,21 @@ Push to your_organization/your_repo finished - ai2_arc ``` -****接口调用示例**** +**接口调用示例** + +为保证代码安全,配置trust_remote_code默认为False,用户需要设置为True,并且确保自己下载的模型和数据的安全性。 - 使用`ai2_arc`数据集评估`Baichuan/Baichuan2_7b_chat_pt`精度。 ```bash - openmind-cli eval --model_name_or_path Baichuan/Baichuan2_7b_chat_pt --device 0 --tasks arithmetic --batch_size 64 + openmind-cli eval --model_name_or_path Baichuan/Baichuan2_7b_chat_pt --device 0 --tasks arithmetic --batch_size 64 --trust_remote_code True ``` - 使用`ai2_arc`数据集,单机多卡评估`Baichuan/Baichuan2_7b_chat_pt`精度。 ```bash export ASCEND_RT_VISIBLE_DEVICES=0,1,2,3 - openmind-cli eval --model_name_or_path Baichuan/Baichuan2_7b_chat_pt --tasks ai2_arc --batch_size 64 + openmind-cli eval --model_name_or_path Baichuan/Baichuan2_7b_chat_pt --tasks ai2_arc --batch_size 64 --trust_remote_code True ``` - 打印当前支持的任务(评估集)。 @@ -429,7 +431,7 @@ Push to your_organization/your_repo finished - **--backend** (`str`,*可选*,默认为`lmeval`):指定评估使用的后端。 - **--device**(`str`/`int`, *可选*,默认为0):单卡评估时使用的加速卡,可选值为"cpu"或者0/1/2../7。在单机多卡评估场景下,不需要指定此参数,通过环境变量`ASCEND_RT_VISIBLE_DEVICES`控制使用的npu卡数。`ASCEND_RT_VISIBLE_DEVICES`用法请参考[环境变量说明](https://www.hiascend.com/document/detail/zh/canncommercial/800/apiref/envvar/envref_07_0028.html)。 - **--limit**(`int`,*可选*,默认为`None`):指定每个任务使用的样本数,此参数只用于限定样本数减少评估时间,用于验证功能是否正常,不支持评估模型能力。 -- **--trust_remote_code**(`str`,*可选*,默认为`True`):指定是否允许执行openMind Hub上定义的模型等代码。 +- **--trust_remote_code**(`str`,*可选*,默认为`False`):指定是否允许执行openMind Hub上定义的模型等代码。 - **--batch_size**(`str`,*可选*,默认为`1`):指定评估模型时的`batch_size`。 - **--fp16**(`bool`,*可选*,默认为`False`):模型加载是否使用fp16格式。 - **--bf16**(`bool`,*可选*,默认为`False`):模型加载是否使用bf16格式。 diff --git a/docs/zh/basic_tutorial/cli.md b/docs/zh/basic_tutorial/cli.md index dc07e2e..4df53c1 100644 --- a/docs/zh/basic_tutorial/cli.md +++ b/docs/zh/basic_tutorial/cli.md @@ -302,19 +302,19 @@ run_chat( - ai2_arc:这个任务是一个需要模型进行深入推理和解决问题的任务,它通常包含科学问题和需要复杂推理的问题。当你需要评估模型在解决需要深入推理和背景知识的问题上的能力时,可以使用这个任务。 -接口调用示例如下。 +接口调用示例如下(为保证代码安全,配置trust_remote_code默认为False,用户需要设置为True,并且确保自己下载的模型和数据的安全性)。 - 使用`ai2_arc`数据集评估`Baichuan/Baichuan2_7b_chat_pt`精度。 ```bash - openmind-cli eval --model_name_or_path Baichuan/Baichuan2_7b_chat_pt --device 0 --tasks arithmetic --batch_size 64 + openmind-cli eval --model_name_or_path Baichuan/Baichuan2_7b_chat_pt --device 0 --tasks arithmetic --batch_size 64 --trust_remote_code True ``` - 使用`ai2_arc`数据集,单机多卡评估`Baichuan/Baichuan2_7b_chat_pt`精度。 ```bash export ASCEND_RT_VISIBLE_DEVICES=0,1,2,3 - openmind-cli eval --model_name_or_path Baichuan/Baichuan2_7b_chat_pt --tasks ai2_arc --batch_size 64 + openmind-cli eval --model_name_or_path Baichuan/Baichuan2_7b_chat_pt --tasks ai2_arc --batch_size 64 --trust_remote_code True ``` - 显示当前支持的任务(评估集) @@ -352,6 +352,7 @@ run_eval( tasks="gsm8k", batch_size=64, limit=1, + trust_remote_code=True, # 为保证代码安全,配置trust_remote_code默认为False,用户需要设置为True,并且确保自己下载的模型和数据的安全性 ) ``` diff --git a/docs/zh/basic_tutorial/distributed_launch/distributed_launch_ms.md b/docs/zh/basic_tutorial/distributed_launch/distributed_launch_ms.md index 243f693..aa878fe 100644 --- a/docs/zh/basic_tutorial/distributed_launch/distributed_launch_ms.md +++ b/docs/zh/basic_tutorial/distributed_launch/distributed_launch_ms.md @@ -18,7 +18,7 @@ MindSpore支持**数据并行**,**半自动并行**和**全自动并行**三 - **半自动并行**:在半自动并行模式下,并行逻辑和算法逻辑解耦,用户只需要按单卡串行的方式写算法代码,并配置并行策略来实现自动并行切分;用户无需感知模型切片的调度及集群拓扑。 - **全自动并行**:用户只需要写单卡串行算法,通过搜索算法来自动生成较优的切分策略。 -MindSpore分布式并行介绍请参考:[MindSpore分布式并行原生](https://www.mindspore.cn/docs/zh-CN/master/design/distributed_training_design.html) +MindSpore分布式并行介绍请参考:[MindSpore分布式并行原生](https://www.mindspore.cn/docs/zh-CN/r2.3.1/design/distributed_training_design.html) MindSpore分布式并行教程请参考:[MindSpore分布式并行总览](https://www.mindspore.cn/tutorials/experts/zh-CN/r2.3.1/parallel/overview.html) @@ -129,7 +129,7 @@ def main(): # 传入并行配置,初始化模型 model = AutoModelForCausalLM.from_pretrained("MindSpore-Lab/your_awesome_model", - trust_remote_code=True, + trust_remote_code=True, # 为保证代码安全,配置trust_remote_code默认为False,用户需要设置为True,并且确保自己下载的模型和数据的安全性 parallel_config=get_parallel_config(training_args)) trainer = Trainer(args=training_args, diff --git a/docs/zh/basic_tutorial/fused_ops.md b/docs/zh/basic_tutorial/fused_ops.md index 6c348d3..e7f9bf2 100644 --- a/docs/zh/basic_tutorial/fused_ops.md +++ b/docs/zh/basic_tutorial/fused_ops.md @@ -124,7 +124,7 @@ pipe = pipeline( model="AI-Research/Qwen2.5-7B", framework="pt", backend="transformers", - trust_remote_code=True, + trust_remote_code=True, # 为保证代码安全,配置默认为False,用户需要设置为True,并且确保自己下载的模型和数据的安全性 device="npu:0", ) output = pipe("Give three tips for staying healthy.") diff --git a/docs/zh/basic_tutorial/load_dataset.md b/docs/zh/basic_tutorial/load_dataset.md index 0eb1d8c..e1ab156 100644 --- a/docs/zh/basic_tutorial/load_dataset.md +++ b/docs/zh/basic_tutorial/load_dataset.md @@ -203,7 +203,7 @@ def _split_generators(self, dl_manager): ] ``` -从相关代码中可见,涉及下载对应文件时,URL指定了第三方站点。可尝试以下用例进行下载,请注意使用python脚本下载数据集文件时需要添加参数`trust_remote_code=True`。 +从相关代码中可见,涉及下载对应文件时,URL指定了第三方站点。可尝试以下用例进行下载,请注意使用python脚本下载数据集文件时需要添加参数`trust_remote_code=True`,用户需确保自己下载的模型和数据的安全性。 ```python data = OmDataset.load_dataset("modeltesting/test_py_github", trust_remote_code=True) @@ -446,7 +446,7 @@ print(data) ### 配置`trust_remote_code`参数 -如果下载python文件进行数据集下载时,脚本中涉及复杂的处理逻辑或远程自定义代码,需要设置该参数。如果python脚本仅仅加载了对应的json等文件时(不进一步处理),可以忽略该参数。 +如果下载python文件进行数据集下载时,脚本中涉及复杂的处理逻辑或远程自定义代码,需要设置该参数,并且确保自己下载的模型和数据的安全性。如果python脚本仅仅加载了对应的json等文件时(不进一步处理),可以忽略该参数。 ```python OmDataset.load_dataset(path="repo_name/dataset_name", trust_remote_code=True) diff --git a/docs/zh/basic_tutorial/pipeline.md b/docs/zh/basic_tutorial/pipeline.md index 464a3ee..831c0a5 100644 --- a/docs/zh/basic_tutorial/pipeline.md +++ b/docs/zh/basic_tutorial/pipeline.md @@ -77,7 +77,7 @@ openMind Library `pipeline`方法支持PyTorch和MindSpore两种框架。此外 model="Baichuan/Baichuan2_7b_chat_pt", framework="pt", backend="transformers", - trust_remote_code=True, + trust_remote_code=True, # 为保证代码安全,配置trust_remote_code默认为False,用户需要设置为True,并且确保自己下载的模型和数据的安全性 device="npu:0", ) output = pipe("Give three tips for staying healthy.") @@ -118,11 +118,13 @@ openMind Library `pipeline`方法支持PyTorch和MindSpore两种框架。此外 ms.set_context(mode=0, device_id=0, jit_config={"jit_level": "O0", "infer_boost": "on"}) - pipe = pipeline(task="text-generation", - model='MindSpore-Lab/Qwen2_5-7B-Instruct', - framework='ms', - model_kwargs={"use_past": True}, - trust_remote_code=True) + pipe = pipeline( + task="text-generation", + model='MindSpore-Lab/Qwen2_5-7B-Instruct', + framework='ms', + model_kwargs={"use_past": True}, + trust_remote_code=True # 为保证代码安全,配置trust_remote_code默认为False,用户需要设置为True,并且确保自己下载的模型和数据的安全性 + ) outputs = pipe("Give me some advice on how to stay healthy.") print(outputs) ``` diff --git a/docs/zh/best_practice/baichuan_m1.md b/docs/zh/best_practice/baichuan_m1.md index 4cbda30..b4380d2 100644 --- a/docs/zh/best_practice/baichuan_m1.md +++ b/docs/zh/best_practice/baichuan_m1.md @@ -73,7 +73,7 @@ openMind提供了低代码配置化的方式启动训练流程,只需要编写 ```yaml model_name_or_path: /data/Baichuan_M1_14B_Instruct/ -trust_remote_code: True +trust_remote_code: True # 为保证代码安全,配置trust_remote_code默认为False,用户需要设置为True,并且确保自己下载的模型和数据的安全性 # method stage: sft @@ -130,7 +130,7 @@ ASCEND_RT_VISIBLE_DEVICES=0,1,2,3,4,5,6,7 openmind-cli train baichuan_m1_full_sa model_name_or_path: /data/Baichuan_M1_14B_Instruct adapter_models: saves/baichuan_m1_lora output_dir: target_path -trust_remote_code: True +trust_remote_code: True # 为保证代码安全,配置trust_remote_code默认为False,用户需要设置为True,并且确保自己下载的模型和数据的安全性 ``` 这里定义了原始的权重路径,微调的LoRA权重路径,合并后的目标保存路径 diff --git a/docs/zh/best_practice/deepseek_r1.md b/docs/zh/best_practice/deepseek_r1.md index 54f6b5e..b9ec79a 100644 --- a/docs/zh/best_practice/deepseek_r1.md +++ b/docs/zh/best_practice/deepseek_r1.md @@ -195,6 +195,7 @@ template: deepseek_r1 finetuning_type: lora output_dir: target_path trust_remote_code: True +# 为保证代码安全,配置trust_remote_code默认为False,用户需要设置为True,并且确保自己下载的模型和数据的安全性 ``` 这里定义了原始的权重路径,微调的LoRA权重路径,合并后的目标保存路径 diff --git a/docs/zh/best_practice/opencompass.md b/docs/zh/best_practice/opencompass.md index 770890e..2d7d67f 100644 --- a/docs/zh/best_practice/opencompass.md +++ b/docs/zh/best_practice/opencompass.md @@ -74,6 +74,7 @@ python run.py \ --min-out-len 16 \ --batch-size 32 \ --max-num-workers 4 +# 为保证代码安全,配置trust_remote_code默认为False,用户需要设置为True,并且确保自己下载的模型和数据的安全性 ``` - datasets中可以传入多个数据集,从而一次评估多个数据集。 diff --git a/docs/zh/task/nlp/text_generation.md b/docs/zh/task/nlp/text_generation.md index ac7a35d..f5c743e 100644 --- a/docs/zh/task/nlp/text_generation.md +++ b/docs/zh/task/nlp/text_generation.md @@ -185,7 +185,7 @@ build_context(training_args) ### 模型初始化 -在使用MindSpore框架时,您的任务会基于半自动并行模式进行训练,需要实例化模型并行配置,并将其作为入参传入`AutoModelForCausalLM`以初始化带并行配置的模型。 +在使用MindSpore框架时,您的任务会基于半自动并行模式进行训练,需要实例化模型并行配置,并将其作为入参传入`AutoModelForCausalLM`以初始化带并行配置的模型(为保证代码安全,配置trust_remote_code默认为False,用户需要设置为True,并且确保自己下载的模型和数据的安全性)。 ::: code-group diff --git a/examples/features/chat/chat_demo.yaml b/examples/features/chat/chat_demo.yaml index 2af0537..5e586d7 100644 --- a/examples/features/chat/chat_demo.yaml +++ b/examples/features/chat/chat_demo.yaml @@ -1,5 +1,4 @@ model_name_or_path: AI-Research/internlm2_5-7b-chat -trust_remote_code: True template: internlm2 bf16: True device: 0 \ No newline at end of file diff --git a/examples/features/deploy/deploy_demo_sdk.py b/examples/features/deploy/deploy_demo_sdk.py index 59a535e..21d0a4e 100644 --- a/examples/features/deploy/deploy_demo_sdk.py +++ b/examples/features/deploy/deploy_demo_sdk.py @@ -3,6 +3,5 @@ from openmind import run_deploy run_deploy( model_name_or_path="AI_Connect/Qwen2_0.5B", backend="lmdeploy", - device=2, - trust_remote_code=True + device=2 ) \ No newline at end of file diff --git a/examples/features/eval/eval_demo.yaml b/examples/features/eval/eval_demo.yaml index bcc3034..e45863d 100644 --- a/examples/features/eval/eval_demo.yaml +++ b/examples/features/eval/eval_demo.yaml @@ -3,5 +3,4 @@ model_name_or_path: AI_Connect/Qwen2_0.5B device: 0 tasks: gsm8k batch_size: 64 -trust_remote_code: True limit: 1 diff --git a/examples/features/train/train_rm_lora.yaml b/examples/features/train/train_rm_lora.yaml index 9c25e53..a501b07 100644 --- a/examples/features/train/train_rm_lora.yaml +++ b/examples/features/train/train_rm_lora.yaml @@ -9,8 +9,6 @@ template: qwen deepspeed: examples/deepspeed/ds_z2_config.json -trust_remote_code: True - # dataset dataset: rlhf-reward-datasets cutoff_len: 1024 diff --git a/examples/glm4/train_sft_lora_glm_4_9b_chat.yaml b/examples/glm4/train_sft_lora_glm_4_9b_chat.yaml index 20aaaf3..2654915 100644 --- a/examples/glm4/train_sft_lora_glm_4_9b_chat.yaml +++ b/examples/glm4/train_sft_lora_glm_4_9b_chat.yaml @@ -1,6 +1,5 @@ # model model_id: Glm-4-9b-chat -trust_remote_code: true # fusion operator: use_npu_fusion_attention: false diff --git a/examples/internlm2/train_sft_lora_internlm2_7b.yaml b/examples/internlm2/train_sft_lora_internlm2_7b.yaml index 1badeb6..5c6ac57 100644 --- a/examples/internlm2/train_sft_lora_internlm2_7b.yaml +++ b/examples/internlm2/train_sft_lora_internlm2_7b.yaml @@ -1,6 +1,5 @@ # model model_id: Internlm2-7B -trust_remote_code: true # method stage: sft diff --git a/examples/internlm3/train_sft_full_internlm3_8b_chat.yaml b/examples/internlm3/train_sft_full_internlm3_8b_chat.yaml index 0551ea8..db87a1a 100644 --- a/examples/internlm3/train_sft_full_internlm3_8b_chat.yaml +++ b/examples/internlm3/train_sft_full_internlm3_8b_chat.yaml @@ -1,6 +1,5 @@ # model model_id: Internlm3-8B-Chat -trust_remote_code: true # method stage: sft diff --git a/examples/internlm3/train_sft_lora_internlm3_8b_chat.yaml b/examples/internlm3/train_sft_lora_internlm3_8b_chat.yaml index 2e8bceb..dc67fff 100644 --- a/examples/internlm3/train_sft_lora_internlm3_8b_chat.yaml +++ b/examples/internlm3/train_sft_lora_internlm3_8b_chat.yaml @@ -1,6 +1,5 @@ # model model_id: Internlm3-8B-Chat -trust_remote_code: true # method stage: sft diff --git a/examples/internlm3/train_sft_qlora_internlm3_8b_chat.yaml b/examples/internlm3/train_sft_qlora_internlm3_8b_chat.yaml index 996b3b0..89bd454 100644 --- a/examples/internlm3/train_sft_qlora_internlm3_8b_chat.yaml +++ b/examples/internlm3/train_sft_qlora_internlm3_8b_chat.yaml @@ -1,6 +1,5 @@ # model model_id: Internlm3-8B-Chat -trust_remote_code: true load_in_4bit: True use_npu_fusion_attention: false use_fused_rms_norm: false diff --git a/src/openmind/flow/eval/lmeval.py b/src/openmind/flow/eval/lmeval.py index 25ddfd2..e31de6a 100644 --- a/src/openmind/flow/eval/lmeval.py +++ b/src/openmind/flow/eval/lmeval.py @@ -82,10 +82,6 @@ class LMEval: path = dataset_map[path] break - # Add trust_remote_code if not exists - if "trust_remote_code" not in kwargs: - kwargs["trust_remote_code"] = True - return load_datasets_func(path, *args, **kwargs) return wrapper -- Gitee