Skip to content

微调DS_32B后merge_lora,将合并后的模型推理不生效 #3974

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
nenelin opened this issue Apr 24, 2025 · 9 comments
Open

微调DS_32B后merge_lora,将合并后的模型推理不生效 #3974

nenelin opened this issue Apr 24, 2025 · 9 comments

Comments

@nenelin
Copy link

nenelin commented Apr 24, 2025

CUDA_VISIBLE_DEVICES=0,1,2,3,4,5,6,7 \ swift deploy \ --adapters /mnt/data/ffcs/code/ms-swift/output/v1-20250423-180903/checkpoint-138 \ --infer_backend vllm \ --temperature 0 \ --max_new_tokens 2048 \ --tensor-parallel-size 8 \ --merge_lora true

控制台中,微调内容推理正常,

当单独使用合并后的文件夹进行 vllm推理的时候
微调后的内容不生效

from transformers import AutoModelForCausalLM, AutoTokenizer

model_path = "/mnt/data/ffcs/code/ms-swift/output/v1-20250423-180903/checkpoint-138-merged" # 替换为实际路径或模型名称
tokenizer = AutoTokenizer.from_pretrained(model_path)
model = AutoModelForCausalLM.from_pretrained(
model_path,
torch_dtype="auto",
device_map="auto"
)

prompt = "你是谁"
messages = [
{"role": "user", "content": prompt}
]

text = tokenizer.apply_chat_template(
messages,
tokenize=False,
add_generation_prompt=True
)
inputs = tokenizer(text, return_tensors="pt").to(model.device)

outputs = model.generate(
**inputs,
max_new_tokens=512
)
print(tokenizer.decode(outputs[0], skip_special_tokens=True))

输出:
<|User|>你是谁<|Assistant|>
您好!我是由中国的深度求索(DeepSeek)公司开发的智能助手DeepSeek-R1。如您有任何问题或建议,请随时告诉我,我会尽我所能为您提供帮助。

您好!我是由中国的深度求索(DeepSeek)公司开发的智能助手DeepSeek-R1。如您有任何问题或建议,请随时告诉我,我会尽我所能为您提供帮助。

CUDA_VISIBLE_DEVICES=0,1,2,3,4,5,6,7 \ swift deploy \ --adapters /mnt/data/ffcs/code/ms-swift/output/v1-20250423-180903/checkpoint-138 \ --infer_backend vllm \ --temperature 0 \ --max_new_tokens 2048 \ --tensor-parallel-size 8 \ --merge_lora true

