匿名用户2024年07月31日
26阅读
所属分类ai、其他
开源地址https://modelscope.cn/models/Lanzer/Night-Ode

作品详情

环境安装

'''

    # 设置pip全局镜像
    pip config set global.index-url https://mirrors.aliyun.com/pypi/simple/
    # 安装ms-swift
    git clone https://github.com/modelscope/swift.git
    cd swift
    pip install -e .[llm]

    #环境对齐 (如果你运行错误, 可以跑下面的代码, 仓库使用最新环境测试)
    pip install -r requirements/framework.txt  -U
    pip install -r requirements/llm.txt  -U

'''

超参数设置

模型采用qwen7bchat

微调超参数:

traindatasetsample=500,

eval_steps=20,

logging_steps=5,

output_dir='output',

loratargetmodules='ALL',

selfcognitionsample=500

微调

提示: 因为自我认知训练涉及到知识编辑, 建议对MLP加loratargetmodules. 可以通过指定--loratargetmodules ALL在所有的linear层(包括qkvo以及mlp)加lora. 这通常是效果最好的.

使用python:

    # Experimental environment: A10, 3090, V100, ...
    # 18GB GPU memory
    import os
    os.environ['CUDA_VISIBLE_DEVICES'] = '0'

    from swift.llm import DatasetName, ModelType, SftArguments, sft_main

    sft_args = SftArguments(
        model_type=ModelType.qwen_7b_chat,
        dataset=[DatasetName.alpaca_zh, DatasetName.alpaca_en],
        train_dataset_sample=500,
        eval_steps=20,
        logging_steps=5,
        output_dir='output',
        lora_target_modules='ALL',
        self_cognition_sample=500,
        model_name=['夜咏', 'Night Ode'],
        model_author=['李岚泽', 'Lanzer'])
    output = sft_main(sft_args)
    best_model_checkpoint = output['best_model_checkpoint']
    print(f'best_model_checkpoint: {best_model_checkpoint}')

微调实验记录

Alt text Alt text Alt text

微调后推理

需要设置bestmodelcheckpoint的值, 该值会在sft的最后被打印出来.

使用python:

    import os
    os.environ['CUDA_VISIBLE_DEVICES'] = '0'

    from swift.llm import InferArguments, merge_lora_main, infer_main

    best_model_checkpoint = 'output/qwen-7b-chat/v0-20240122-205735/checkpoint-62'
    infer_args = InferArguments(
        ckpt_dir=best_model_checkpoint,
        eval_human=True)
    # merge_lora_main(infer_args)
    result = infer_main(infer_args)

实验记录

Alt text

声明:本文仅代表作者观点,不代表本站立场。如果侵犯到您的合法权益,请联系我们删除侵权资源!如果遇到资源链接失效,请您通过评论或工单的方式通知管理员。未经允许,不得转载,本站所有资源文章禁止商业使用运营!
下载安装【程序员客栈】APP
实时对接需求、及时收发消息、丰富的开放项目需求、随时随地查看项目状态

评论