phi-4-FP8-dynamic
Model Overview
- Model Architecture: Phi3ForCausalLM
- Input: Text
- Output: Text
- Model Optimizations:
- Activation quantization: FP8
- Weight quantization: FP8
- Intended Use Cases: This model is designed to accelerate research on language models, for use as a building block for generative AI powered features. It provides uses for general purpose AI systems and applications (primarily in English) which require:
- Memory/compute constrained environments.
- Latency bound scenarios.
- Reasoning and logic.
- Out-of-scope: This model is not specifically designed or evaluated for all downstream purposes, thus:
- Developers should consider common limitations of language models as they select use cases, and evaluate and mitigate for accuracy, safety, and fairness before using within a specific downstream use case, particularly for high-risk scenarios.
- Developers should be aware of and adhere to applicable laws or regulations (including privacy, trade compliance laws, etc.) that are relevant to their use case, including the model’s focus on English.
- Nothing contained in this Model Card should be interpreted as or deemed a restriction or modification to the license the model is released under.
- Release Date: 03/03/2025
- Version: 1.0
- Model Developers: RedHat (Neural Magic)
Model Optimizations
This model was obtained by quantizing activation and weights of phi-4 to FP8 data type. This optimization reduces the number of bits used to represent weights and activations from 16 to 8, reducing GPU memory requirements (by approximately 50%) and increasing matrix-multiply compute throughput (by approximately 2x). Weight quantization also reduces disk size requirements by approximately 50%.
Only weights and activations of the linear operators within transformers blocks are quantized. Weights are quantized with a symmetric static per-channel scheme, whereas activations are quantized with a symmetric dynamic per-token scheme. The llm-compressor library is used for quantization.
Deployment
This model can be deployed efficiently using the vLLM backend, as shown in the example below.
from vllm import LLM, SamplingParams
from transformers import AutoTokenizer
model_id = "neuralmagic-ent/phi-4-FP8-dynamic"
number_gpus = 1
sampling_params = SamplingParams(temperature=0.7, top_p=0.8, max_tokens=256)
tokenizer = AutoTokenizer.from_pretrained(model_id)
messages = [
{"role": "user", "content": "Give me a short introduction to large language model."},
]
prompts = tokenizer.apply_chat_template(messages, tokenize=False)
llm = LLM(model=model_id, tensor_parallel_size=number_gpus)
outputs = llm.generate(prompts, sampling_params)
generated_text = outputs[0].outputs[0].text
print(generated_text)
vLLM aslo supports OpenAI-compatible serving. See the documentation for more details.
Creation
Creation details
This model was created with [llm-compressor](https://github.com/vllm-project/llm-compressor) by running the code snippet below.from transformers import AutoModelForCausalLM, AutoTokenizer
from llmcompressor.modifiers.quantization import QuantizationModifier
from llmcompressor.transformers import oneshot
# Load model
model_stub = "microsoft/phi-4"
model_name = model_stub.split("/")[-1]
tokenizer = AutoTokenizer.from_pretrained(model_stub)
model = AutoModelForCausalLM.from_pretrained(
model_stub,
device_map="auto",
torch_dtype="auto",
)
# Configure the quantization algorithm and scheme
recipe = QuantizationModifier(
targets="Linear",
scheme="FP8_dynamic",
ignore=["lm_head"],
)
# Apply quantization
oneshot(
model=model,
recipe=recipe,
)
# Save to disk in compressed-tensors format
save_path = model_name + "-FP8-dynamic"
model.save_pretrained(save_path)
tokenizer.save_pretrained(save_path)
print(f"Model and tokenizer saved to: {save_path}")
Evaluation
The model was evaluated on the OpenLLM leaderboard tasks (version 1) with the lm-evaluation-harness and the vLLM engine, using the following command:
lm_eval \
--model vllm \
--model_args pretrained="neuralmagic-ent/phi-4-FP8-dynamic",dtype=auto,gpu_memory_utilization=0.6,max_model_len=4096,enable_chunk_prefill=True,tensor_parallel_size=1 \
--tasks openllm \
--batch_size auto
Accuracy
Open LLM Leaderboard evaluation scores
Benchmark | phi-4 | phi-4-FP8-dynamic (this model) |
Recovery |
MMLU (5-shot) | 80.30 | 80.30 | 100.0% |
ARC Challenge (25-shot) | 64.42 | 64.25 | 99.7% |
GSM-8K (5-shot, strict-match) | 90.07 | 90.67 | 100.7% |
Hellaswag (10-shot) | 84.37 | 84.19 | 99.8% |
Winogrande (5-shot) | 80.58 | 79.87 | 99.1% |
TruthfulQA (0-shot, mc2) | 59.37 | 59.54 | 100.3% |
Average | 76.52 | 76.47 | 99.9% |
- Downloads last month
- 16
Model tree for RedHatAI/phi-4-FP8-dynamic
Base model
microsoft/phi-4