问题一:win系统用 modelscope的训练训练的时候报错了 是有什么源码要修改吗?
win系统用 modelscope的训练训练的时候报错了 是有什么源码要修改吗? Producer process has been terminated before all shared CUDA tensors released. See Note [Sharing CUDA tensors]
参考回答:
报错信息 "Producer process has been terminated before all shared CUDA tensors released. See Note [Sharing CUDA tensors]" 通常和使用多进程时释放共享CUDA张量有关。这个问题在 Windows 系统上更常见。
你可以尝试下面的解决方法:
检查 PyTorch 和 CUDA 版本是否匹配。确保安装了与你的 CUDA 版本兼容的 PyTorch 版本。你可以查看 PyTorch 官方网站获取相关版本信息。
将以下代码片段添加到你的训练脚本的开头,设置仅使用单个进程来避免多进程共享 CUDA 张量导致的问题:
import torch torch.multiprocessing.set_start_method('spawn', force=True)
如果你使用了 DataLoader 加载数据,在创建 DataLoader 对象之前,将 num_workers 设置为 0,禁用多进程加载数据:
data_loader = DataLoader(dataset, num_workers=0, ...)
如果你是在 Jupyter Notebook 中执行训练过程,尝试在启动 Jupyter Notebook 时加入 --NotebookApp.iopub_data_rate_limit=1e10 参数,增加 Jupyter Notebook 的数据传输速率限制。 希望以上方法能够解决你的问题。如果问题仍然存在,请提供更多详细信息,以便我能够更准确地帮助你解决问题。
关于本问题的更多回答可点击原文查看:https://developer.aliyun.com/ask/512676?spm=a2c6h.14164896.0.0.4f7a1edfxgD65O
问题二:麻烦问下使用build_trainer进行训练的话,ModelScope如何设置每个epoch保存?
麻烦问下使用build_trainer进行训练的话,ModelScope如何设置每个epoch保存一个模型呢,我想保存训练过程中最优模型?
参考回答:
您可以查看文档:https://www.modelscope.cn/docs/Configuration%E8%AF%A6%E8%A7%A3#checkpoint
关于本问题的更多回答可点击原文查看:https://developer.aliyun.com/ask/520285?spm=a2c6h.14164896.0.0.55721edfBKaCYG
问题三:使用StructBERT FAQ问答 模型进行训练时报错,各位大佬进来看看,帮忙解决解决,十分感谢
问题描述
使用问答模型 damo/nlp_structbert_faq-question-answering_chinese-base 进行训练时,参照官方文档代码出现如下错误
** build_dataset error log: 'structbert is not in the custom_datasets registry group faq-question-answering. Please make sure the correct version of ModelScope library is used.'
官方地址
使用的数据集格式 如下
text | label | answer |
数据采集 | 1 | 数据采集 |
采集数据 | 1 | 数据采集 |
数据收集 | 1 | 数据采集 |
开始采集 | 1 | 数据采集 |
采集开始 | 1 | 数据采集 |
收集数据 | 1 | 数据采集 |
数据收集 | 1 | 数据采集 |
问题反馈 | 2 | 问题反馈 |
反馈问题 | 2 | 问题反馈 |
上报问题 | 2 | 问题反馈 |
问题上报 | 2 | 问题反馈 |
开始反馈 | 2 | 问题反馈 |
反馈开始 | 2 | 问题反馈 |
汇报工作 | 3 | 工作汇报 |
工作汇报 | 3 | 工作汇报 |
工作上报 | 3 | 工作汇报 |
上报工作 | 3 | 工作汇报 |
开始汇报 | 3 | 工作汇报 |
汇报开始 | 3 | 工作汇报 |
工作填报 | 4 | 工作填报 |
填报工作 | 4 | 工作填报 |
开始填报 | 4 | 工作填报 |
工作填报 | 4 | 工作填报 |
调试完整代码
import os from modelscope.metainfo import Trainers from modelscope.msdatasets import MsDataset from modelscope.pipelines import pipeline from modelscope.trainers import build_trainer from modelscope.utils.config import Config from modelscope.utils.hub import read_config train_dataset = MsDataset.load("./qa.csv", split='train').remap_columns({'text': 'text'}) print(train_dataset) eval_dataset = train_dataset cfg: Config = read_config("damo/nlp_structbert_faq-question-answering_chinese-base") cfg.train.train_iters_per_epoch = 30 cfg.evaluation.val_iters_per_epoch = 2 cfg.train.seed = 1234 cfg.train.optimizer.lr = 2e-5 cfg.train.hooks = [{ 'type': 'CheckpointHook', 'by_epoch': False, 'interval': 50 }, { 'type': 'EvaluationHook', 'by_epoch': False, 'interval': 50 }, { 'type': 'TextLoggerHook', 'by_epoch': False, 'rounding_digits': 5, 'interval': 10 }] cfg_file = os.path.join("./model/temp", 'config.json') cfg.dump(cfg_file) trainer = build_trainer( Trainers.faq_question_answering_trainer, default_args=dict( model="damo/nlp_structbert_faq-question-answering_chinese-base", work_dir="./model/temp", train_dataset=train_dataset, eval_dataset=eval_dataset, cfg_file=cfg_file)) trainer.train() evaluate_result = trainer.evaluate() print(evaluate_result)
完整错误信息
Dataset({ features: ['text', 'label', 'answer'], num_rows: 26 }) 2023-06-26 20:32:21,659 - modelscope - INFO - initialize model from ./model/damo/nlp_structbert_faq-question-answering_chinese-base 2023-06-26 20:32:22,949 - modelscope - INFO - faq task build protonet network 2023-06-26 20:32:28,135 - modelscope - INFO - All model checkpoint weights were used when initializing SbertForFaqQuestionAnswering. 2023-06-26 20:32:28,136 - modelscope - INFO - All the weights of SbertForFaqQuestionAnswering were initialized from the model checkpoint If your task is similar to the task the model of the checkpoint was trained on, you can already use SbertForFaqQuestionAnswering for predictions without further training. 2023-06-26 20:32:28,137 - modelscope - WARNING - No train key and type key found in preprocessor domain of configuration.json file. 2023-06-26 20:32:28,138 - modelscope - WARNING - Cannot find available config to build preprocessor at mode train, current config: {'max_seq_length': 50, 'model_dir': './model/damo/nlp_structbert_faq-question-answering_chinese-base'}. trying to build by task and model information. 2023-06-26 20:32:28,172 - modelscope - WARNING - No val key and type key found in preprocessor domain of configuration.json file. 2023-06-26 20:32:28,172 - modelscope - WARNING - Cannot find available config to build preprocessor at mode eval, current config: {'max_seq_length': 50, 'model_dir': './model/damo/nlp_structbert_faq-question-answering_chinese-base'}. trying to build by task and model information. 2023-06-26 20:32:28,185 - modelscope - WARNING - ('CUSTOM_DATASETS', 'faq-question-answering', 'structbert') not found in ast index file 2023-06-26 20:32:28,186 - modelscope - WARNING - ('CUSTOM_DATASETS', 'faq-question-answering', 'structbert') not found in ast index file 2023-06-26 20:32:28,187 - modelscope - INFO - cuda is not available, using cpu instead. 2023-06-26 20:32:28,187 - modelscope - INFO - ==========================Training Config Start========================== 2023-06-26 20:32:28,187 - modelscope - INFO - { "framework": "pytorch", "task": "faq-question-answering", "pipeline": { "type": "faq-question-answering" }, "model": { "type": "structbert", "pooling": "avg", "metric": "relation" }, "preprocessor": { "max_seq_length": 50, "model_dir": "./model/damo/nlp_structbert_faq-question-answering_chinese-base" }, "train": { "seed": 1234, "hooks": [ { "type": "IterTimerHook" } ], "train_iters_per_epoch": 30, "max_epochs": 1, "sampler": { "n_way": 5, "k_shot": 5, "r_query": 5, "min_labels": 2 }, "optimizer": { "type": "Adam", "lr": 2e-05, "options": { "grad_clip": { "max_norm": 5.0 } } }, "lr_scheduler": { "type": "LinearLR", "options": { "by_epoch": false } }, "dataloader": { "workers_per_gpu": 1 }, "checkpoint": { "period": { "by_epoch": false, "interval": 50 } }, "logging": { "by_epoch": false, "rounding_digits": 5, "interval": 10 }, "work_dir": "./model/temp" }, "evaluation": { "metrics": "seq-cls-metric", "val_iters_per_epoch": 2, "dataloader": { "workers_per_gpu": 1 }, "period": { "by_epoch": false, "interval": 50 } } } 2023-06-26 20:32:28,188 - modelscope - INFO - ===========================Training Config End=========================== 2023-06-26 20:32:28,190 - modelscope - INFO - num. of bad sample ids:5/26 2023-06-26 20:32:28,192 - modelscope - INFO - train: label size:3.0, data size:18, domain_size:1 2023-06-26 20:32:28,193 - modelscope - WARNING - ('OPTIMIZER', 'default', 'Adam') not found in ast index file 2023-06-26 20:32:28,194 - modelscope - WARNING - ('LR_SCHEDULER', 'default', 'LinearLR') not found in ast index file 2023-06-26 20:32:28,194 - modelscope - INFO - Stage: before_run: (ABOVE_NORMAL) OptimizerHook (LOW ) LrSchedulerHook (LOW ) CheckpointHook (VERY_LOW ) TextLoggerHook -------------------- Stage: before_train_epoch: (LOW ) LrSchedulerHook -------------------- Stage: before_train_iter: (ABOVE_NORMAL) OptimizerHook -------------------- Stage: after_train_iter: (ABOVE_NORMAL) OptimizerHook (NORMAL ) EvaluationHook (LOW ) LrSchedulerHook (LOW ) CheckpointHook (VERY_LOW ) TextLoggerHook -------------------- Stage: after_train_epoch: (NORMAL ) EvaluationHook (LOW ) LrSchedulerHook (LOW ) CheckpointHook (VERY_LOW ) TextLoggerHook -------------------- Stage: after_val_epoch: (VERY_LOW ) TextLoggerHook -------------------- Stage: after_run: (LOW ) CheckpointHook -------------------- 2023-06-26 20:32:28,197 - modelscope - INFO - Checkpoints will be saved to ./model/temp 2023-06-26 20:32:28,197 - modelscope - INFO - Text logs will be saved to ./model/temp ** build_dataset error log: 'structbert is not in the custom_datasets registry group faq-question-answering. Please make sure the correct version of ModelScope library is used.' ** build_dataset error log: 'structbert is not in the custom_datasets registry group faq-question-answering. Please make sure the correct version of ModelScope library is used.'
参考回答:
可以使用以下命令进行更新:
python
Copy
!pip install -U modelscope
如果更新后仍然存在问题,可以尝试手动注册自定义数据集。在代码中添加以下代码:
python
Copy
from modelscope.datasets import custom_datasets
custom_datasets.register("faq-question-answering", "structbert")
关于本问题的更多回答可点击原文查看:https://developer.aliyun.com/ask/524664?spm=a2c6h.14164896.0.0.55721edfBKaCYG
问题四:论坛上说,ModelScope要用 GPU来训练。我这个如何用 GPU来训练呢?
问题1: 论坛上说,ModelScope要用 GPU来训练。我这个如何用 GPU来训练呢? 问题2:现在怎么启动呢?
参考回答:
回答1:你这一看 就不是GPU,选择的点点在CPU上 关闭了重新开吧 回答2:点方式2旁边那个圆圈圈
关于本问题的更多回答可点击原文查看:https://developer.aliyun.com/ask/518680?spm=a2c6h.14164896.0.0.55721edfBKaCYG
问题五:我使用buildertrain训练过程中报了个错误,请问ModelScope这个是版本问题导致的嘛?
我使用buildertrain训练过程中报了个错误,在trainer,train()时,KeyError: 'LinearLR is not in the lr_scheduler registry group default. Please make sure the correct version of ModelScope library is used.'请问ModelScope这个是版本问题导致的嘛?
参考回答:
pytorch版本比较低,可以使用更高版本比如1.12以上,或者使用其他的lr_scheduler
关于本问题的更多回答可点击原文查看:https://developer.aliyun.com/ask/520286?spm=a2c6h.14164896.0.0.55721edfBKaCYG