Training Verifiers to Solve Math Word Problems
Paper • 2110.14168 • Published • 7
How to use RedHatAI/Meta-Llama-3-70B-Instruct-FP8-KV with Transformers:
# Use a pipeline as a high-level helper
from transformers import pipeline
pipe = pipeline("text-generation", model="RedHatAI/Meta-Llama-3-70B-Instruct-FP8-KV")
messages = [
{"role": "user", "content": "Who are you?"},
]
pipe(messages) # Load model directly
from transformers import AutoTokenizer, AutoModelForCausalLM
tokenizer = AutoTokenizer.from_pretrained("RedHatAI/Meta-Llama-3-70B-Instruct-FP8-KV")
model = AutoModelForCausalLM.from_pretrained("RedHatAI/Meta-Llama-3-70B-Instruct-FP8-KV")
messages = [
{"role": "user", "content": "Who are you?"},
]
inputs = tokenizer.apply_chat_template(
messages,
add_generation_prompt=True,
tokenize=True,
return_dict=True,
return_tensors="pt",
).to(model.device)
outputs = model.generate(**inputs, max_new_tokens=40)
print(tokenizer.decode(outputs[0][inputs["input_ids"].shape[-1]:]))How to use RedHatAI/Meta-Llama-3-70B-Instruct-FP8-KV with vLLM:
# Install vLLM from pip:
pip install vllm
# Start the vLLM server:
vllm serve "RedHatAI/Meta-Llama-3-70B-Instruct-FP8-KV"
# Call the server using curl (OpenAI-compatible API):
curl -X POST "http://localhost:8000/v1/chat/completions" \
-H "Content-Type: application/json" \
--data '{
"model": "RedHatAI/Meta-Llama-3-70B-Instruct-FP8-KV",
"messages": [
{
"role": "user",
"content": "What is the capital of France?"
}
]
}'docker model run hf.co/RedHatAI/Meta-Llama-3-70B-Instruct-FP8-KV
How to use RedHatAI/Meta-Llama-3-70B-Instruct-FP8-KV with SGLang:
# Install SGLang from pip:
pip install sglang
# Start the SGLang server:
python3 -m sglang.launch_server \
--model-path "RedHatAI/Meta-Llama-3-70B-Instruct-FP8-KV" \
--host 0.0.0.0 \
--port 30000
# Call the server using curl (OpenAI-compatible API):
curl -X POST "http://localhost:30000/v1/chat/completions" \
-H "Content-Type: application/json" \
--data '{
"model": "RedHatAI/Meta-Llama-3-70B-Instruct-FP8-KV",
"messages": [
{
"role": "user",
"content": "What is the capital of France?"
}
]
}'docker run --gpus all \
--shm-size 32g \
-p 30000:30000 \
-v ~/.cache/huggingface:/root/.cache/huggingface \
--env "HF_TOKEN=<secret>" \
--ipc=host \
lmsysorg/sglang:latest \
python3 -m sglang.launch_server \
--model-path "RedHatAI/Meta-Llama-3-70B-Instruct-FP8-KV" \
--host 0.0.0.0 \
--port 30000
# Call the server using curl (OpenAI-compatible API):
curl -X POST "http://localhost:30000/v1/chat/completions" \
-H "Content-Type: application/json" \
--data '{
"model": "RedHatAI/Meta-Llama-3-70B-Instruct-FP8-KV",
"messages": [
{
"role": "user",
"content": "What is the capital of France?"
}
]
}'How to use RedHatAI/Meta-Llama-3-70B-Instruct-FP8-KV with Docker Model Runner:
docker model run hf.co/RedHatAI/Meta-Llama-3-70B-Instruct-FP8-KV
Meta-Llama-3-70B-Instruct quantized to FP8 weights and activations using per-tensor quantization, ready for inference with vLLM >= 0.5.0.
This model checkpoint also includes per-tensor scales for FP8 quantized KV Cache, accessed through the --kv-cache-dtype fp8 argument in vLLM.
from vllm import LLM
model = LLM(model="neuralmagic/Meta-Llama-3-70B-Instruct-FP8-KV", kv_cache_dtype="fp8")
result = model.generate("Hello, my name is")
Produced using AutoFP8 with calibration samples from ultrachat.
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-KV"
tokenizer = AutoTokenizer.from_pretrained(pretrained_model_dir, use_fast=True)
tokenizer.pad_token = tokenizer.eos_token
ds = load_dataset("mgoin/ultrachat_2k", split="train_sft")
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="static",
ignore_patterns=["re:.*lm_head"],
kv_cache_quant_targets=("k_proj", "v_proj"),
)
model = AutoFP8ForCausalLM.from_pretrained(pretrained_model_dir, quantize_config)
model.quantize(examples)
model.save_quantized(quantized_model_dir)
Model evaluation results obtained via lm-evaluation-harness.
| Benchmark | Meta-Llama-3-70B-Instruct | Meta-Llama-3-70B-Instruct-FP8 | Meta-Llama-3-70B-Instruct-FP8-KV (this model) |
|---|---|---|---|
| ARC-c 25-shot |
72.69 | 72.61 | 72.57 |
| HellaSwag 10-shot |
85.50 | 85.41 | 85.32 |
| MMLU 5-shot |
80.18 | 80.06 | 79.69 |
| TruthfulQA 0-shot |
62.90 | 62.73 | 61.92 |
| WinoGrande 5-shot |
83.34 | 83.03 | 83.66 |
| GSM8K 5-shot |
92.49 | 91.12 | 90.83 |
| Average Accuracy |
79.51 | 79.16 | 79.00 |
| Recovery | 100% | 99.55% | 99.36% |