AdaSeq icon indicating copy to clipboard operation
AdaSeq copied to clipboard

[Question] 为什么model.save_pretrained总会报错,无法生成pred文件

Open ybqand187 opened this issue 2 years ago • 7 comments

What is your question?

代码是在天池上copy的,但每个模型训练结束执行model.save_pretrained时总会报错,报错如下 ~/opt/anaconda3/lib/python3.9/site-packages/modelscope/trainers/hooks/checkpoint_hook.py in copy_files_and_dump_config(trainer, output_dir, config, bin_file) 261 if hasattr(model, 'save_pretrained'): 262 # Save pretrained of model, skip saving checkpoint --> 263 model.save_pretrained( 264 output_dir, 265 bin_file,

~/opt/anaconda3/lib/python3.9/site-packages/adaseq/models/base.py in save_pretrained(self, target_folder, save_checkpoint_names, save_function, config, save_config_function, with_meta, **kwargs) 161 for field in ['experiment', 'dataset', 'train', 'evaluation']: 162 if field in config: --> 163 del config[field] 164 165 if (

AttributeError: delitem

What have you tried?

No response

Code (if necessary)

`from modelscope.utils.config import Config

config = Config.from_string(""" experiment: exp_dir: experiments/ exp_name: transformer_crf seed: 42

task: named-entity-recognition

dataset: data_file: train: /Users/yyy/data/train.conll valid: /Users/yyy/data/dev.conll test: /Users/yyy/data/test.conll data_type: conll

preprocessor: type: sequence-labeling-preprocessor max_length: 80

data_collator: SequenceLabelingDataCollatorWithPadding

model: type: sequence-labeling-model embedder: model_name_or_path: damo/nlp_raner_named-entity-recognition_chinese-base-news dropout: 0.1 use_crf: true

train: max_epochs: 20 dataloader: batch_size_per_gpu: 16 optimizer: type: AdamW lr: 5.0e-5 param_groups: - regex: crf lr: 5.0e-1 lr_scheduler: type: StepLR step_size: 2 gamma: 0.8 hooks: - type: TensorboardHook

evaluation: dataloader: batch_size_per_gpu: 128 metrics: - type: ner-metric - type: ner-dumper model_type: sequence_labeling dump_format: conll """, file_format='.yaml')

initialize a trainer

import os from adaseq.commands.train import build_trainer_from_partial_objects

work_dir = 'experiments/transformer_crf' os.makedirs(work_dir, exist_ok=True)

trainer = build_trainer_from_partial_objects( config, work_dir=work_dir, seed=42, device='cuda:0' )

do training

trainer.train()

do testing

trainer.test()`

What's your environment?

  • AdaSeq Version (e.g., 1.0 or master):
  • ModelScope Version (e.g., 1.0 or master):
  • PyTorch Version (e.g., 1.12.1):
  • OS (e.g., Ubuntu 20.04):
  • Python version:
  • CUDA/cuDNN version:
  • GPU models and configuration:
  • Any other relevant information:

Code of Conduct

  • [X] I agree to follow this project's Code of Conduct

ybqand187 avatar Apr 21 '23 02:04 ybqand187

您好,我想问一下,后来您这个问题解决了么??因为我在训练过程中也遇到了同样的问题!

thy1999 avatar Apr 23 '23 15:04 thy1999

还是没解决,换用其它框架了

---原始邮件--- 发件人: @.> 发送时间: 2023年4月23日(周日) 晚上11:06 收件人: @.>; 抄送: @.@.>; 主题: Re: [modelscope/AdaSeq] [Question] 为什么model.save_pretrained总会报错,无法生成pred文件 (Issue #19)

您好,我想问一下,后来您这个问题解决了么??因为我在训练过程中也遇到了同样的问题!

— Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you authored the thread.Message ID: @.***>

ybqand187 avatar Apr 23 '23 15:04 ybqand187

那真是太遗憾了,我找了半天也没有找出哪里有问题。。

thy1999 avatar Apr 23 '23 15:04 thy1999

您好,之前钉钉群里也有人提到了这个问题,可能是相同原因,麻烦可以尝试一下呢。 很抱歉最近开发者没有及时跟进issues。

image

image

可以尝试先把modelscope版本降级到1.4.2以下,运行pip install modelscope==1.4.2。 这个问题是ms版本升级导致的兼容性问题,我们会尽快修复!

izhx avatar Apr 23 '23 15:04 izhx

@ybqand187 @thy1999 您好,兼容性问题已经修复了。 重新git pull下代码,或者pip install adaseq==0.6.3,可以再试试看呢~

huangshenno1 avatar Apr 24 '23 06:04 huangshenno1

感谢您的回答,目前这一问题已经被修复。但我还有一个问题想要询问一下,就是我想要在除了已经给出的这些数据集之外的其他数据集上跑MoRe多模态模型,但github上并没有给出相应数据预处理的代码,所以我不太清楚如何得到加image和text的数据预处理文件,不知道是否方便提供一下MoRe这一模型数据预处理的代码呢?

thy1999 avatar Apr 24 '23 12:04 thy1999

感谢您的回答,目前这一问题已经被修复。但我还有一个问题想要询问一下,就是我想要在除了已经给出的这些数据集之外的其他数据集上跑MoRe多模态模型,但github上并没有给出相应数据预处理的代码,所以我不太清楚如何得到加image和text的数据预处理文件,不知道是否方便提供一下MoRe这一模型数据预处理的代码呢?

@caijiong 是MoRE的作者,已经跟他沟通了,晚点他来回复。

huangshenno1 avatar Apr 28 '23 07:04 huangshenno1