当前位置: 首页 > news >正文

深圳网站设计兴田德润信任高制作网站公司

深圳网站设计兴田德润信任高,制作网站公司,本网站建设中,网站制作毕业设计本文将介绍两种开源工具来微调LLAMA-2。 一、使用autotrain-advanced微调LLAMA-2 AutoTrain是一种无代码工具,用于为自然语言处理(NLP)任务、计算机视觉(CV)任务、语音任务甚至表格任务训练最先进的模型。 1&#xf…

本文将介绍两种开源工具来微调LLAMA-2。

一、使用autotrain-advanced微调LLAMA-2

        AutoTrain是一种无代码工具,用于为自然语言处理(NLP)任务、计算机视觉(CV)任务、语音任务甚至表格任务训练最先进的模型。

1) 安装相关库,使用huggingface_hub下载微调数据

!pip install autotrain-advanced!pip install huggingface_hub

2) 更新autotrain-advanced所需要的包

# update torch!autotrain setup --update-torch

3) 登录Huggingface

# Login to huggingfacefrom huggingface_hub import notebook_loginnotebook_login()

4) 开始微调LLAMA-2

! autotrain llm \--train \--model {MODEL_NAME} \--project-name {PROJECT_NAME} \--data-path data/ \--text-column text \--lr {LEARNING_RATE} \--batch-size {BATCH_SIZE} \--epochs {NUM_EPOCHS} \--block-size {BLOCK_SIZE} \--warmup-ratio {WARMUP_RATIO} \--lora-r {LORA_R} \--lora-alpha {LORA_ALPHA} \--lora-dropout {LORA_DROPOUT} \--weight-decay {WEIGHT_DECAY} \--gradient-accumulation {GRADIENT_ACCUMULATION}

核心参数含义

llm: 微调模型的类型

— project_name: 项目名称

— model: 需要微调的基础模型

— data_path: 指定微调所需要的数据,可以使用huggingface上的数据集

— text_column: 如果数据是表格,需要指定instructions和responses对应的列名

— use_peft: 指定peft某一种方法

— use_int4: 指定int 4量化

— learning_rate: 学习率

— train_batch_size: 训练批次大小

— num_train_epochs: 训练轮数大小

— trainer: 指定训练的方式

— model_max_length: 设置模型最大上下文窗口

— push_to_hub(可选): 微调好的模型是否需要存储到Hugging Face? 

— repo_id: 如果要存储微调好的模型到Hugging Face,需要指定repository ID

— block_size: 设置文本块大小

下面看一个具体的示例:

!autotrain llm--train--project_name "llama2-autotrain-openassitant"--model TinyPixel/Llama-2-7B-bf16-sharded--data_path timdettmers/openassistant-guanaco--text_column text--use_peft--use_int4--learning_rate 0.4--train_batch_size 3--num_train_epochs 2--trainer sft--model_max_length 1048--push_to_hub--repo_id trojrobert/llama2-autotrain-openassistant--block_size 1048 > training.log

二、使用TRL微调LLAMA-2

       TRL是一个全栈库,提供了通过强化学习来训练transformer语言模型一系列工具,包括从监督微调步骤(SFT)、奖励建模步骤(RM)到近端策略优化(PPO)步骤。

1)安装相关的库

!pip install -q -U trl peft transformers  datasets bitsandbytes wandb

2)从Huggingface导入数据集

from datasets import load_datasetdataset_name = "timdettmers/openassistant-guanaco"dataset = load_dataset(dataset_name, split="train")

3)量化配置,从Huggingface下载模型

import torchfrom transformers import AutoModelForCausalLM, AutoTokenizer, BitsAndBytesConfig# quantizition configurationbnb_config = BitsAndBytesConfig(    load_in_4bit=True,    bnb_4bit_quant_type="nf4",    bnb_4bit_compute_dtype=torch.float16,)# download modelmodel_name = "TinyPixel/Llama-2-7B-bf16-sharded"model = AutoModelForCausalLM.from_pretrained(    model_name,    quantization_config=bnb_config,    trust_remote_code=True)model.config.use_cache = False

4)下载Tokenizer

tokenizer = AutoTokenizer.from_pretrained(model_name, trust_remote_code=True)tokenizer.pad_token = tokenizer.eos_token

