赞
踩
chatglm3-6b, chatglm-3b微调/LORA/推理/单机多卡/deepspeed/支持多轮对话
源码:https://github.com/yongzhuo/ChatGLM3-SFT
0.官方prompt, 支持chatml(system), system可以改,但是要注意<|user|>最好放第一位, 如果换成<|assistant|>直接预测、微调会变得很差
<|system|>
You are ChatGLM3, a large language model trained by Zhipu.AI. Follow the user's instructions carefully. Respond using markdown.
<|user|>
Hello
<|assistant|>
Hello, I'm ChatGLM3. What can I assist you today?
"[MASK]": 64789,
"[gMASK]": 64790,
"[sMASK]": 64791,
"sop": 64792,
"eop": 64793,
"<|system|>": 64794,
"<|user|>": 64795,
"<|assistant|>": 64796,
"<|observation|>": 64797
<|system|> Answer the following questions as best as you can. You have access to the following tools: [ { "name": "get_current_weather", "description": "Get the current weather in a given location", "parameters": { "type": "object", "properties": { "location": { "type": "string", "description": "The city and state, e.g. San Francisco, CA", }, "unit": {"type": "string"}, }, "required": ["location"], }, } ] <|user|> 今天北京的天气怎么样? <|assistant|> 好的,让我们来查看今天的天气 <|assistant|>get_current_weather '''python tool_call(location="beijing", unit="celsius") ''' <|observation|> {"temperature": 22} <|assistant|> 根据查询结果,今天北京的气温为 22 摄氏度。
def build_chat_input(self, query, history=None, role="user"):
if history is None:
history = []
input_ids = []
for item in history:
content = item["content"]
if item["role"] == "system" and "tools" in item:
content = content + "\n" + json.dumps(item["tools"], indent=4, ensure_ascii=False)
input_ids.extend(self.build_single_message(item["role"], item.get("metadata", ""), content))
input_ids.extend(self.build_single_message(role, "", query))
input_ids.extend([self.get_command("<|assistant|>")])
return self.batch_encode_plus([input_ids], return_tensors="pt", is_split_into_words=True)
transformers==4.27.1
torch>=2.0
sentencepiece
cpm_kernels
mdtex2html
accelerate
protobuf
gradio
地址: chatglm3_6b/ft_chatglm3
配置: chatglm3_6b/ft_chatglm3/config.py
训练: python train.py
接口: python post_api.py
回答得比较短了, 也确实遵循了主题
本项目相关资源仅供学术研究之用,使用涉及第三方代码的部分时,请严格遵循相应的开源协议。模型生成的内容受模型计算、随机性和量化精度损失等因素影响,本项目不对其准确性作出保证。对于模型输出的任何内容,本项目不承担任何法律责任,亦不对因使用相关资源和输出结果而可能产生的任何损失承担责任。
型输出的任何内容,本项目不承担任何法律责任,亦不对因使用相关资源和输出结果而可能产生的任何损失承担责任。
可以直接model.merge_and_unload(),也可以参考https://github.com/ymcui/Chinese-LLaMA-Alpaca/blob/main/scripts/merge_llama_with_chinese_lora.py
print_named_parameters(model, True) model = load_model_state(model=model, model_save_dir=MODEL_SAVE_DIR) model = prepare_model_for_half_training(model, use_gradient_checkpointing=False, output_embedding_layer_name="lm_head", layer_norm_names=["post_attention_layernorm", "final_layernorm", "input_layernorm", ], ) print_named_parameters(model, True) if USE_CUDA: model = model.half().cuda() else: model = model.bfloat16() print_named_parameters(model, True) model = model.merge_and_unload() print_named_parameters(model, True) model.train(False) model.save_pretrained("merge_and_unload")
merge前:
('base_model.model.transformer.encoder.layers.0.self_attention.query_key_value.weight', torch.float16, False, tensor([
[ 0.0064, 0.0006, 0.0198, ..., -0.0052, -0.0012, -0.0023],
('base_model.model.transformer.encoder.layers.0.self_attention.query_key_value.lora_A.default.weight', torch.float16, False, tensor([
[-0.0134, 0.0130, 0.0087, ..., -0.0275, -0.0126, -0.0121],
merge后:
('transformer.encoder.layers.0.self_attention.query_key_value.weight', torch.bfloat16, False, tensor([
[ 0.0069, -0.0003, 0.0182, ..., -0.0044, -0.0007, -0.0022],
merge前: gMASK sop<|system|> You are a helpful assistant,10 words per answer. <|user|> What's the weather like today? <|assistant|> It's sunny and warm. <|user|> merge后: gMASK sop<|system|> You are a helpful assistant, 10 words per answer. <|user|> What's the weather like today? <|assistant|> It's sunny and warm. <|user|>
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。