🚀 Meta-Llama-3-70B-Instruct-FP8
Meta-Llama-3-70B-Instruct-FP8 是 Meta-Llama-3-70B-Instruct 的量化版本,通过将权重和激活量化为 FP8 数据类型,在减少磁盘大小和 GPU 内存需求的同时,仍能在基准测试中保持较高的性能,适用于英文的商业和研究用途。
🚀 快速开始
使用 vLLM 进行部署
此模型可以使用 vLLM 后端高效部署,示例代码如下:
from vllm import LLM, SamplingParams
from transformers import AutoTokenizer
model_id = "neuralmagic/Meta-Llama-3-70B-Instruct-FP8"
sampling_params = SamplingParams(temperature=0.6, top_p=0.9, max_tokens=256)
tokenizer = AutoTokenizer.from_pretrained(model_id)
messages = [
{"role": "system", "content": "You are a pirate chatbot who always responds in pirate speak!"},
{"role": "user", "content": "Who are you?"},
]
prompts = tokenizer.apply_chat_template(messages, tokenize=False)
llm = LLM(model=model_id)
outputs = llm.generate(prompts, sampling_params)
generated_text = outputs[0].outputs[0].text
print(generated_text)
vLLM 还支持与 OpenAI 兼容的服务。更多详细信息请参阅 文档。
✨ 主要特性
模型概述
- 模型架构:Meta-Llama-3
- 模型优化:
- 预期用例:适用于英文的商业和研究用途。与 Meta-Llama-3-70B-Instruct 类似,该模型旨在用于类似助手的聊天场景。
- 不适用范围:以任何违反适用法律法规(包括贸易合规法律)的方式使用。用于英文以外的语言。
- 发布日期:2024 年 6 月 8 日
- 版本:1.0
- 许可证:Llama3
- 模型开发者:Neural Magic
该模型是 Meta-Llama-3-70B-Instruct 的量化版本。在 OpenLLM 基准测试(版本 1)中,它的平均得分为 79.16,而未量化的模型得分为 79.51。
模型优化
此模型通过将 Meta-Llama-3-70B-Instruct 的权重和激活量化为 FP8 数据类型获得,可用于 vLLM >= 0.5.0 进行推理。这种优化将每个参数的位数从 16 位减少到 8 位,使磁盘大小和 GPU 内存需求大约减少 50%。
仅对 Transformer 块内线性算子的权重和激活进行量化。采用对称的逐张量量化,其中单个线性缩放映射量化权重和激活的 FP8 表示。使用 AutoFP8 对 512 个 UltraChat 序列进行量化。
模型创建
该模型通过应用 使用来自 ultrachat 的校准样本的 AutoFP8 创建,代码示例如下:
from datasets import load_dataset
from transformers import AutoTokenizer
from auto_fp8 import AutoFP8ForCausalLM, BaseQuantizeConfig
pretrained_model_dir = "meta-llama/Meta-Llama-3-70B-Instruct"
quantized_model_dir = "Meta-Llama-3-70B-Instruct-FP8"
tokenizer = AutoTokenizer.from_pretrained(pretrained_model_dir, use_fast=True, model_max_length=4096)
tokenizer.pad_token = tokenizer.eos_token
ds = load_dataset("mgoin/ultrachat_2k", split="train_sft").select(range(512))
examples = [tokenizer.apply_chat_template(batch["messages"], tokenize=False) for batch in ds]
examples = tokenizer(examples, padding=True, truncation=True, return_tensors="pt").to("cuda")
quantize_config = BaseQuantizeConfig(
quant_method="fp8",
activation_scheme="dynamic",
ignore_patterns=["re:.*lm_head"],
)
model = AutoFP8ForCausalLM.from_pretrained(
pretrained_model_dir, quantize_config=quantize_config
)
model.quantize(examples)
model.save_quantized(quantized_model_dir)
虽然此特定模型使用了 AutoFP8,但 Neural Magic 正在过渡到使用 llm-compressor,它支持多种量化方案和 AutoFP8 不支持的模型。
模型评估
该模型在 OpenLLM 排行榜任务(版本 1)上使用 lm-evaluation-harness(提交版本 383bbd54bc621086e05aa1b030d8d4d5635b25e6)和 vLLM 引擎进行评估,使用以下命令:
lm_eval \
--model vllm \
--model_args pretrained="neuralmagic/Meta-Llama-3-70B-Instruct-FP8",dtype=auto,gpu_memory_utilization=0.4,add_bos_token=True,max_model_len=4096 \
--tasks openllm \
--batch_size auto
准确率
Open LLM 排行榜评估分数
基准测试 |
Meta-Llama-3-70B-Instruct |
Meta-Llama-3-70B-Instruct-FP8(本模型) |
恢复率 |
MMLU (5-shot) |
80.18 |
80.06 |
99.85% |
ARC Challenge (25-shot) |
72.69 |
72.61 |
99.88% |
GSM-8K (5-shot, strict-match) |
92.49 |
91.12 |
98.51% |
Hellaswag (10-shot) |
85.50 |
85.41 |
99.89% |
Winogrande (5-shot) |
83.34 |
83.03 |
99.62% |
TruthfulQA (0-shot) |
62.90 |
62.73 |
99.72% |
平均 |
79.51 |
79.16 |
99.55% |
📄 许可证
本模型使用 Llama3 许可证。