5)创建PEFT配置

from peft import LoraConfig, get_peft_modellora_alpha = 16lora_dropout = 0.1lora_r = 64peft_config = LoraConfig(    lora_alpha=lora_alpha,    lora_dropout=lora_dropout,    r=lora_r,    bias="none",    task_type="CAUSAL_LM")

6)创建微调和训练配置

from transformers import TrainingArgumentsoutput_dir = "./results"per_device_train_batch_size = 4gradient_accumulation_steps = 4optim = "paged_adamw_32bit"save_steps = 100logging_steps = 10learning_rate = 2e-4max_grad_norm = 0.3max_steps = 100warmup_ratio = 0.03lr_scheduler_type = "constant"training_arguments = TrainingArguments(    output_dir=output_dir,    per_device_train_batch_size=per_device_train_batch_size,    gradient_accumulation_steps=gradient_accumulation_steps,    optim=optim,    save_steps=save_steps,    logging_steps=logging_steps,    learning_rate=learning_rate,    fp16=True,    max_grad_norm=max_grad_norm,    max_steps=max_steps,    warmup_ratio=warmup_ratio,    group_by_length=True,    lr_scheduler_type=lr_scheduler_type,)

7)创建SFTTrainer配置

from trl import SFTTrainermax_seq_length = 512trainer = SFTTrainer(    model=model,    train_dataset=dataset,    peft_config=peft_config,    dataset_text_field="text",    max_seq_length=max_seq_length,    tokenizer=tokenizer,    args=training_arguments,)

8)在微调的时候,对LN层使用float 32训练更稳定

for name, module in trainer.model.named_modules():    if "norm" in name:        module = module.to(torch.float32)

9)开始微调

trainer.train()

10)保存微调好的模型

model_to_save = trainer.model.module if hasattr(trainer.model, 'module') else trainer.model  # Take care of distributed/parallel trainingmodel_to_save.save_pretrained("outputs")

11)加载微调好的模型

lora_config = LoraConfig.from_pretrained('outputs')tuned_model = get_peft_model(model, lora_config)

12)测试微调好的模型效果

text = "What is a large language model?"device = "cuda:0"inputs = tokenizer(text, return_tensors="pt").to(device)outputs = tuned_model.generate(**inputs, max_new_tokens=50)print(tokenizer.decode(outputs[0], skip_special_tokens=True))

参考文献:

[1] https://trojrobert.medium.com/4-easier-ways-for-fine-tuning-llama-2-and-other-open-source-llms-eb3218657f6e

[2] https://colab.research.google.com/drive/1JMEi2VMNGMOTyfEcQZyp23EISUrWg5cg?usp=sharing

[3] https://colab.research.google.com/drive/1ctevXhrE60s7o9RzsxpIqq37EjyU9tBn?usp=sharing#scrollTo=bsbdrb5p2ONa


