欢迎来到尧图网

客户服务 关于我们

您的位置:首页 > 文旅 > 旅游 > 【从0到1,训练大模型,从llama3开始】

【从0到1,训练大模型,从llama3开始】

2024/10/24 15:17:08 来源:https://blog.csdn.net/mars131458/article/details/140578664  浏览:    关键词:【从0到1,训练大模型,从llama3开始】

摘要:

随着大模型越来越多,大家肯定眼花缭乱。不知道选择哪个好,换句话说,不知道哪个才适合自己。
通过社长的实操:chatgpt3.5、gpt4、gpt4o、llama3、通义千问、豆包等大模型,总结是:大家都很好,都能一定程度上的帮助你。
不过怎么说呢,他们什么都懂,但是,什么都不精。
比如:我想写一个sql,他们都可能给你一个错误的版本,只有当你跑完,发现错误之后,告诉他们,他们才会意识到自己的错误,然后重新给你生成一个。这样就导致一个问题,你不敢真正意义上的相信他们。可能在让他们帮你写代码的时候,他们直接偷懒或者把重要的部分写错了,你完全不知道,真正上线的时候,已经晚了。
怎么样才能避免这个问题呢?
只能微调,通过庞大的数据量告诉他,你想要的答案,你想要的回答方式,你想要的是什么。。。

谷歌Colab

当真正想对模型进行微调的时候,你会发现,自己的电脑配置好像不够,可能勉强能够运行大模型,但是在对模型进行大数据量训练的时候,算力的支持上需要更高的性能硬件配置。
这种情况只有## 标题两种解决方案:
1、买更高配置的电脑
2、租用、借用可以进行这种效果的服务器
我们现在呢,就租用谷歌的colab吧。它每天都可以免费使用2小时以上,对进行简单大模型的训练上,算力勉强够了。

使用unsoth

GitHub地址:https://github.com/unslothai/unsloth
详细你可以看它的readme,简单点说,直接用他们的训练步骤,你就可以训练了。

首先,打开GitHub地址,找到你要训练的模型,然后点Start for free。
在这里插入图片描述
然后你可以看到一个谷歌Colab的文件,点击复制,会在你自己的colab上复制一份。
下面,我贴上我的,你们到时候,复制到自己的colab上,一步步使用就行了。
地址是:https://colab.research.google.com/drive/1ltGhvWMWJAMx986V1if9E6_WFD_pZclE#scrollTo=bDp0zNpwe6U_

装环境

%%capture
!pip install "unsloth[colab-new] @ git+https://github.com/unslothai/unsloth.git"
!pip install --no-deps "xformers<0.0.27" "trl<0.9.0" peft accelerate bitsandbytes

选择要训练的模型,可以从huggingface中选择

from unsloth import FastLanguageModel
import torch
max_seq_length = 2048 # Choose any! We auto support RoPE Scaling internally!
dtype = None # None for auto detection. Float16 for Tesla T4, V100, Bfloat16 for Ampere+
load_in_4bit = True # Use 4bit quantization to reduce memory usage. Can be False.# 4bit pre quantized models we support for 4x faster downloading + no OOMs.
fourbit_models = ["unsloth/mistral-7b-v0.3-bnb-4bit",      # New Mistral v3 2x faster!"unsloth/mistral-7b-instruct-v0.3-bnb-4bit","unsloth/llama-3-8b-bnb-4bit",           # Llama-3 15 trillion tokens model 2x faster!"unsloth/llama-3-8b-Instruct-bnb-4bit","unsloth/llama-3-70b-bnb-4bit","unsloth/Phi-3-mini-4k-instruct",        # Phi-3 2x faster!"unsloth/Phi-3-medium-4k-instruct","unsloth/mistral-7b-bnb-4bit","unsloth/gemma-7b-bnb-4bit","hfl/llama-3-chinese-8b-instruct-v3"# Gemma 2.2x faster!
] # More models at https://huggingface.co/unslothmodel, tokenizer = FastLanguageModel.from_pretrained(model_name = "hfl/llama-3-chinese-8b-instruct-v3",max_seq_length = max_seq_length,dtype = dtype,load_in_4bit = load_in_4bit,# token = "hf_...", # use one if using gated models like meta-llama/Llama-2-7b-hf
)

## 配置参数```bash
model = FastLanguageModel.get_peft_model(model,r = 16, # Choose any number > 0 ! Suggested 8, 16, 32, 64, 128target_modules = ["q_proj", "k_proj", "v_proj", "o_proj","gate_proj", "up_proj", "down_proj",],lora_alpha = 16,lora_dropout 

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com