• 微调
    大语言模型-ChatGLM-Tuning
    大语言模型-微调chatglm6b
    大语言模型-中文chatGLM-LLAMA微调
    大语言模型-alpaca-lora

  • 本地知识库
    大语言模型2-document ai解读
    大语言模型-DocumentSearch解读
    大语言模型-中文Langchain

本文解读代码的地址:
https://github.com/27182812/ChatGLM-LLaMA-chinese-insturct

中文instruct在chatGLM, LLAMA上的表现

数据

json的预处理

  • instruction
  • tokenizer

相比大语言模型-ChatGLM-Tuning中,是两个函数都放在了dataprocess的一个类中进行,初步看起来需要改变的几乎相同

微调

  • 对chatGLM,finetune.sh
  • 对LLAMA,test_llama1.py

对于chatGLM和之前文章几乎相同,这里主要关注一下LLAMA

数据

def generate_prompt(data_point):# sorry about the formatting disaster gotta move fastif data_point["input"]:return f"""Below is an instruction that describes a task, paired with an input that provides further context. Write a response that appropriately completes the request.
### Instruction:
{data_point["instruction"]}
### Input:
{data_point["input"]}
### Response:
{data_point["output"]}"""else:return f"""Below is an instruction that describes a task. Write a response that appropriately completes the request.
### Instruction:
{data_point["instruction"]}
### Response:
{data_point["output"]}"""def tokenize(prompt):# there's probably a way to do this with the tokenizer settings# but again, gotta move fastresult = tokenizer(prompt,truncation=True,max_length=CUTOFF_LEN + 1,padding="max_length",)return {"input_ids": result["input_ids"][:-1],"attention_mask": result["attention_mask"][:-1],}

模型

model = LlamaForCausalLM.from_pretrained("decapoda-research/llama-7b-hf",load_in_8bit=True,device_map="auto",
)
tokenizer = LlamaTokenizer.from_pretrained("decapoda-research/llama-7b-hf", add_eos_token=True
)model = prepare_model_for_int8_training(model)config = LoraConfig(r=LORA_R,lora_alpha=LORA_ALPHA,target_modules=["q_proj", "v_proj"],lora_dropout=LORA_DROPOUT,bias="none",task_type="CAUSAL_LM",
)
model = get_peft_model(model, config)
tokenizer.pad_token_id = 0  # unk. we want this to be different from the eos token

微调

data = data.shuffle().map(lambda x: tokenize(generate_prompt(x)))trainer = transformers.Trainer(model=model,train_dataset=data["train"],args=transformers.TrainingArguments(per_device_train_batch_size=MICRO_BATCH_SIZE,gradient_accumulation_steps=GRADIENT_ACCUMULATION_STEPS,warmup_steps=100,num_train_epochs=EPOCHS,learning_rate=LEARNING_RATE,fp16=True,logging_steps=20,output_dir="qys-alpaca-chinese",save_total_limit=3,),data_collator=transformers.DataCollatorForLanguageModeling(tokenizer, mlm=False),
)
model.config.use_cache = False
trainer.train(resume_from_checkpoint=False)
# trainer.train()model.save_pretrained("qys-alpaca-chinese")

推理

  • 对chatGLM,infer.py
  • 对LLAMA,generate_llama1.py

推理代码

tokenizer = LlamaTokenizer.from_pretrained("decapoda-research/llama-7b-hf")model = LlamaForCausalLM.from_pretrained("decapoda-research/llama-7b-hf",load_in_8bit=True,torch_dtype=torch.float16,device_map="auto",
)model = PeftModel.from_pretrained( model, "./qys-alpaca-chinese", torch_dtype=torch.float16
)def generate_prompt(instruction, input=None):if input:return f"""Below is an instruction that describes a task, paired with an input that provides further context. Write a response that appropriately completes the request.
### Instruction:
{instruction}
### Input:
{input}
### Response:"""else:return f"""Below is an instruction that describes a task. Write a response that appropriately completes the request.
### Instruction:
{instruction}
### Response:"""instructions = json.load(open("data/zh-data01.json"))answers = []with torch.no_grad():for idx, item in enumerate(instructions[12:18]):feature = format_example(item)input_text = feature['context']print(input_text)inputs = tokenizer(input_text, return_tensors="pt")input_ids = inputs["input_ids"].cuda()generation_config = GenerationConfig(temperature=0.1,top_p=0.75,top_k=40,num_beams=4,)generation_output = model.generate(input_ids=input_ids,generation_config=generation_config,return_dict_in_generate=True,output_scores=True,max_new_tokens=256,)s = generation_output.sequences[0]output = tokenizer.decode(s)print(output.strip())print("--------------------------------------------")