输出:
的,用户问我是谁,我需要按照设定的角色来回答。首先,我得确认自己的身份是智能医疗助手。我叫「吉祥福医」,要保持口语化,简洁易懂。\nin用户可能刚接触这个系统,所以需要明确说明我的功能,比如提供医疗咨询、健康建议等。同时,根据之前的指示,要加入情感陪伴和情节推动,可能需要询问用户的需求,引导他们进一步互动。\n还要注意不要使用专业术语,保持自然。比如用“在线医生”而不是“医疗专业人员”。另外,要确保回答符合角色设定,不涉及其他功能或超出范围的内容。\ìn可能用户有健康问题需要帮助,或者只是好奇。所以回答里要包含主动询问,比如“您有什么健康方面的问题需要我帮忙解答吗?“这样可以推动对话进展,促进用户提出县体问题。\nn检査是否有需要调整的地方,比如是否足够亲切,有没有遗漏关键信息。确保符合所有给定的指导方针,出如人格可塑性和情感链接。最后,保持回复简短,避免冗长。\nnnn您好!我是[吉祥福医!。作为您的AT中医助手,我深度融合千年中医精髓与现代人工智能技术,致力于为公众提供专业、精准的中医药健康服务,你有什么医疗方面的问题需要我帮忙解答吗?我会尽力为您提供帮助。
控制台启动推理则为正常

@Jintao-Huang
Copy link
Collaborator

微调的shell有嘛

@Jintao-Huang
Copy link
Collaborator

确认一下是不是merge-lora导致的问题

请使用swift infer --model xxx-merged 进行尝试

@Jintao-Huang Jintao-Huang added the bug Something isn't working label Apr 25, 2025
@charlist8324
Copy link

我也有这个问题,web上微调后,再使用web页面的推理,都正常,导出lora检查点合并模型权重后,丢失微调的内容
导出命令: swift export --adapters /home/data/llm_train/ms-swift/ms-swift/output/bg_vl_out/3/v0-20250424-164656/checkpoint-270 --merge_lora true
部署使用方法是:
swift deploy
--model /home/data/llm_train/ms-swift/ms-swift/output/bg_vl_out/3/v0-20250424-164656/merge/3
--infer_backend pt
--temperature 0.3
--max_new_tokens 2048
--served_model_name 'bg_vl'

@charlist8324
Copy link

不要用官方的导出方式,使用以下命令导出即可,感觉很乱啊
swift export --model_type internvl3 --template internvl2_5 --merge_lora True --output_dir XXX --ckpt_dir XXX

@Jintao-Huang
Copy link
Collaborator

merge-lora是使用命令行方式做的嘛

我也有这个问题,web上微调后,再使用web页面的推理,都正常,导出lora检查点合并模型权重后,丢失微调的内容 导出命令: swift export --adapters /home/data/llm_train/ms-swift/ms-swift/output/bg_vl_out/3/v0-20250424-164656/checkpoint-270 --merge_lora true 部署使用方法是: swift deploy --model /home/data/llm_train/ms-swift/ms-swift/output/bg_vl_out/3/v0-20250424-164656/merge/3 --infer_backend pt --temperature 0.3 --max_new_tokens 2048 --served_model_name 'bg_vl'

@nenelin
Copy link
Author

nenelin commented Apr 29, 2025

微调的shell有嘛

swift export
--adapters output/vx-xxx/checkpoint-xxx
--merge_lora true
使用这个合并之后 vllm启动微调内容不生效

nohup bash -c 'CUDA_VISIBLE_DEVICES=0,1,2,3,4 swift deploy
--adapters /checkpoint-xxxx
--stream true
--infer_backend vllm
--gpu_memory_utilization 0.9
--max_model_len 16384
--temperature 0
--max_new_tokens 40000
--served_model_name xxx
--tensor-parallel-size 4' > output.log 2>&1 &
这个推理是正常的

@Jintao-Huang Jintao-Huang removed the bug Something isn't working label May 2, 2025
@lzk9508
Copy link

lzk9508 commented May 7, 2025

不要用官方的导出方式,使用以下命令导出即可,感觉很乱啊 swift export --model_type internvl3 --template internvl2_5 --merge_lora True --output_dir XXX --ckpt_dir XXX

这个work吗?不是应该有三个地址吗,微调完一个lora的checkpoint,还有一个基本模型,以及merge后输出的模型

@lzk9508
Copy link

lzk9508 commented May 7, 2025

swift export --model_type internvl3 --template internvl2_5 --merge_lora True --output_dir XXX --ckpt_dir XXX

好像--model_type还不支持internvl3:ValueError: model_type: 'internvl3' not in ['emu3_gen', 'emu3_chat', 'baichuan', 'baichuan_m1', 'baichuan2', 'modern_bert', 'modern_bert_gte', 'bert', 'chatglm2', 'chatglm3', 'glm4', 'longwriter_llama3_1', 'codegeex4', 'glm4v', 'cogvlm', 'cogagent_chat', 'cogagent_vqa', 'cogvlm2', 'cogvlm2_video', 'glm_edge', 'glm_edge_v', 'qwen', 'modelscope_agent', 'qwen_audio', 'qwen_vl', 'qwen2', 'qwen2_5', 'qwen2_5_math', 'qwen2_moe', 'qwen2_vl', 'qvq', 'qwen2_5_vl', 'qwen2_audio', 'marco_o1', 'qwq', 'ovis1_6', 'ovis1_6_llama3', 'ovis2', 'qwen2_reward', 'qwen2_5_prm', 'qwen2_5_math_reward', 'codefuse_qwen', 'codefuse_codegeex2', 'codefuse_codellama', 'deepseek', 'deepseek_moe', 'deepseek_v2', 'deepseek_v2_5', 'deepseek_vl', 'deepseek_janus', 'deepseek_janus_pro', 'deepseek_vl2', 'deepseek_r1', 'deepseek_r1_distill', 'moonlight', 'paligemma', 'gemma', 'gemma2', 'internlm', 'internlm2', 'internlm3', 'internvl', 'internvl_phi3', 'internvl2', 'internvl2_phi3', 'internvl2_5', 'xcomposer2_5', 'xcomposer2', 'xcomposer2_4khd', 'xcomposer2_5_ol_audio', 'internlm2_reward', 'llama', 'llama3', 'llama3_1', 'llama3_2', 'llama3_2_vision', 'llama3_1_omni', 'reflection', 'atom', 'mengzi3', 'numina', 'ziya', 'megrez', 'llava_llama3_hf', 'llava1_5_hf', 'llava_onevision_hf', 'llava_next_qwen_hf', 'llama3_llava_next_hf', 'llava1_6_vicuna_hf', 'llava1_6_mistral_hf', 'llava_llama3_1_hf', 'llava1_6_yi_hf', 'llava_next_video_hf', 'llava_next_video_yi_hf', 'llama3_llava_next', 'llava1_6_mistral', 'llava1_6_yi', 'llava_next_qwen', 'grok', 'polylm', 'yuan2', 'orion', 'dbrx', 'bluelm', 'seggpt', 'xverse', 'xverse_moe', 'c4ai', 'aya', 'qwen2_gte', 'mamba', 'phi3_vision', 'florence', 'phi3_small', 'phi2', 'phi3', 'phi4', 'phi3_moe', 'minicpm_moe', 'minicpmv', 'minicpmv2_5', 'minicpmv2_6', 'minicpmo2_6', 'minicpm', 'minicpm_chatml', 'minicpm3', 'minimax_vl', 'minimax', 'mistral', 'mixtral', 'mistral_nemo', 'mistral_2501', 'zephyr', 'wizardlm2_moe', 'wizardlm2', 'idefics3', 'pixtral', 'molmoe', 'molmo', 'megrez_omni', 'mplug_owl2', 'mplug_owl2_1', 'mplug_owl3', 'mplug_owl3_241101', 'doc_owl2', 'openbuddy_llama', 'openbuddy_llama3', 'openbuddy_mistral', 'openbuddy_mixtral', 'skywork', 'skywork_o1', 'llama3_2_reward', 'gemma_reward', 'got_ocr2', 'got_ocr2_hf', 'step_audio', 'telechat', 'telechat2', 'valley', 'yi_vl', 'yi', 'yi_coder', 'sus']

@nenelin
Copy link
Author

nenelin commented May 8, 2025

不要用官方的导出方式,使用以下命令导出即可,感觉很乱啊 swift export --model_type internvl3 --template internvl2_5 --merge_lora True --output_dir XXX --ckpt_dir XXX

这个work吗?不是应该有三个地址吗,微调完一个lora的checkpoint,还有一个基本模型,以及merge后输出的模型

这个命令是官网拿的 我model没有换,实际写的没有问题,使用的deepseek

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants