微调 Code Llama 完整指南

text2sql:SQLCoder的简介、安装、使用方法之详细攻略 SQLCoder 是一个 15B 参数模型,在sql-eval框架上,它的性能优于自然语言到 SQL 生成任务,并且明显优于所有流行的开源模型。在给定架构上进行微调时,它的性能也优于SQLCoder 在基本的 StarCoder 模型上进行了微调。性能对比:在 SQL 生成任务的评估框架上,SQLCoder(64.6%)的性能略微超过了 gpt-3.5-turbo(60.6%)。训练数据:Defog 在两个周期内对10,537个人工策划的问题进行了训练,这些问题基于10种不同的模式。使用方法。 阅读详情
AI摘要

本文详细介绍了如何对CodeLlama进行针对SQL开发的微调,包括安装依赖、加载数据集、使用Lora方法、模型训练和加载最终检查点。通过这些步骤,可以提升CodeLlama在SQL任务上的性能。

一、前言

今天这篇文章将向大家详细介绍如何对 Code Llama 进行微调,让它变成适合 SQL 开发的有利工具。对于编程开发任务,经过适当微调后的 Code Llama 的性能通常都会比普通的 Llama 强很多,特别是当我们针对具体任务进行优化时:

  • 使用b-mc2/sql-create-context这个文本查询及其对应的SQL查询集合进行训练

  • 使用Lora方法,将基础模型的权重量化为int8,冻结权重,仅对适配器进行训练

  • 本文大多参考了alpaca-lora项目,同时也进行了一定的改进与优化

通过上述几点方法,相信我们能使Code Llama专注于SQL开发领域,获得更好的效果。如果按照本指南步骤进行指导,相信您也能掌握微调的奥妙。

二、微调 Code Llama

2.1、安装依赖

我使用了一台配置了 Python 3.10 和 Cuda 11.8 的 A100 GPU 服务器来运行本文中的代码。大约运行了一个小时。(为了验证可移植性,我还试验在Colab上运行代码,效果都很好。)

!pip install git+https://github.com/huggingface/transformers.git@main bitsandbytes accelerate==0.20.3  # we need latest transformers for this
!pip install git+https://github.com/huggingface/peft.git@e536616888d51b453ed354a6f1e243fecb02ea08
!pip install datasets==2.10.1
import locale # colab workaround
locale.getpreferredencoding = lambda: "UTF-8" # colab workaround
!pip install wandb

2.2、加载库

from datetime import datetime
import os
import sys

import torch
from peft import (
    LoraConfig,
    get_peft_model,
    get_peft_model_state_dict,
    prepare_model_for_int8_training,
    set_peft_model_state_dict,
)
from transformers import AutoTokenizer, AutoModelForCausalLM, TrainingArguments, Trainer, DataCollatorForSeq2Seq

(如果出现导入错误,请尝试重新启动 Jupyter 内核)

2.3、加载数据集

这将从 Huggingface Hub 中提取数据集,并将其中的 10% 分成评估集,以检查模型在训练中的表现如何:

from datasets import load_dataset
dataset = load_dataset("b-mc2/sql-create-context", split="train")
train_dataset = dataset.train_test_split(test_size=0.1)["train"]
eval_dataset = dataset.train_test_split(test_size=0.1)["test"]

如果您想加载自己的数据集,请执行以下操作:

train_dataset = load_dataset('json', data_files='train_set.jsonl', split='train')
eval_dataset = load_dataset('json', data_files='validation_set.jsonl', split='train')

如果您想查看数据集中的任何样本,只需执行以下

【LoRa】【BLOOMZ】用peft训练bloomz保存检查点,保存和加载的权重不一致???adapter_model.bin只有4kb??? 能看到检查点中adapter_model.bin只有4kb,这明显什么都没有保存。,训练了1轮后发现,结果没有任何变化,用几个检查点做了测试结果也是没有任何变化。最近用peft的lora对bloomz做训练,参考的。都是解决保存和加载不一致的问题。但最终,我的解决办法是把。有两篇帖子能作为参考。 阅读详情

