模型简介
模型特点
模型能力
使用案例
🚀 Llama-3-6B模型
本项目推出了全球首个具有60亿参数的Llama-3基础模型。该模型是prince-canuma/Llama-3-6B-v0的预训练版本,它采用了一种名为降阶循环(downcycling)的技术,从Meta-Llama-3-8B创建而来。该模型在来自fineweb的10亿个英文文本标记上进行了持续预训练,在评估集上取得了令人瞩目的成果:
- 损失率:2.4942
🚀 快速开始
使用以下代码开始使用该模型:
from transformers import AutoModelForCausalLM, AutoConfig, AutoTokenizer
# 加载模型、配置和分词器
model_name = "prince-canuma/Llama-3-6B-v0.1"
model = AutoModelForCausalLM.from_pretrained(model_name)
tokenizer = AutoTokenizer.from_pretrained(model_name)
inputs = tokenizer(
[
"Who created Python?"
], return_tensors = "pt")
from transformers import TextStreamer
text_streamer = TextStreamer(tokenizer)
_ = model.generate(**inputs, streamer = text_streamer, max_new_tokens = 200)
输出:
<|begin_of_text|>Who created Python? What is Python used for? What is the difference between Python 2 and Python 3? What is the difference between Python and Python 3?
Python is a programming language that was created by Guido van Rossum in 1991. It is a widely used language for web development, data science, and machine learning. Python is also used for creating software applications and games.
Python is a powerful language that is easy to learn and use. It has a large library of built-in functions and packages that make it easy to write code. Python is also a very popular language for web development, with many popular web frameworks such as Django and Flask being written in Python.
Python is also used for data science and machine learning. It has a large library of packages for data analysis, machine learning, and artificial intelligence. Python is also used for creating software applications and games.
Python 2 and Python 3 are two different versions of the Python language. Python 2 was the original version of the
✨ 主要特性
- 基于Llama-3架构,具有60亿参数,在英文文本任务上表现出色。
- 通过降阶循环技术,从Llama-3-8B创建而来,可进一步进行预训练和微调。
- 可用于多种自然语言处理任务,如编码辅助、检索增强生成(RAG)、函数调用等。
📦 安装指南
文档未提及安装步骤,故跳过该章节。
💻 使用示例
基础用法
from transformers import AutoModelForCausalLM, AutoConfig, AutoTokenizer
# 加载模型、配置和分词器
model_name = "prince-canuma/Llama-3-6B-v0.1"
model = AutoModelForCausalLM.from_pretrained(model_name)
tokenizer = AutoTokenizer.from_pretrained(model_name)
inputs = tokenizer(
[
"Who created Python?"
], return_tensors = "pt")
from transformers import TextStreamer
text_streamer = TextStreamer(tokenizer)
_ = model.generate(**inputs, streamer = text_streamer, max_new_tokens = 200)
高级用法
文档未提及高级用法示例,故跳过该部分。
📚 详细文档
模型描述
这是一个🤗 Transformers模型的模型卡片,已推送到Hugging Face Hub。该模型卡片是自动生成的。
- 开发者:Prince Canuma
- 赞助方:General
- 模型类型:Llama
- 许可证:Llama-3
- 预训练基础模型:prince-canuma/Llama-3-6B-v0
模型来源
- 仓库:https://github.com/Blaizzy/Coding-LLMs-from-scratch/tree/main/Llama-3
- 视频:https://youtube.com/playlist?list=PLDn_JsyofyfTH5_5V1MNb8UYKxMl6IMNy&si=5Y4cm-6wrMOD1Abr
用途
你可以使用此模型创建指令和聊天版本,用于各种用例,如编码助手、检索增强生成(RAG)、函数调用等。
局限性
该模型继承了基础模型的一些局限性,以及在创建过程中产生的一些额外局限性,例如:
- 编码和数学能力有限:根据基准测试,该模型需要在代码和数学数据上进行更多的预训练/微调,才能在推理任务中表现出色。
- 语言局限性:该模型仅在英文数据上进行了持续预训练。如果计划将其用于多语言用例,建议进行微调或继续预训练。
🔧 技术细节
降阶循环
图1. 降阶循环工作流,详情见arxiv.org/abs/2404.08634。
降阶循环是一种允许从大型预训练模型的检查点创建不同大小的新大语言模型(LLM)的技术。具体做法是,选取一个参考模型(如Llama-3-8B),复制其32层中的24层的权重,以及嵌入层和预测头的权重。然后,初始化一个具有24层的较小目标模型,并加载这些预训练权重。
这个新模型很可能仍然能够输出清晰可读的内容,但要使其表现良好,需要继续进行预训练。
图2. 未继续预训练的降阶模型与参考模型对比。
训练数据
为了进行持续预训练,从Huggingface的FineWeb CC-Main-2024-10切片中提取了10亿个标记。
训练超参数
训练过程中使用了以下超参数:
属性 | 详情 |
---|---|
学习率 | 0.0002 |
训练批次大小 | 2 |
评估批次大小 | 2 |
随机种子 | 42 |
分布式类型 | 多GPU |
设备数量 | 4 |
梯度累积步数 | 8 |
总训练批次大小 | 64 |
总评估批次大小 | 8 |
优化器 | Adam(β1=0.9,β2=0.999,ε=1e-08) |
学习率调度器类型 | 余弦 |
学习率调度器热身步数 | 100 |
训练轮数 | 2 |
查看Axolotl配置
Axolotl版本:0.4.0
base_model: prince-canuma/Llama-3-6B-v0.1
model_type: AutoModelForCausalLM
tokenizer_type: AutoTokenizer
load_in_8bit: false
load_in_4bit: true
strict: false
datasets:
- path: prince-canuma/fineweb-CC-MAIN-2024-10-1B-en
type: completion
split: train
dataset_prepared_path: last_run_prepared
val_set_size: 0.001
output_dir: ./llama-3-6b
save_safetensors: true
adapter: qlora
lora_model_dir:
sequence_len: 8192
sample_packing: false
pad_to_sequence_len: false
lora_r: 128
lora_alpha: 128
lora_dropout: 0.05
lora_target_modules:
lora_target_linear: true
lora_fan_in_fan_out:
wandb_project: llama-3-6b
wandb_entity:
wandb_watch:
wandb_name:
wandb_log_model:
gradient_accumulation_steps: 8
micro_batch_size: 2
num_epochs: 2
optimizer: paged_adamw_32bit
lr_scheduler: cosine
learning_rate: 2e-4
train_on_inputs: false
group_by_length: false
bf16: auto
fp16:
tf32: false
gradient_checkpointing: true
early_stopping_patience:
resume_from_checkpoint:
local_rank:
logging_steps: 1
xformers_attention:
flash_attention: true
warmup_steps: 100
evals_per_epoch: 4
eval_table_size:
save_steps: 4000
debug:
deepspeed:
weight_decay: 0.0
fsdp:
fsdp_config:
special_tokens:
pad_token: "<|reserved_special_token_0|>"
训练结果
进行了3次不同的实验。由于预算限制,在这些实验中使用了QLoRA而不是全量微调。
- v0:进行了1000步的测试,以检查模型在QLoRA参数下是否会有所改进。
- v1:调整了QLoRA参数(秩和α)。
- v2:这是主要实验,在FineWeb的10亿个标记上进行了2个轮次的训练。
所有详细信息可在我的Wandb仪表盘上找到:https://wandb.ai/prince-canuma/llama-3-6b?nw=nwuserprincecanuma
 图3. Wandb上的实验训练损失图表。
