FinGPT 当我尝试将默认模型 "chatglm2" 转换为 "llama2" 时,它不起作用,

vhipe2zx  于 9个月前  发布在  其他
关注(0)|答案(3)|浏览(165)

感谢您的精彩项目。我复制了FinGPT v3.1.2(4位QLORA)。它可以在Colab上的默认LLM模型“chatglm2”上工作,但当我想要使用Llama2获得更好的结果时,它会停止运行。

  • 我根据您的指示更改了模型,将model_name = "THUDM/chatglm2-6b"更改为model_name = "daryl149/llama-2-7b-chat-hf"
  • 然后由于运行错误删除了设备:
  1. model = AutoModel.from_pretrained(
  2. model_name,
  3. quantization_config=q_config,
  4. trust_remote_code=True,
  5. token = access_token,
  6. # device='cuda'
  7. )
  • target_modules更改为llama:

target_modules = TRANSFORMERS_MODELS_TO_LORA_TARGET_MODULES_MAPPING['llama']

  • 不幸的是,最后一步出现了一个TypeError: 'NoneType' object cannot be interpreted as an integer
  1. writer = SummaryWriter()
  2. trainer = ModifiedTrainer(
  3. model=model,
  4. args=training_args, # Trainer args
  5. train_dataset=dataset["train"], # Training set
  6. eval_dataset=dataset["test"], # Testing set
  7. data_collator=data_collator, # Data Collator
  8. callbacks=[TensorBoardCallback(writer)],
  9. )
  10. trainer.train()
  11. writer.close()
  12. # save model
  13. model.save_pretrained(training_args.output_dir)

详细的错误如下:

  1. You are adding a <class 'transformers.integrations.TensorBoardCallback'> to the callbacks of this Trainer, but there is already one. The currentlist of callbacks is
  2. :DefaultFlowCallback
  3. TensorBoardCallback
  4. ---------------------------------------------------------------------------
  5. TypeError Traceback (most recent call last)
  6. <ipython-input-27-d05cf508c134> in <cell line: 11>()
  7. 9 callbacks=[TensorBoardCallback(writer)],
  8. 10 )
  9. ---> 11 trainer.train()
  10. 12 writer.close()
  11. 13 # save model
  12. 6 frames
  13. <ipython-input-25-26476d7038e4> in data_collator(features)
  14. 37 ids = ids + [tokenizer.pad_token_id] * (longest - ids_l)
  15. 38 _ids = torch.LongTensor(ids)
  16. ---> 39 labels_list.append(torch.LongTensor(labels))
  17. 40 input_ids.append(_ids)
  18. 41 input_ids = torch.stack(input_ids)
  19. TypeError: 'NoneType' object cannot be interpreted as an integer

您能帮我解决这个问题吗?期待您的回复!(平台:Google Colab上的A100)

kx5bkwkv

kx5bkwkv1#

我也遇到了同样的问题。
我正在运行AWS g5.8xlarge。
你解决了吗?

4ioopgfo

4ioopgfo2#

由于LlamaTokenizer没有tokenizer.pad_token_id的值,所以它的值为None。当这个分词器用于计算'labels'的值时,它会报错。
我将tokenizer.pad_token_id的值设置为0,解决了上述错误。但是又遇到了另一个错误Llama.forward() got an unexpected keyword argument 'labels'。为了解决这个问题,我将
model = AutoModel.from_pretrained( model_name, quantization_config=q_config, trust_remote_code=True )
替换为
model = AutoModelForCausalLM.from_pretrained( model_name, quantization_config=q_config, trust_remote_code=True, device_map = "auto" )
,现在一切正常了。

rt4zxlrg

rt4zxlrg3#

TL;DR:在代码中添加 tokenizer.pad_token_id = 0
主要问题是,ChatGPT 中的代码依赖于 pad_token_id,而元-LLAMA 模型不使用。但是,如果我们仔细查看 special_tokens_map.json,我们可以看到下面的几行:

  1. "pad_token": "<unk>",
  2. "unk_token": {
  3. "content": "<unk>",
  4. "lstrip": false,
  5. "normalized": true,
  6. "rstrip": false,
  7. "single_word": false
  8. }

因此,作为 pad_token,我们可以使用 unk_token 的 id,它等于 0。要解决 None 的问题,请使用 pad_token_id 初始化 tokenizer 中的字段 0:tokenizer.pad_token_id = 0

相关问题