--- license: apache-2.0 pipeline_tag: text-generation tags: - fp8 - quantized - llm-compressor - compressed-tensors - red hat base_model: - meta-llama/Llama-3.1-8B-Instruct --- # Llama-3.1-8B-Instruct-FP8-block ## Model Overview - **Model Architecture:** LlamaForCausalLM - **Input:** Text - **Output:** Text - **Model Optimizations:** - **Weight quantization:** FP8 - **Activation quantization:** FP8 - **Release Date:** - **Version:** 1.0 - **Model Developers:**: Red Hat Quantized version of [meta-llama/Llama-3.1-8B-Instruct](https://huggingface.co/meta-llama/Llama-3.1-8B-Instruct). ### Model Optimizations This model was obtained by quantizing the weights and activations of [meta-llama/Llama-3.1-8B-Instruct](https://huggingface.co/meta-llama/Llama-3.1-8B-Instruct) to FP8 data type. This optimization reduces the number of bits per parameter from 16 to 8, reducing the disk size and GPU memory requirements by approximately 50%. Only the weights and activations of the linear operators within transformers blocks of the language model are quantized. ## Deployment ### Use with vLLM 1. Initialize vLLM server: ``` vllm serve RedHatAI/Llama-3.1-8B-Instruct-FP8-block --tensor_parallel_size 1 ``` 2. Send requests to the server: ```python from openai import OpenAI # Modify OpenAI's API key and API base to use vLLM's API server. openai_api_key = "EMPTY" openai_api_base = "http://:8000/v1" client = OpenAI( api_key=openai_api_key, base_url=openai_api_base, ) model = "RedHatAI/Llama-3.1-8B-Instruct-FP8-block" messages = [ {"role": "user", "content": "Explain quantum mechanics clearly and concisely."}, ] outputs = client.chat.completions.create( model=model, messages=messages, ) generated_text = outputs.choices[0].message.content print(generated_text) ``` ## Creation This model was quantized using the [llm-compressor](https://github.com/vllm-project/llm-compressor) library as shown below.
Creation details ```python from transformers import AutoProcessor, LlamaForCausalLM from llmcompressor import oneshot from llmcompressor.modeling import replace_modules_for_calibration from llmcompressor.modifiers.quantization import QuantizationModifier MODEL_ID = "meta-llama/Llama-3.1-8B-Instruct" # Load model. model = LlamaForCausalLM.from_pretrained(MODEL_ID, dtype="auto") processor = AutoProcessor.from_pretrained(MODEL_ID) model = replace_modules_for_calibration(model) # Configure the quantization algorithm and scheme. # In this case, we: # * quantize the weights to fp8 with per-block quantization # * quantize the activations to fp8 with dynamic token activations recipe = QuantizationModifier( targets="Linear", scheme="FP8_BLOCK", ignore=["lm_head"], ) # Apply quantization. oneshot(model=model, recipe=recipe) # Save to disk in compressed-tensors format. SAVE_DIR = MODEL_ID.rstrip("/").split("/")[-1] + "-FP8-block" model.save_pretrained(SAVE_DIR) processor.save_pretrained(SAVE_DIR) ```
## Evaluation The model was evaluated on the OpenLLMv1 leaderboard task, using [lm-evaluation-harness](https://github.com/EleutherAI/lm-evaluation-harness), on reasoning tasks using [lighteval](https://github.com/huggingface/lighteval). [vLLM](https://docs.vllm.ai/en/stable/) was used for all evaluations.
Evaluation details **Openllm V1** ``` lm_eval \ --model vllm \ --model_args pretrained="RedHatAI/Llama-3.1-8B-Instruct-FP8-block",dtype=auto,add_bos_token=True,max_model_len=16384,tensor_parallel_size=1,gpu_memory_utilization=0.9,enable_chunked_prefill=True,trust_remote_code=True \ --tasks openllm \ --write_out \ --batch_size auto \ --show_config ``` **Openllm V2** ``` lm_eval \ --model vllm \ --model_args pretrained="RedHatAI/Llama-3.1-8B-Instruct-FP8-block",dtype=auto,add_bos_token=False,max_model_len=16384,tensor_parallel_size=1,gpu_memory_utilization=0.7,disable_log_stats=True,enable_chunked_prefill=True,trust_remote_code=True \ --tasks leaderboard \ --apply_chat_template \ --fewshot_as_multiturn \ --write_out \ --batch_size auto \ --show_config ``` **Coding Benchmarks** ``` evalplus.evaluate --model "RedHatAI/Llama-3.1-8B-Instruct-FP8-block" \ --dataset "humaneval" \ --backend vllm \ --tp 1 \ --greedy evalplus.evaluate --model "RedHatAI/Llama-3.1-8B-Instruct-FP8-block" \ --dataset "mbpp" \ --backend vllm \ --tp 1 \ --greedy ```
### Accuracy
Category Metric meta-llama/Llama-3.1-8B-Instruct RedHatAI/Llama-3.1-8B-Instruct-FP8-block Recovery (%)
OpenLLM V1 ARC-Challenge (Acc-Norm, 25-shot) 60.92 60.92 100.00
GSM8K (Strict-Match, 5-shot) 71.11 70.66 99.36
HellaSwag (Acc-Norm, 10-shot) 80.75 80.48 99.67
MMLU (Acc, 5-shot) 68.20 67.96 99.64
TruthfulQA (MC2, 0-shot) 54.54 54.18 99.34
Winogrande (Acc, 5-shot) 78.45 78.14 99.60
Average Score 69.00 68.72 99.59
OpenLLM V2 IFEval (Inst Level Strict Acc, 0-shot) 81.89 81.41 99.41
BBH (Acc-Norm, 3-shot) 50.70 50.96 100.51
Math-Hard (Exact-Match, 4-shot) 20.24 20.77 102.61
GPQA (Acc-Norm, 0-shot) 29.53 29.95 101.42
MUSR (Acc-Norm, 0-shot) 38.89 38.62 99.32
MMLU-Pro (Acc, 5-shot) 37.71 37.48 99.38
Average Score 43.16 43.20 100.09
Coding HumanEval pass@1 68.90 68.90 100.00
HumanEval+ pass@1 62.20 61.00 98.07
MBPP pass@1 67.70 71.40 105.47
MBPP+ pass@1 55.60 57.90 104.14