Llama-4-Maverick-17B-128E-Instruct-NVFP4
Model Overview
- Model Architecture: Meta-Llama-3.1
- Input: Text / Image
- Output: Text
- Model Optimizations:
- Weight quantization: FP4
- Activation quantization: FP4
- Intended Use Cases: Intended for commercial and research use in multiple languages.
- Out-of-scope: Use in any manner that violates applicable laws or regulations (including trade compliance laws). Use in languages other than English.
- Release Date: 10/29/25
- Version: 1.0
- License(s): llama3.1
- Model Developers: RedHatAI
This model is a quantized version of Llama-4-Maverick-17B-128E-Instruct. It was evaluated on a several tasks to assess the its quality in comparison to the unquatized model.
Model Optimizations
This model was obtained by quantizing the weights and activations of Llama-4-Maverick-17B-128E-Instruct to FP4 data type, ready for inference with vLLM>=0.9.1 This optimization reduces the number of bits per parameter from 16 to 4, reducing the disk size and GPU memory requirements by approximately 25%.
Only the weights of the linear operators within transformers blocks are quantized using LLM Compressor.
Deployment
Use with vLLM
This model can be deployed efficiently using the vLLM backend, as shown in the example below.
Model Usage Code
from vllm import LLM, SamplingParams
from transformers import AutoTokenizer
model_id = "RedHatAI/Llama-4-Maverick-17B-128E-Instruct-NVFP4"
number_gpus = 2
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)
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
This model was created by applying LLM Compressor with calibration samples from neuralmagic/calibration dataset, as presented in the code snipet below.
Model Creation Code
from transformers import Llama4ForConditionalGeneration, Llama4Processor
from llmcompressor import oneshot
from llmcompressor.modifiers.quantization import QuantizationModifier
from llmcompressor.modeling.prepare import replace_modules_for_calibration
from datasets import load_dataset
import torch
import gc
# --- Load model ---
model_id = "meta-llama/Llama-4-Maverick-17B-128E-Instruct"
model = Llama4ForConditionalGeneration.from_pretrained(
model_id, torch_dtype="auto", device_map=None
)
processor = Llama4Processor.from_pretrained(model_id)
# --- Patch MoE layers to run all experts during calibration ---
model = replace_modules_for_calibration(model, calibrate_all_experts=True)
# Oneshot arguments
DATASET_ID = "neuralmagic/calibration"
NUM_CALIBRATION_SAMPLES = 512
MAX_SEQUENCE_LENGTH = 2048
ds = load_dataset(DATASET_ID, name="LLM", split=f"train[:{NUM_CALIBRATION_SAMPLES}]")
def preprocess_function(example):
messgages = []
for message in example["messages"]:
messgages.append(
{
"role": message["role"],
"content": [{"type": "text", "text": message["content"]}]
}
)
return processor.apply_chat_template(
messgages,
return_tensors="pt",
padding=False,
truncation=True,
max_length=MAX_SEQUENCE_LENGTH,
tokenize=True,
add_special_tokens=False,
return_dict=True,
add_generation_prompt=False,
)
ds = ds.map(
preprocess_function,
batched=False,
remove_columns=ds.column_names
)
# Define a oneshot data collator for multimodal inputs.
def data_collator(batch):
assert len(batch) == 1
return {
key: torch.tensor(value) if key != "pixel_values" else torch.tensor(value, dtype=torch.bfloat16).squeeze(0)
for key, value in batch[0].items()
}
recipe = QuantizationModifier(targets="Linear", scheme="NVFP4",
ignore=[
're:.*lm_head',
're:.*self_attn',
're:.*router',
're:.*vision_model',
're:.*multi_modal_projector',
"Llama4TextAttention",
],
)
MODEL_ID.rstrip("/").split("/")[-1] + "-NVFP4"
# Perform oneshot
oneshot(
model=model,
tokenizer=model_id,
dataset=ds,
recipe=recipe,
max_seq_length=MAX_SEQUENCE_LENGTH,
num_calibration_samples=NUM_CALIBRATION_SAMPLES,
trust_remote_code_model=True,
data_collator=data_collator,
output_dir=SAVE_DIR,
pipeline="sequential",
sequential_targets=["Llama4TextMLP"],
)
# --- Save compressed model ---
print("Saving compressed model...")
model.save_pretrained(SAVE_DIR, save_compressed=True)
processor.save_pretrained(SAVE_DIR)
Evaluation
This model was evaluated on the well-known OpenLLM v1, OpenLLM v2 and HumanEval_64 benchmarks. All evaluations were conducted using lm-evaluation-harness.
Accuracy
Reproduction
The results were obtained using the following commands:
Model Evaluation Commands
MMLU_LLAMA
lm_eval \
--model vllm \
--model_args pretrained="RedHatAI/Llama-4-Maverick-17B-128E-Instruct-NVFP4",dtype=auto,add_bos_token=True,max_model_len=4096,tensor_parallel_size=2,enable_chunked_prefill=True,enforce_eager=True \
--tasks mmlu_llama \
--apply_chat_template \
--fewshot_as_multiturn \
--batch_size auto
MMLU_COT_LLAMA
lm_eval \
--model vllm \
--model_args pretrained="RedHatAI/Llama-4-Maverick-17B-128E-Instruct-NVFP4",dtype=auto,add_bos_token=True,max_model_len=4096,tensor_parallel_size=2,enable_chunked_prefill=True,enforce_eager=True \
--tasks mmlu_cot_llama \
--apply_chat_template \
--fewshot_as_multiturn \
--batch_size auto
ARC-Challenge
lm_eval \
--model vllm \
--model_args pretrained="RedHatAI/Llama-4-Maverick-17B-128E-Instruct-NVFP4",dtype=auto,add_bos_token=True,max_model_len=4096,tensor_parallel_size=2,enable_chunked_prefill=True,enforce_eager=True \
--tasks arc_challenge_llama \
--apply_chat_template \
--batch_size auto
GSM-8K
lm_eval \
--model vllm \
--model_args pretrained="RedHatAI/Llama-4-Maverick-17B-128E-Instruct-NVFP4",dtype=auto,add_bos_token=True,max_model_len=4096,tensor_parallel_size=2,enable_chunked_prefill=True,enforce_eager=True \
--tasks gsm8k_llama \
--apply_chat_template \
--fewshot_as_multiturn \
--batch_size auto
Hellaswag
lm_eval \
--model vllm \
--model_args pretrained="RedHatAI/Llama-4-Maverick-17B-128E-Instruct-NVFP4",dtype=auto,add_bos_token=True,max_model_len=4096,tensor_parallel_size=2,enable_chunked_prefill=True,enforce_eager=True \
--tasks hellaswag \
--apply_chat_template \
--fewshot_as_multiturn \
--batch_size auto
Winogrande
lm_eval \
--model vllm \
--model_args pretrained="RedHatAI/Llama-4-Maverick-17B-128E-Instruct-NVFP4",dtype=auto,add_bos_token=True,max_model_len=4096,tensor_parallel_size=2,enable_chunked_prefill=True,enforce_eager=True \
--tasks winogrande \
--apply_chat_template \
--fewshot_as_multiturn \
--batch_size auto
TruthfulQA
lm_eval \
--model vllm \
--model_args pretrained="RedHatAI/Llama-4-Maverick-17B-128E-Instruct-NVFP4",dtype=auto,add_bos_token=True,max_model_len=4096,tensor_parallel_size=2,enable_chunked_prefill=True,enforce_eager=True \
--tasks truthfulqa \
--apply_chat_template \
--fewshot_as_multiturn \
--batch_size auto
OpenLLM v2
lm_eval \
--model vllm \
--model_args pretrained="RedHatAI/Llama-4-Maverick-17B-128E-Instruct-NVFP4",dtype=auto,max_model_len=4096,tensor_parallel_size=2,enable_chunked_prefill=True,enforce_eager=True\
--apply_chat_template \
--fewshot_as_multiturn \
--tasks leaderboard \
--batch_size auto
HumanEval and HumanEval_64
lm_eval \
--model vllm \
--model_args pretrained="RedHatAI/Llama-4-Maverick-17B-128E-Instruct-NVFP4",dtype=auto,max_model_len=4096,tensor_parallel_size=2,enable_chunked_prefill=True,enforce_eager=True\
--apply_chat_template \
--fewshot_as_multiturn \
--tasks humaneval_64_instruct \
--batch_size auto
- Downloads last month
- 426
Model tree for RedHatAI/Llama-4-Maverick-17B-128E-Instruct-NVFP4
Base model
meta-llama/Llama-4-Maverick-17B-128E