百川sft微调模型,是在百川-7B预训练模型的基础上微调的模型,本模型会持续update在不同的数据集上sft的百川的模型和方法。
安装依赖:
pip install peft
使用代码
from transformers import AutoModelForCausalLM, AutoTokenizer, TextStreamer
from peft import PeftModel
from modelscope.hub.snapshot_download import snapshot_download
model_dir = snapshot_download('baichuan-inc/baichuan-7B', cache_dir='baichuan-7B', revision='v1.0.2')
model_dir_sft = snapshot_download('AI-ModelScope/baichuan_sft_lora', cache_dir='baichuan-sft',revision='v1.0.0')
import sys
sys.path.append("/mnt/workspace/baichuan-7B/baichuan-inc/baichuan-7B")
tokenizer = AutoTokenizer.from_pretrained("/mnt/workspace/baichuan-7B/baichuan-inc/baichuan-7B", trust_remote_code=True)
model = AutoModelForCausalLM.from_pretrained("/mnt/workspace/baichuan-7B/baichuan-inc/baichuan-7B",device_map="auto", trust_remote_code=True)
model = PeftModel.from_pretrained(model, "/mnt/workspace/baichuan-sft/AI-ModelScope/baichuan_sft_lora")
streamer = TextStreamer(tokenizer, skip_prompt=True, skip_special_tokens=True)
query = "晚上睡不着怎么办?"
prompt="Below is an instruction that describes a task. Write a response that appropriately completes the request."
prompt+="### Instruction:\n{}\n\n### Response:\n".format(query)
inputs = tokenizer([prompt], return_tensors="pt")
inputs = inputs.to("cuda")
generate_ids = model.generate(**inputs, max_new_tokens=256,streamer=streamer)
#您可以尝试以下方法来帮助您入睡:
如果您尝试这些方法后仍然无法入睡,建议您咨询医生或寻求专业帮助。
Loss curve on training set:
Loss curve on evaluation set: