Chinese-LLaMA-Alpaca icon indicating copy to clipboard operation
Chinese-LLaMA-Alpaca copied to clipboard

关于合并llama-alpaca 的问题

Open moseshu opened this issue 2 years ago • 3 comments

Chinese-Alpaca-Plus-7B 和 Chinese-LLaMA-Plus-7B在训练中,target_modules 这个参数都是一样的吧?我看LoraConfig的配置都差不多,都把embedding做了训练

如果我是基于Chinese-Alpaca-Plus-7B 的 adapater.bin做prompt训练,我只需要在代码中设置 model.resize_token_embeddings(tokenzier_vocab_size)( 这里的model 是将facebook权重跟 Chinese-LLaMA-Plus-7B做了合并的) lora config也需要LoraConfig.LoraConfig.from_pretrained("adpater_config_dir")( /adpater_config_dir/adapter_config.json) 比如: config = LoraConfig.LoraConfig.from_pretrained("adpater_config_dir") model = LlamaForCausalLM.from_pretrained("llama_weight") tokenizer = LlamaTokenizer.from_pretrained("alpaca_plus_7B") model.resize_token_embeddings(len(tokenizer))

model = get_peft_model(model, config) adapters_weights = torch.load("lora_ch/adapter_model.bin") model = set_peft_model_state_dict(model, adapters_weights)

moseshu avatar May 05 '23 09:05 moseshu

所以问题是? 另外排版有点乱,代码部分可以放在专门的代码环境:

``` python your code here ```

airaria avatar May 05 '23 14:05 airaria

config = LoraConfig.LoraConfig.from_pretrained("adpater_config_dir")
model = LlamaForCausalLM.from_pretrained("llama_weight")
tokenizer = LlamaTokenizer.from_pretrained("alpaca_plus_7B")
model.resize_token_embeddings(len(tokenizer))

model = get_peft_model(model, config)
adapters_weights = torch.load("lora_ch/adapter_model.bin")
model = set_peft_model_state_dict(model, adapters_weights)

我的意思是我用上的代码在alpaca-plus的基础上训练是可以的吧?

moseshu avatar May 05 '23 14:05 moseshu

如果你的model加载的是合并Chinese-LLaMA-Plus-LoRA后的全量模型(model = LlamaForCausalLM.from_pretrained("llama_weight")),那是可以继续训练的。

不过没按你提供的代码那种方式写过,而且peft库变动也较大,提供一份示例供参考(适用于peft 13e53fc),加载alpaca_plus并继续训练LoRA(假设model已加载合并LLaMA-Plus-LoRA后的全量模型):

tokenizer = LlamaTokenizer.from_pretrained("alpaca_plus_7B")
model.resize_token_embeddings(len(tokenizer)) # len(tokenizer)==49954
model = PeftModel.from_pretrained(model, "alpaca_plus_7B")

airaria avatar May 05 '23 14:05 airaria

如果你的model加载的是合并Chinese-LLaMA-Plus-LoRA后的全量模型(model = LlamaForCausalLM.from_pretrained("llama_weight")),那是可以继续训练的。

不过没按你提供的代码那种方式写过,而且peft库变动也较大,提供一份示例供参考(适用于peft 13e53fc),加载alpaca_plus并继续训练LoRA(假设model已加载合并LLaMA-Plus-LoRA后的全量模型):

tokenizer = LlamaTokenizer.from_pretrained("alpaca_plus_7B")
model.resize_token_embeddings(len(tokenizer)) # len(tokenizer)==49954
model = PeftModel.from_pretrained(model, "alpaca_plus_7B")

好的

moseshu avatar May 06 '23 01:05 moseshu