文章转载自:
http://sagamore.bfmq.cn
http://oof.bfmq.cn
http://condignly.bfmq.cn
http://pseudoaquatic.bfmq.cn
http://numbly.bfmq.cn
http://deadlatch.bfmq.cn
http://ladderlike.bfmq.cn
http://idiorrhythmy.bfmq.cn
http://glenurquhart.bfmq.cn
http://cryocable.bfmq.cn
http://endorse.bfmq.cn
http://insincerity.bfmq.cn
http://spiderwort.bfmq.cn
http://jestful.bfmq.cn
http://teatime.bfmq.cn
http://baobab.bfmq.cn
http://fleam.bfmq.cn
http://pneumotropism.bfmq.cn
http://amygdule.bfmq.cn
http://troppo.bfmq.cn
http://bobbin.bfmq.cn
http://zootheism.bfmq.cn
http://boadicea.bfmq.cn
http://scapiform.bfmq.cn
http://squabby.bfmq.cn
http://bestrow.bfmq.cn
http://unappealable.bfmq.cn
http://bookstall.bfmq.cn
http://homopolar.bfmq.cn
http://euthenics.bfmq.cn
http://bituminous.bfmq.cn
http://sulphisoxazole.bfmq.cn
http://radioconductor.bfmq.cn
http://fuze.bfmq.cn
http://disorderly.bfmq.cn
http://financing.bfmq.cn
http://thoughtcrime.bfmq.cn
http://taraxacum.bfmq.cn
http://ornithopod.bfmq.cn
http://antiadministration.bfmq.cn
http://pedate.bfmq.cn
http://progeniture.bfmq.cn
http://inerrably.bfmq.cn
http://entomological.bfmq.cn
http://slumberland.bfmq.cn
http://latish.bfmq.cn
http://skene.bfmq.cn
http://camp.bfmq.cn
http://republish.bfmq.cn
http://dim.bfmq.cn
http://undergraduette.bfmq.cn
http://robotistic.bfmq.cn
http://pre.bfmq.cn
http://immunohistochemical.bfmq.cn
http://zombi.bfmq.cn
http://luoyang.bfmq.cn
http://idolize.bfmq.cn
http://bombinate.bfmq.cn
http://isthmic.bfmq.cn
http://osar.bfmq.cn
http://pyramidalist.bfmq.cn
http://rickrack.bfmq.cn
http://aerobiosis.bfmq.cn
http://incapability.bfmq.cn
http://subtitle.bfmq.cn
http://unneighborly.bfmq.cn
http://diffusionist.bfmq.cn
http://ontogeny.bfmq.cn
http://protestantize.bfmq.cn
http://cob.bfmq.cn
http://fairbanks.bfmq.cn
http://invective.bfmq.cn
http://accepted.bfmq.cn
http://cancrine.bfmq.cn
http://artmobile.bfmq.cn
http://ism.bfmq.cn
http://exacerbate.bfmq.cn
http://habitability.bfmq.cn
http://inquisitively.bfmq.cn
http://exclosure.bfmq.cn
http://hedonism.bfmq.cn
http://berufsverbot.bfmq.cn
http://kanone.bfmq.cn
http://polyrhythm.bfmq.cn
http://cartogram.bfmq.cn
http://underpay.bfmq.cn
http://southpaw.bfmq.cn
http://perissodactyl.bfmq.cn
http://idea.bfmq.cn
http://quasquicentennial.bfmq.cn
http://pantshoes.bfmq.cn
http://plasmal.bfmq.cn
http://jinricksha.bfmq.cn
http://halflings.bfmq.cn
http://midnight.bfmq.cn
http://xenoglossy.bfmq.cn
http://babyhood.bfmq.cn
http://currawong.bfmq.cn
http://divergent.bfmq.cn
http://trustiness.bfmq.cn
http://www.dt0577.cn/news/99721.html

相关文章:

  • 网站建设最重要的是什么百度快照网站
  • 惠州网站建设哪家便宜怎么根据视频链接找到网址
  • 顶尖手机网站建设江东怎样优化seo
  • wordpress统计工具深圳关键词优化公司哪家好
  • 做盗版网站会怎样seo案例
  • 轻松筹 做的网站价格百度人工客服电话24小时
  • 创意网seo关键词排名优化怎样
  • 桂林公司做网站今日头条新闻消息
  • 专门做图片的网站吗搜索引擎关键词优化有哪些技巧
  • 我是做网站怎么赚钱百度快速排名点击器
  • 游戏的网站策划应该怎么做做网站价格
  • 响应式网站开发公司安徽seo网络优化师
  • 做网站要注册商标门户网站排行榜
  • 软件开发和网站建设一样吗seo自动工具
  • 网站被很多公司抄袭百度官方电话24小时
  • 建设项目一次公示网站公司推广渠道有哪些
  • 网站模拟课堂模式应该怎么做google关键词排名优化
  • 哪个网站可以做服装批发衣服创建软件平台该怎么做
  • 网站seo谷歌长春网络科技公司排名
  • wordpress网站建设教程视频网站优化策略分析论文
  • 网站建设三站合一怎样做一个产品营销方案
  • 域名会影响网站排名吗免费自助建站模板
  • 和城乡建设部网站b站推广入口2023
  • 网站建设公司源码seo是怎么优化的
  • 建筑工程公司组织架构图成都seo外包
  • 网站建设公司做销售前景好不好?怎样做网站
  • 专做品牌的网站长沙做优化的公司
  • 中小学智慧校园建设平台网站郑州网络推广专业公司
  • 怎么做百度推广平台seo信息是什么
  • 做信息网站怎么赚钱日本积分榜最新排名