总体指标:
训练损失 | 轮次 | 步数 | 验证损失 |
---|---|---|---|
7.1562 | 0.0 | 1 | 7.1806 |
2.7339 | 0.25 | 5867 | 2.6266 |
2.6905 | 0.5 | 11734 | 2.5872 |
2.6134 | 0.75 | 17601 | 2.5549 |
2.532 | 1.0 | 23468 | 2.5235 |
2.5319 | 1.25 | 29335 | 2.5067 |
2.3336 | 1.5 | 35202 | 2.4968 |
2.3486 | 1.75 | 41069 | 2.4942 |
框架版本
- PEFT 0.10.0
- Transformers 4.40.0.dev0
- Pytorch 2.2.0+cu121
- Datasets 2.15.0
- Tokenizers 0.15.0
硬件
- 使用JarvisLabs的4块RTX6000显卡(由General Catalyst赞助,感谢Viet)
评估
基准测试
- Hellaswag:用于研究基于常识的推理的数据集。
- ARC:来自3至9年级科学考试的多项选择题问答数据集。
- MMLU:包含57项任务的测试,用于衡量文本模型的多任务准确性。
- TruthfulQA:用于衡量模型传播网上常见虚假信息倾向的测试。
- Winogrande:用于常识推理。
- GSM8k:多样化的小学算术应用题,用于衡量模型解决多步数学推理问题的能力。
结果
图4. Llama-3-8B、Llama-3-6B和Llama-3-6B(持续预训练)的性能比较。
在10亿个标记上进行2个轮次的预训练在各个方面都产生了积极影响。新的基础模型现在与参考模型(Llama-3-8B)具有竞争力,同时体积小了1.3倍。
图5. Llama-3-8B、Llama-2-13B、Yi-1.5-6B和Llama-3-6B的性能比较。
Llama-3-6B在其类别内的模型中具有竞争力,并且在6个不同的基准测试中,与自身大小2倍的模型相比也不逊色。
总结与未来方向
本次实验取得了成功!使用这种技术,我将能够构建许多变体。这是我计划创建的众多新基础模型中的第一个。
接下来,我计划探索不同的数据混合方式,并进行全量微调,所有这些都将有助于开发其他小型模型以及更大、更强大的模型。
📄 许可证
本模型使用Llama-3许可证。
引用
BibTeX
@misc{prince2024downcycling,
title={Efficient LLM Downcycling: Generating Diverse Model Sizes from Pretrained Giants},
author={Prince Canuma},
year={2024},
}
参考文献
@misc{komatsuzaki2023sparse,
title={Sparse Upcycling: Training Mixture-of-Experts from Dense Checkpoints},
author={Aran Komatsuzaki and Joan Puigcerver and James Lee-Thorp and Carlos Riquelme Ruiz and Basil Mustafa and Joshua Ainslie and Yi Tay and Mostafa Dehghani and Neil Houlsby},
year={2023},
eprint={2212.05055},
archivePrefix={arXiv},
primaryClass={cs.LG}
}
@misc{sanyal2024pretraining,
title={Pre-training Small Base LMs with Fewer Tokens},
author={Sunny Sanyal and Sujay Sanghavi and Alexandros G. Dimakis},
year={2024},
eprint={2404.08634},
archivePrefix={arXiv},
primaryClass={cs.CL}
}
致谢
我衷心感谢社区提供的宝贵专业知识和坚定支持。
此外,我要感谢General Catalyst(GC)的Viet为我提供了急需的计算资源。
这是我迄今为止最具雄心的项目,如果没有出色的开源机器学习社区,这是不可能实现的!
开发者们,我期待看到并听到你们创建的创新微调模型和应用程序。
用户们,我很高兴了解你们的使用体验和用例。
感谢你们的关注和支持!



