swift
swift copied to clipboard
自我认知微调失败
微调前 `import os os.environ['CUDA_VISIBLE_DEVICES'] = '0'
from swift.llm import ModelType, InferArguments, infer_main
infer_args = InferArguments(model_type=ModelType.qwen1half_0_5b_chat)
infer_main(infer_args)微调
import os
os.environ['CUDA_VISIBLE_DEVICES'] = '0'
from swift.llm import DatasetName, ModelType, SftArguments, sft_main
sft_args = SftArguments( model_type=ModelType.qwen1half_0_5b_chat, dataset=[DatasetName.alpaca_zh, DatasetName.alpaca_en], train_dataset_sample=1000, logging_steps=5, max_length=2048, learning_rate=5e-5, warmup_ratio=0.4, output_dir='output', lora_target_modules=['ALL'], self_cognition_sample=500, model_name=['小黄', 'Xiao Huang'], model_author=['魔搭', 'ModelScope']) output = sft_main(sft_args) best_model_checkpoint = output['best_model_checkpoint'] print(f'best_model_checkpoint: {best_model_checkpoint}')`
微调后
`import os os.environ['CUDA_VISIBLE_DEVICES'] = '0'
from swift.llm import InferArguments, merge_lora, infer_main
best_model_checkpoint = 'output/qwen1half-0_5b-chat/v4-20240522-133722/checkpoint-50' infer_args = InferArguments(ckpt_dir=best_model_checkpoint) merge_lora(infer_args, device_map='auto') result = infer_main(infer_args) `
output: <<< 你是谁 我是来自阿里云的大规模语言模型,我叫通义千问。
全流程都是按照官方文档来的,环境配置:ubuntu22.04-cuda12.1.0-py310-torch2.1.2-tf2.14.0-1.14.0