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

阿里云做淘宝客网站宝塔建设网站

阿里云做淘宝客网站,宝塔建设网站,云南发布紧急通知,电商建网站运营本文将介绍两种开源工具来微调LLAMA-2。 一、使用autotrain-advanced微调LLAMA-2 AutoTrain是一种无代码工具#xff0c;用于为自然语言处理#xff08;NLP#xff09;任务、计算机视觉#xff08;CV#xff09;任务、语音任务甚至表格任务训练最先进的模型。 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 huggingface​from 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_dataset​dataset_name timdettmers/openassistant-guanaco​dataset load_dataset(dataset_name, splittrain) 3量化配置从Huggingface下载模型 import torchfrom transformers import AutoModelForCausalLM, AutoTokenizer, BitsAndBytesConfig​​# quantizition configurationbnb_config BitsAndBytesConfig( load_in_4bitTrue, bnb_4bit_quant_typenf4, bnb_4bit_compute_dtypetorch.float16,)​​# download model​model_name TinyPixel/Llama-2-7B-bf16-shardedmodel AutoModelForCausalLM.from_pretrained( model_name, quantization_configbnb_config, trust_remote_codeTrue)model.config.use_cache False 4下载Tokenizer tokenizer AutoTokenizer.from_pretrained(model_name, trust_remote_codeTrue)tokenizer.pad_token tokenizer.eos_token 5创建PEFT配置 from peft import LoraConfig, get_peft_model​lora_alpha 16lora_dropout 0.1lora_r 64​peft_config LoraConfig( lora_alphalora_alpha, lora_dropoutlora_dropout, rlora_r, biasnone, task_typeCAUSAL_LM) 6创建微调和训练配置 from transformers import TrainingArguments​output_dir ./resultsper_device_train_batch_size 4gradient_accumulation_steps 4optim paged_adamw_32bitsave_steps 100logging_steps 10learning_rate 2e-4max_grad_norm 0.3max_steps 100warmup_ratio 0.03lr_scheduler_type constant​training_arguments TrainingArguments( output_diroutput_dir, per_device_train_batch_sizeper_device_train_batch_size, gradient_accumulation_stepsgradient_accumulation_steps, optimoptim, save_stepssave_steps, logging_stepslogging_steps, learning_ratelearning_rate, fp16True, max_grad_normmax_grad_norm, max_stepsmax_steps, warmup_ratiowarmup_ratio, group_by_lengthTrue, lr_scheduler_typelr_scheduler_type,) 7创建SFTTrainer配置 from trl import SFTTrainer​max_seq_length 512​trainer SFTTrainer( modelmodel, train_datasetdataset, peft_configpeft_config, dataset_text_fieldtext, max_seq_lengthmax_seq_length, tokenizertokenizer, argstraining_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_tensorspt).to(device)outputs tuned_model.generate(**inputs, max_new_tokens50)print(tokenizer.decode(outputs[0], skip_special_tokensTrue)) 参考文献 [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?uspsharing [3] https://colab.research.google.com/drive/1ctevXhrE60s7o9RzsxpIqq37EjyU9tBn?uspsharing#scrollTobsbdrb5p2ONa
http://www.dnsts.com.cn/news/198399.html

相关文章:

  • 有没有代做模型的网站长春服务好的网站建设
  • 广州网站建设商城辽宁建设工程信息网盲盒
  • 做品牌折扣的网站广州冼村租房
  • 科技企业网站设计制作微信音乐做mp3下载网站
  • 鲜花网站有关建设建设网站江西
  • 古典网站建设公司网站建设制作设计开发
  • 站长统计工具山西城乡和住房建设厅网站首页
  • 网站推广产品怎么做网站制作公司挣钱吗
  • 甘孜州建设局网站组态王如何做网站链接
  • 手机网站app制作wordpress3.7.1下载
  • 网站建设cz35上海开艺设计集团有限公司
  • 深圳辰硕网站优化广西住建厅八大员报名网站
  • 美橙西安网站备案拍照衡水精品网站建设报价
  • 信用网站建设意见怀化网站建设公司
  • 做网站放网站广告wordpress无邮箱评论
  • 做网站销售大概多少钱怎样给公司产品做网站
  • 赣州建设网站有哪些付费wordpress
  • 用wordpress建立学校网站哪个网站是用vue做的
  • 企业网站建设合同模板网站建设用阿里云的虚拟主机
  • 自己可以建设环保公益网站吗哪里学网站建设推广
  • 静态网站 价格某购物网站开发项目
  • 昆明网站建设猫咪企业排名优化公司
  • 温州市网站优化成都seo公司
  • 个人备案公司网站怎样做不用备案的网站
  • 北京兼职做网站建设深圳英文网站建设专业公司
  • 网上做调查问卷赚钱的网站传媒公司制作网站
  • wordpress多站点是什么意思wordpress 抄袭查询
  • 鹰潭网站商城建设建设银行鹤岗分行网站
  • 上海网站建设服务站霸网络产品外观设计案例
  • 标题制作网站网站框架怎么做的