初始化项目,由ModelHub XC社区提供模型
Model: Karlzhy/Content_Review_Model Source: Original Platform
This commit is contained in:
22
m2.py
Normal file
22
m2.py
Normal file
@@ -0,0 +1,22 @@
|
||||
from transformers import AutoModelForCausalLM, AutoTokenizer
|
||||
from peft import PeftModel, PeftConfig
|
||||
|
||||
peft_path = "./qwen_lora_checkpoint"
|
||||
merged_path = "./qwen2_ad_audit_merged"
|
||||
|
||||
# 读取 LoRA 配置
|
||||
config = PeftConfig.from_pretrained(peft_path)
|
||||
|
||||
# 加载 base 模型
|
||||
base = AutoModelForCausalLM.from_pretrained(config.base_model_name_or_path, trust_remote_code=True)
|
||||
|
||||
# 注入 LoRA
|
||||
model = PeftModel.from_pretrained(base, peft_path)
|
||||
|
||||
# 合并
|
||||
model = model.merge_and_unload()
|
||||
|
||||
# 保存合并后的完整模型
|
||||
model.save_pretrained(merged_path)
|
||||
tokenizer = AutoTokenizer.from_pretrained(config.base_model_name_or_path, trust_remote_code=True)
|
||||
tokenizer.save_pretrained(merged_path)
|
||||
Reference in New Issue
Block a user