大语言模型-中文chatGLM-LLAMA微调相关推荐

  1. 大语言模型-中文Langchain

    微调 大语言模型-ChatGLM-Tuning 大语言模型-微调chatglm6b 大语言模型-中文chatGLM-LLAMA微调 大语言模型-alpaca-lora 本地知识库 大语言模型2-doc ...

  2. 中文LLaMa和Alpaca大语言模型开源方案 | 扩充中文词表 针对中文语料进行高效编码

    欢迎关注『CVHub』官方微信公众号! Title: Efficient and Effective Text Encoding for Chinese Llama and Alpaca PDF: h ...

  3. Firefly(流萤): 中文对话式大语言模型

    来自:YeungNLP 在本文中,笔者将介绍关于Firefly(流萤)模型的工作,一个中文对话式大语言模型.我们使用较小的模型参数量,如1.4B和2.6B,实现了不错的生成效果. 项目地址: http ...

  4. 生成式大语言模型微调训练快速手册

    ChatGPT的流行让大语言模型走入了大家的视线,怎么打造自己的大语言模型成为了一个急需解决的问题. 目录 大语言模型的获取方法有以下三种: 目前可以Play 的大语言基础模型列表: 相关项目 大语言 ...

  5. 大语言模型排行榜来啦!Vicuna夺冠,清华ChatGLM进前5

    源 | 新智元 大家好,这里是 ‍NewBeeNLP.万万没想到,现在大语言模型们也要像王者荣耀/LoL/Dota这些游戏里的玩家一样打排位赛了!据说,那些闭源模型们很快也会被拉出来溜溜. 最近,来自 ...

  6. UC伯克利发布大语言模型排行榜!Vicuna夺冠,清华ChatGLM进前5

    [导读]万万没想到,现在大语言模型们也要像王者荣耀/LoL/Dota这些游戏里的玩家一样打排位赛了!据说,那些闭源模型们很快也会被拉出来溜溜. 最近,来自LMSYS Org(UC伯克利主导)的研究人员 ...

  7. 本地化部署大语言模型 ChatGLM

    本地化部署大语言模型 ChatGLM 本地化部署大语言模型 ChatGLM 前期筹备 GitHub 基础包 语言模型文件 基础配置 显存查看方法 Anaconda 模块 ChatGLM-6B 网页部署 ...

  8. “超越”(MMCU)中文通用大语言模型测试集预发布

    近期,中文大语言模型蓬勃发展,但却一直没有出现可应用于评测大模型能力的测试.甲骨易AI研究院提出一种衡量中文大模型处理多任务准确度的测试,并在此基础上制作了一套适配测试中文大模型的数据集,并将其命名为 ...

  9. 讯飞星火 VS 文心一言:谁是中文大语言模型的TOP1?

    在百度发布文心一言一个多月后,科大讯飞也发布了自己的大模型"讯飞星火大模型".本篇博客就测评一下这两个在中文圈最受好评的大语言模型,顺便辅以ChatGPT为参考.大家一起来看看到底 ...

最新文章

  1. mysql双机热备的实现
  2. 三、Dockerfile的说明和编写
  3. 微信小游戏 Egret开发数据域官方Demo下载地址
  4. Selenium备忘手册 [转]
  5. windows定时计划备份MySql
  6. filegee为啥没变动也更新_小米miui12中谷歌商店无法更新油管和下载Twitter的问题...
  7. 中国内部物流输送系统市场趋势报告、技术动态创新及市场预测
  8. java List 排序 Collections.sort()
  9. Unity编辑器工具简体繁体一键转换
  10. 关于求数列极限的方法的总结
  11. linux的mysql占用cpu过高_关于在Linux环境下,Mysql占用CPU使用率100%的优化
  12. n−皇后问题 (dfs)
  13. shal+php,PHP微信开发——第二弹
  14. 优化AI搜索引擎,从这3个领域入手!
  15. 无人驾驶汽车系统入门(十五)——ROS入门与实践(2)
  16. python一元线性回归算法,代码及参数更新动图展示
  17. 2023/1/2总结
  18. python做图笔记
  19. 鲜为人知的myeclipse配置
  20. NTT笔记和多项式全家桶

热门文章

  1. 如何把表格导入到excel
  2. 怎么更改一张图片的分辨率,即改变其大小
  3. Lake Shore 648型双极磁铁电源
  4. 元神服务器维护时间,原神维护到几点结束 维护时间1.4版本公告_游戏369
  5. 百万级日活 App 的屏幕录制功能是如何实现的
  6. $( )与` `(反引号)的区别和使用
  7. sql 统计总数和各状态数
  8. PP助手数据采集分析
  9. STM32F103C8T6使用modbus协议读取温湿度传感器
  10. Azure AD Conditional Access