模型概述
模型特點
模型能力
使用案例
🚀 Llama-3.3-70B-Instruct-quantized.w8a8
這是 Llama-3.3-70B-Instruct 的量化版本模型,支持多語言文本生成,可用於商業和研究場景,在多個基準測試中表現出色。
🚀 快速開始
本模型可以使用 vLLM 後端進行高效部署,示例代碼如下:
from vllm import LLM, SamplingParams
from transformers import AutoTokenizer
model_id = "neuralmagic-ent/Llama-3.3-70B-Instruct-quantized.w8a8"
number_gpus = 1
max_model_len = 8192
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, add_generation_prompt=True, tokenize=False)
llm = LLM(model=model_id, tensor_parallel_size=number_gpus, max_model_len=max_model_len)
outputs = llm.generate(prompts, sampling_params)
generated_text = outputs[0].outputs[0].text
print(generated_text)
vLLM 還支持與 OpenAI 兼容的服務,更多詳細信息請參閱 文檔。
✨ 主要特性
- 多語言支持:支持英語、德語、法語、意大利語、葡萄牙語、印地語、西班牙語、泰語等多種語言。
- 量化優化:對權重和激活進行 INT8 量化,減少 GPU 內存需求(約 50%),提高矩陣乘法計算吞吐量(約 2 倍),同時磁盤大小需求也減少約 50%。
- 廣泛評估:在多個基準測試中進行了評估,如 OpenLLM v1、OpenLLM v2、HumanEval 和 HumanEval+,與未量化模型相比表現出色。
📦 安裝指南
本部分未提供具體的安裝命令,暫不展示安裝指南相關內容。
💻 使用示例
基礎用法
from vllm import LLM, SamplingParams
from transformers import AutoTokenizer
model_id = "neuralmagic-ent/Llama-3.3-70B-Instruct-quantized.w8a8"
number_gpus = 1
max_model_len = 8192
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, add_generation_prompt=True, tokenize=False)
llm = LLM(model=model_id, tensor_parallel_size=number_gpus, max_model_len=max_model_len)
outputs = llm.generate(prompts, sampling_params)
generated_text = outputs[0].outputs[0].text
print(generated_text)
高級用法
在不同平臺上部署模型的示例代碼:
在 Red Hat AI Inference Server 上部署
podman run --rm -it --device nvidia.com/gpu=all -p 8000:8000 \
--ipc=host \
--env "HUGGING_FACE_HUB_TOKEN=$HF_TOKEN" \
--env "HF_HUB_OFFLINE=0" -v ~/.cache/vllm:/home/vllm/.cache \
--name=vllm \
registry.access.redhat.com/rhaiis/rh-vllm-cuda \
vllm serve \
--tensor-parallel-size 8 \
--max-model-len 32768 \
--enforce-eager --model RedHatAI/Llama-3.3-70B-Instruct-quantized.w8a8
更多詳細信息請參閱 Red Hat AI Inference Server 文檔。
在 Red Hat Enterprise Linux AI 上部署
# 從 Red Hat Registry 通過 docker 下載模型
# 注意:除非指定 --model-dir,否則模型將下載到 ~/.cache/instructlab/models
ilab model download --repository docker://registry.redhat.io/rhelai1/llama-3-3-70b-instruct-quantized-w8a8:1.5
# 通過 ilab 提供模型服務
ilab model serve --model-path ~/.cache/instructlab/models/llama-3-3-70b-instruct-quantized-w8a8
# 與模型進行對話
ilab model chat --model ~/.cache/instructlab/models/llama-3-3-70b-instruct-quantized-w8a8
更多詳細信息請參閱 Red Hat Enterprise Linux AI 文檔。
在 Red Hat Openshift AI 上部署
# 使用 ServingRuntime 設置 vllm 服務器
# 保存為: vllm-servingruntime.yaml
apiVersion: serving.kserve.io/v1alpha1
kind: ServingRuntime
metadata:
name: vllm-cuda-runtime # 可選修改: 設置唯一名稱
annotations:
openshift.io/display-name: vLLM NVIDIA GPU ServingRuntime for KServe
opendatahub.io/recommended-accelerators: '["nvidia.com/gpu"]'
labels:
opendatahub.io/dashboard: 'true'
spec:
annotations:
prometheus.io/port: '8080'
prometheus.io/path: '/metrics'
multiModel: false
supportedModelFormats:
- autoSelect: true
name: vLLM
containers:
- name: kserve-container
image: quay.io/modh/vllm:rhoai-2.20-cuda # 如有需要可更改。如果是 AMD: quay.io/modh/vllm:rhoai-2.20-rocm
command:
- python
- -m
- vllm.entrypoints.openai.api_server
args:
- "--port=8080"
- "--model=/mnt/models"
- "--served-model-name={{.Name}}"
env:
- name: HF_HOME
value: /tmp/hf_home
ports:
- containerPort: 8080
protocol: TCP
# 將模型附加到 vllm 服務器。這是一個 NVIDIA 模板
# 保存為: inferenceservice.yaml
apiVersion: serving.kserve.io/v1beta1
kind: InferenceService
metadata:
annotations:
openshift.io/display-name: llama-3-3-70b-instruct-quantized-w8a8 # 可選修改
serving.kserve.io/deploymentMode: RawDeployment
name: llama-3-3-70b-instruct-quantized-w8a8 # 指定模型名稱。此值將用於在有效負載中調用模型
labels:
opendatahub.io/dashboard: 'true'
spec:
predictor:
maxReplicas: 1
minReplicas: 1
model:
modelFormat:
name: vLLM
name: ''
resources:
limits:
cpu: '2' # 這是特定於模型的
memory: 8Gi # 這是特定於模型的
nvidia.com/gpu: '1' # 這是特定於加速器的
requests: # 此塊同樣適用
cpu: '1'
memory: 4Gi
nvidia.com/gpu: '1'
runtime: vllm-cuda-runtime # 必須與上面的 ServingRuntime 名稱匹配
storageUri: oci://registry.redhat.io/rhelai1/modelcar-llama-3-3-70b-instruct-quantized-w8a8:1.5
tolerations:
- effect: NoSchedule
key: nvidia.com/gpu
operator: Exists
# 確保首先位於要部署模型的項目中
# oc project <項目名稱>
# 應用兩個資源以運行模型
# 應用 ServingRuntime
oc apply -f vllm-servingruntime.yaml
# 應用 InferenceService
oc apply -f qwen-inferenceservice.yaml
# 替換下面的 <推理服務名稱> 和 <集群入口域名>:
# - 如果不確定,請運行 `oc get inferenceservice` 查找您的 URL。
# 使用 curl 調用服務器:
curl https://<推理服務名稱>-predictor-default.<域名>/v1/chat/completions
-H "Content-Type: application/json" \
-d '{
"model": "llama-3-3-70b-instruct-quantized-w8a8 ",
"stream": true,
"stream_options": {
"include_usage": true
},
"max_tokens": 1,
"messages": [
{
"role": "user",
"content": "How can a bee fly when its wings are so small?"
}
]
}'
更多詳細信息請參閱 Red Hat Openshift AI 文檔。
📚 詳細文檔
模型概述
- 模型架構:Llama
- 輸入:文本
- 輸出:文本
- 模型優化:
- 激活量化:INT8
- 權重量化:INT8
- 預期用例:適用於多語言的商業和研究用途。與 Llama-3.3-70B-Instruct 類似,該模型旨在用於類似助手的聊天場景。
- 適用範圍外:禁止以任何違反適用法律法規(包括貿易合規法律)的方式使用。
- 發佈日期:2025 年 1 月 20 日
- 版本:1.0
- 模型開發者:Neural Magic
模型創建
本模型使用 llm-compressor 庫創建,示例代碼如下:
from transformers import AutoTokenizer, AutoModelForCausalLM
from datasets import Dataset
from llmcompressor.transformers import oneshot
from llmcompressor.modifiers.quantization import GPTQModifier
import random
model_id = "meta-llama/Meta-Llama-3.1-8B-Instruct"
num_samples = 1024
max_seq_len = 8192
tokenizer = AutoTokenizer.from_pretrained(model_id)
max_token_id = len(tokenizer.get_vocab()) - 1
input_ids = [[random.randint(0, max_token_id) for _ in range(max_seq_len)] for _ in range(num_samples)]
attention_mask = num_samples * [max_seq_len * [1]]
ds = Dataset.from_dict({"input_ids": input_ids, "attention_mask": attention_mask})
recipe = GPTQModifier(
targets="Linear",
scheme="W8A8",
ignore=["lm_head"],
dampening_frac=0.01,
)
model = SparseAutoModelForCausalLM.from_pretrained(
model_id,
device_map="auto",
)
oneshot(
model=model,
dataset=ds,
recipe=recipe,
max_seq_length=max_seq_len,
num_calibration_samples=num_samples,
)
model.save_pretrained("Llama-3.3-70B-Instruct-quantized.w8a8")
模型評估
本模型在知名的 OpenLLM v1、OpenLLM v2、HumanEval 和 HumanEval+ 基準測試中進行了評估。在所有情況下,模型輸出均使用 vLLM 引擎生成。
OpenLLM v1 和 v2 評估使用 Neural Magic 對 lm-evaluation-harness 的分支(llama_3.1_instruct 分支)進行。此版本的 lm-evaluation-harness 包含與 Meta-Llama-3.1-Instruct-evals 提示風格匹配的 MMLU、ARC-Challenge 和 GSM-8K 版本,以及對 OpenLLM v2 任務的一些修復。
HumanEval 和 HumanEval+ 評估使用 Neural Magic 對 EvalPlus 倉庫的分支進行。
準確性
類別 | 基準測試 | Llama-3.3-70B-Instruct | Llama-3.3-70B-Instruct-quantized.w8a8(本模型) | 恢復率 |
---|---|---|---|---|
OpenLLM v1 | MMLU (5-shot) | 81.60 | 81.19 | 99.5% |
OpenLLM v1 | MMLU (CoT, 0-shot) | 86.58 | 85.92 | 99.2% |
OpenLLM v1 | ARC Challenge (0-shot) | 49.23 | 48.04 | 97.6% |
OpenLLM v1 | GSM-8K (CoT, 8-shot, strict-match) | 94.16 | 94.01 | 99.8% |
OpenLLM v1 | Hellaswag (10-shot) | 86.49 | 86.47 | 100.0% |
OpenLLM v1 | Winogrande (5-shot) | 84.77 | 83.74 | 98.8% |
OpenLLM v1 | TruthfulQA (0-shot, mc2) | 62.75 | 63.09 | 99.5% |
OpenLLM v1 | 平均 | 77.94 | 77.49 | 99.4% |
OpenLLM v2 | MMLU-Pro (5-shot) | 51.89 | 51.59 | 99.7% |
OpenLLM v2 | IFEval (0-shot) | 90.89 | 90.68 | 99.4% |
OpenLLM v2 | BBH (3-shot) | 63.15 | 62.54 | 99.0% |
OpenLLM v2 | Math-lvl-5 (4-shot) | 0.17 | 0.00 | N/A |
OpenLLM v2 | GPQA (0-shot) | 46.10 | 46.44 | 100.8% |
OpenLLM v2 | MuSR (0-shot) | 44.35 | 44.34 | 100.0% |
OpenLLM v2 | 平均 | 49.42 | 49.27 | 99.7% |
編碼 | HumanEval pass@1 | 83.20 | 83.30 | 100.1% |
編碼 | HumanEval+ pass@1 | 78.40 | 78.60 | 100.3% |
多語言 | 葡萄牙語 MMLU (5-shot) | 79.76 | 79.47 | 99.6% |
多語言 | 西班牙語 MMLU (5-shot) | 79.33 | 79.23 | 99.9% |
多語言 | 意大利語 MMLU (5-shot) | 79.15 | 78.80 | 99.6% |
多語言 | 德語 MMLU (5-shot) | 77.94 | 77.92 | 100.0% |
多語言 | 法語 MMLU (5-shot) | 75.69 | 75.79 | 100.1% |
多語言 | 印地語 MMLU (5-shot) | 73.81 | 73.49 | 99.6% |
多語言 | 泰語 MMLU (5-shot) | 71.97 | 71.44 | 99.2% |
復現結果
使用以下命令可復現評估結果:
MMLU
lm_eval \
--model vllm \
--model_args pretrained="neuralmagic-ent/Llama-3.3-70B-Instruct-quantized.w8a8",dtype=auto,max_model_len=3850,max_gen_toks=10,tensor_parallel_size=1 \
--tasks mmlu_llama_3.1_instruct \
--fewshot_as_multiturn \
--apply_chat_template \
--num_fewshot 5 \
--batch_size auto
MMLU-CoT
lm_eval \
--model vllm \
--model_args pretrained="neuralmagic-ent/Llama-3.3-70B-Instruct-quantized.w8a8",dtype=auto,max_model_len=4064,max_gen_toks=1024,tensor_parallel_size=1 \
--tasks mmlu_cot_0shot_llama_3.1_instruct \
--apply_chat_template \
--num_fewshot 0 \
--batch_size auto
ARC-Challenge
lm_eval \
--model vllm \
--model_args pretrained="neuralmagic-ent/Llama-3.3-70B-Instruct-quantized.w8a8",dtype=auto,max_model_len=3940,max_gen_toks=100,tensor_parallel_size=1 \
--tasks arc_challenge_llama_3.1_instruct \
--apply_chat_template \
--num_fewshot 0 \
--batch_size auto
GSM-8K
lm_eval \
--model vllm \
--model_args pretrained="neuralmagic-ent/Llama-3.3-70B-Instruct-quantized.w8a8",dtype=auto,max_model_len=4096,max_gen_toks=1024,tensor_parallel_size=1 \
--tasks gsm8k_cot_llama_3.1_instruct \
--fewshot_as_multiturn \
--apply_chat_template \
--num_fewshot 8 \
--batch_size auto
Hellaswag
lm_eval \
--model vllm \
--model_args pretrained="neuralmagic-ent/Llama-3.3-70B-Instruct-quantized.w8a8",dtype=auto,add_bos_token=True,max_model_len=4096,tensor_parallel_size=1 \
--tasks hellaswag \
--num_fewshot 10 \
--batch_size auto
Winogrande
lm_eval \
--model vllm \
--model_args pretrained="neuralmagic-ent/Llama-3.3-70B-Instruct-quantized.w8a8",dtype=auto,add_bos_token=True,max_model_len=4096,tensor_parallel_size=1 \
--tasks winogrande \
--num_fewshot 5 \
--batch_size auto
TruthfulQA
lm_eval \
--model vllm \
--model_args pretrained="neuralmagic-ent/Llama-3.3-70B-Instruct-quantized.w8a8",dtype=auto,add_bos_token=True,max_model_len=4096,tensor_parallel_size=1 \
--tasks truthfulqa \
--num_fewshot 0 \
--batch_size auto
OpenLLM v2
lm_eval \
--model vllm \
--model_args pretrained="neuralmagic-ent/Llama-3.3-70B-Instruct-quantized.w8a8",dtype=auto,max_model_len=4096,tensor_parallel_size=1,enable_chunked_prefill=True \
--apply_chat_template \
--fewshot_as_multiturn \
--tasks leaderboard \
--batch_size auto
葡萄牙語 MMLU
lm_eval \
--model vllm \
--model_args pretrained="neuralmagic-ent/Llama-3.3-70B-Instruct-quantized.w8a8",dtype=auto,max_model_len=3850,max_gen_toks=10,tensor_parallel_size=1 \
--tasks mmlu_pt_llama_3.1_instruct \
--fewshot_as_multiturn \
--apply_chat_template \
--num_fewshot 5 \
--batch_size auto
西班牙語 MMLU
lm_eval \
--model vllm \
--model_args pretrained="neuralmagic-ent/Llama-3.3-70B-Instruct-quantized.w8a8",dtype=auto,max_model_len=3850,max_gen_toks=10,tensor_parallel_size=1 \
--tasks mmlu_es_llama_3.1_instruct \
--fewshot_as_multiturn \
--apply_chat_template \
--num_fewshot 5 \
--batch_size auto
意大利語 MMLU
lm_eval \
--model vllm \
--model_args pretrained="neuralmagic-ent/Llama-3.3-70B-Instruct-quantized.w8a8",dtype=auto,max_model_len=3850,max_gen_toks=10,tensor_parallel_size=1 \
--tasks mmlu_it_llama_3.1_instruct \
--fewshot_as_multiturn \
--apply_chat_template \
--num_fewshot 5 \
--batch_size auto
德語 MMLU
lm_eval \
--model vllm \
--model_args pretrained="neuralmagic-ent/Llama-3.3-70B-Instruct-quantized.w8a8",dtype=auto,max_model_len=3850,max_gen_toks=10,tensor_parallel_size=1 \
--tasks mmlu_de_llama_3.1_instruct \
--fewshot_as_multiturn \
--apply_chat_template \
--num_fewshot 5 \
--batch_size auto
法語 MMLU
lm_eval \
--model vllm \
--model_args pretrained="neuralmagic-ent/Llama-3.3-70B-Instruct-quantized.w8a8",dtype=auto,max_model_len=3850,max_gen_toks=10,tensor_parallel_size=1 \
--tasks mmlu_fr_llama_3.1_instruct \
--fewshot_as_multiturn \
--apply_chat_template \
--num_fewshot 5 \
--batch_size auto
印地語 MMLU
lm_eval \
--model vllm \
--model_args pretrained="neuralmagic-ent/Llama-3.3-70B-Instruct-quantized.w8a8",dtype=auto,max_model_len=3850,max_gen_toks=10,tensor_parallel_size=1 \
--tasks mmlu_hi_llama_3.1_instruct \
--fewshot_as_multiturn \
--apply_chat_template \
--num_fewshot 5 \
--batch_size auto
泰語 MMLU
lm_eval \
--model vllm \
--model_args pretrained="neuralmagic-ent/Llama-3.3-70B-Instruct-quantized.w8a8",dtype=auto,max_model_len=3850,max_gen_toks=10,tensor_parallel_size=1 \
--tasks mmlu_th_llama_3.1_instruct \
--fewshot_as_multiturn \
--apply_chat_template \
--num_fewshot 5 \
--batch_size auto
HumanEval 和 HumanEval+
生成
python3 codegen/generate.py \
--model neuralmagic-ent/Llama-3.3-70B-Instruct-quantized.w8a8 \
--bs 16 \
--temperature 0.2 \
--n_samples 50 \
--root "." \
--dataset humaneval
清理
python3 evalplus/sanitize.py \
humaneval/neuralmagic-ent--Llama-3.3-70B-Instruct-quantized.w8a8_vllm_temp_0.2
評估
evalplus.evaluate \
--dataset humaneval \
--samples humaneval/neuralmagic-ent--Llama-3.3-70B-Instruct-quantized.w8a8_vllm_temp_0.2-sanitized
🔧 技術細節
本模型通過將 Llama-3.3-70B-Instruct 的權重和激活量化為 INT8 數據類型獲得。這種優化將表示權重和激活所需的位數從 16 位減少到 8 位,從而減少了 GPU 內存需求(約 50%),並提高了矩陣乘法計算吞吐量(約 2 倍)。權重量化還使磁盤大小需求減少了約 50%。
僅對 Transformer 塊內線性算子的權重和激活進行量化。權重採用對稱靜態逐通道方案進行量化,即對每個輸出通道維度在 INT8 和浮點表示之間應用固定的線性縮放因子。激活採用對稱動態逐樣本方案進行量化,即在運行時為每個樣本計算 INT8 和浮點表示之間的線性縮放因子。
📄 許可證
本模型使用的許可證為 llama3.3。
📋 模型信息
屬性 | 詳情 |
---|---|
模型類型 | Llama |
基礎模型 | meta-llama/Llama-3.3-70B-Instruct |
支持語言 | 英語、德語、法語、意大利語、葡萄牙語、印地語、西班牙語、泰語 |
許可證 | llama3.3 |