相关推荐

模型微调-基于LLaMA-Factory进行微调的一个简单案例

接下来就可以通过 LLaMa-Factory 进行微调了,这里先做一个简单的演示,为了不让这篇文章篇幅过长,先不具体讲解各种微调参数的含义和作用,数据集也只使用 LLaMa-Factory 自带的示例数据集,演示一下对模型认知设定的微调。需要注意的是,加载本地模型的时候,需要修改填写模型本地路径,这里的路径是模型快照的唯一哈希值,而不是模型文件夹的路径。之后就可通过和模型进行对话,测试下载下来的模型是否正常了,也可以看下对话中模型输出的风格,和我们微调之后的做下对比。

weixin_37648525的博客 2022

LLama-Factory大模型训练框架,基于自己数据集微调qwen7B模型实战

LLama-Factory,大模型训练框架,支持多种模型,多种训练方式,link。

dream_home8407的博客 4089

在Ubuntu上用Llama Factory命令行微调Qwen2.5的简单过程

如果显存不够可能会报错,这个我在后一篇博客里再总结。如果显存够,那么可以直接得到微调后的lora模块,我这里用两个3090训练只需要一分多钟。"output": "您好,我是 {{name}},一个由 {{author}} 发明的人工智能助手。我可以回答各种问题,提供实用的建议和帮助,帮助用户完成各种任务。如果用命令行做的话,前面的步骤可以参考上面这个博客。然后再问大模型“你是谁?”,就可以看到修改之后的效果了。"instruction": "你是谁?

qysh123的专栏 2259

Code Llama系列教程之 微调 CodeLlama 34B 以进行聊天(打造自己的代码AI)

虽然 Meta 的 Llama2 在 AI 领域引起了广泛关注,但 34b 模型却缺席了相当长一段时间。对于许多人来说,这个 34b 模型是运行本地 LLM 的理想选择,因为它与使用 4 位量化的单个 4090 GPU 兼容。我一直在热切地等待 Meta 发布这个特定的模型。幸运的是,Meta 最近推出了 CodeLlama,这是一个针对编码相关任务训练的专门模型。

iCloudEnd的博客 2281

LLaMA Factory单机微调的实战教程

本文主要介绍了使用LLaMA Factory对大模型进行单机微调的实战教程,希望对学习大语言模型的同学们有所帮助。 文章目录 1. 前言 2. 配置环境 2.1 安装虚拟环境 2.2 安装依赖库 2.3 模型选型与下载 3. 运行代码 3.1 构建训练数据 3.2 修改配置文件 3.3 微调

herosunly的博客 21万+

Llama3-8B+ LLaMA-Factory 中文微调

Llama3是目前开源大模型中最优秀的模型之一,但是原生的Llama3模型训练的中文语料占比非常低,因此在中文的表现方便略微欠佳!本教程就以Llama3-8B-Instruct开源模型为模型基座,通过开源程序LLaMA-Factory来进行中文的微调,提高Llama3的中文能力!

2401_84052244的博客 9998

超聚变安装银河麒麟服务器系统ky10-server-x86

超聚变-通过BMC口进服务器管理界面如下图为BMC管理口:默认BMC口IP:https://192.168.2.100l浏览器打开网页,输入用户名和密码登陆后,如下图红框处,选择“启动虚拟控制台”——选择“HTML集成远程控制台”系统银河麒麟服务器系统ky10 server x86选择镜像文件X86架构我们一般选择下图2212版本选择启动方式:光驱重启出现安装图形化界面选装安装系统的磁盘系统安装盘选完后如下图,会置灰创建root密码开始安装系统首次进入,有协议界面。

zengliguang的专栏 5979

ShardingSphere-JDBC 关键字问题

这里得到的提示就是,假设一个老库一堆表,只对个别表进行分表。引入sharding后虽然指定了分表的bindingTables,其余的走default-data-source就是默认不分表的。但是sharding会接管数据源,老表用默认的mybatis正常,sharding可能会报错。preciseAlgorithmClassName对应的是类名,注意yaml的缩进。这不是常见的没有配置sharding数据源导致empty的错误。使用sharding的时候,遇到了两个问题。...

bohu83的博客 4999

Argoverse2数据集保姆级导入教程:从下载到预处理全流程解析

本文详细解析了Argoverse2数据集的完整导入流程,从环境配置、数据下载到预处理和高效加载策略。作为自动驾驶领域的标杆数据集,Argoverse2提供多模态传感器数据和高精地图信息,帮助研究者快速搭建数据处理流水线。文章包含实用代码示例和性能优化技巧,特别适合自动驾驶算法开发者参考。

weixin_29035405的博客 347

Python爬虫实战:携程/飞猪酒店信息爬取与动态价格分析

在当今数字化旅游时代,酒店预订平台的复杂筛选条件和动态定价机制为数据分析和价格监控带来了巨大挑战。本文将深入探讨如何使用最新的Python爬虫技术来抓取携程和飞猪平台的酒店信息,处理复杂的筛选条件,并解析动态价格数据。本文详细介绍了如何使用最新的Python爬虫技术来抓取携程和飞猪平台的酒店信息。通过结合httpxplaywrightparsel强大的反反爬虫能力:通过浏览器指纹伪装、请求签名、智能延迟等技术应对各种反爬措施高效的数据解析:使用CSS选择器和XPath精确提取所需信息灵活的数据存储。

2201_76125261的博客 421

谱方法学习笔记-下(超详细)

《谱方法学习笔记》深入介绍了傅立叶谱方法在解决偏微分方程问题中的理论和实践,提供了清晰的步骤、Matlab代码以及对一维、二维波动方程等不同问题的解析,适合对谱方法感兴趣的学习者。

图灵的猫的博客 2856

YOLO11涨点优化:卷积魔改 | 可变形条带卷积(DSCN),魔改轻量DCNv3二次创新

如何跟YOLO11结合:1)和C3k2创新性结合

①答疑群聊服务;②YOLO大模型知识问答系统;③计算机视觉论文生成智能体; 993

ANSYS专题-利用ANSYS SIwave进行PCB板的EMS仿真

本文详细描述了使用ANSYSSIwave进行电路板电磁敏感度(EMS)仿真的完整流程。主要步骤包括:导入AD软件生成的IPC2581文件,检查PCB叠层和电路参数,为敏感网络设置50欧姆端口并指定GND为参考网络,进行验证检查后设置频段范围和入射波类型(单/多入射、极化方式等),最后启动仿真并查看选定网络的EMS感应电压曲线。该过程提供了从文件准备到结果分析的全套操作指南,适用于评估电路板在电磁干扰环境下的性能表现。

whm128的博客 3660

高通SDX35:SGMII接口PHY RTL8211FSI-CG驱动适配

高通SDX35 RTL8211F SGMII

不秃头的程序猿Gabriel的博客 793

计算机控制技术及应用

《计算机控制技术及应用》通过总结作者的科研成果和吸收国内外的先进理论、方法和技术,以计算机控制系统的网络化、开放化、智能化和集成化发展趋势为主线索,主要介绍计算机控制系统的基本概念和计算机控制系统的典型形式,计算机控制系统的数学描述与基本分析方法,以及数字PID控制器、最少拍控制系统、达林算法、状态变量设计法等设计方法及其各种改进算法。重点突出计算机控制系统输入输出通道接口的设计方法和典型控制系统的设计案例与实现方法等。

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

jdk-8u144-linux-x64.tar.gz.

该资源为搭建Linux系统Java环境用,资源的后缀为tar.gz格式的压缩包

Camera2Demo

在Camera2 的基础上进行封装,使得Camera2一堆初始化逻辑与Activity分离,降低耦合度,完成预览拍照并保存的操作

上一篇: AI情绪检测器:准确检测并解读人类情绪
下一篇: Python实战:分享4个提升Python编程技能的库
技术狂潮AI
博客等级 码龄3年 1282粉丝 137原创
评论 2
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

技术狂潮AI

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值