Run this model with HF Jobs

Run amd/granite-4.0-h-tiny-reap-50-llmcompressor on Hugging Face's managed compute, monitor its progress, and retrieve the results when it's done.

Paste one of these prompts into your coding agent:

Fine-tune on my dataset

Use HF Jobs and TRL to fine-tune https://huggingface.co/amd/granite-4.0-h-tiny-reap-50-llmcompressor. Ask me which dataset to train on, then push the fine-tuned model to a new model repo. Run `hf jobs --help` first to learn the CLI.

Run batch inference

Use HF Jobs to run batch inference with https://huggingface.co/amd/granite-4.0-h-tiny-reap-50-llmcompressor on the inputs in a mounted HF Bucket. Ask me which Bucket to use, then write the outputs back to it and keep each input ID. Run `hf jobs --help` first to learn the CLI.

Evaluate on a benchmark

Use HF Jobs to evaluate https://huggingface.co/amd/granite-4.0-h-tiny-reap-50-llmcompressor. Ask me which benchmark to run, then save the scores and the per-example results to a new dataset repo. Run `hf jobs --help` first to learn the CLI.

granite-4.0-h-tiny-reap-50-llmcompressor

Model Overview

  • Model Architecture: GraniteMoeHybridForCausalLM
    • Input: Text
    • Output: Text
  • Source Model: granite-4.0-h-tiny
  • Supported Hardware: AMD EPYC (CPU inference)
  • Preferred Operating System: Linux
  • Inference Engine: vLLM v0.34.0
  • Compression Framework: LLM Compressor v0.14.0
  • Compression Method: REAP 50% expert pruning (weights remain BF16)
  • Compatible Stack:
    • ZenDNN (main)
    • ZenTorch (main)
    • PyTorch v2.14.0+cpu
    • Transformers v5.20.2
    • LLM Compressor v0.14.0
    • vLLM v0.34.0
    • Python 3.12.16

This is a pruned version of granite-4.0-h-tiny created by AMD using LLM Compressor (compressed-tensors) for ZenDNN-optimized CPU inference.

Compression

The model was pruned from granite-4.0-h-tiny using LLM Compressor via REAP (Router-weighted Expert Activation Pruning). This reduces the model weights from 12.9 GiB to 7.3 GiB on disk (~44% reduction).

  • Method: REAP 50% expert pruning
  • Config: REAPPruningModifier, sparsity=0.50
  • Sparsity: 50% of the experts in every MoE layer โ€” num_local_experts drops from 64 to 32 in each of the 40 decoder layers
  • Precision: BF16 throughout โ€” this is a structural pruning pass, not a quantization pass, so every tensor stays BF16 and the checkpoint carries no quantization_config
  • Pruned: the routed experts (block_sparse_moe.input_linear, block_sparse_moe.output_linear) and the matching router rows (block_sparse_moe.router.layer.weight)
  • Left intact: the shared MLP in every layer (shared_mlp.{input,output}_linear), all 36 Mamba mixers and all 4 attention blocks, embed_tokens (tied to lm_head), and the layer norms
  • Calibration: 128 samples from allenai/tulu-3-sft-personas-math, rendered through the model's chat template and truncated to 1024 tokens, one sequence per batch

REAP scores each expert by how much it actually contributes to its layer's output, weighting the expert's activation magnitude by the router probability it receives, then drops the lowest-scoring half. The router's top-6 selection is unchanged; it simply chooses from the 32 experts that remain in each layer, and the router projection is sliced down to match ([32, 1536]). Because the score depends on the router's real activations, the pass needs calibration data and moe_calibrate_all_experts=False so that each expert is only measured on the tokens actually routed to it.

Granite-4.0-h is a hybrid model: 36 of its 40 layers use a Mamba mixer and only 4 use full attention, and every layer pairs its routed experts with an always-on shared MLP. None of that is touched โ€” the pruning only removes routed experts, so the sequence-mixing stack and the shared MLP are left exactly as they were.

Granite stores each layer's experts as fused 3D tensors, which the pruning hooks cannot address individually. load_context() splits them into per-expert linears for the duration of the pass, and repack_moe() fuses the survivors back into 3D tensors before saving, so the result loads as a stock Granite-4.0-h checkpoint with a smaller expert dimension โ€” block_sparse_moe.input_linear.weight becomes [32, 1024, 1536] and block_sparse_moe.output_linear.weight becomes [32, 1536, 512]. The surviving expert indices are written to retained_experts.json in the output directory, one list of 32 indices per layer.

import torch
import transformers
from transformers import AutoConfig, AutoProcessor

from llmcompressor import oneshot
from llmcompressor.modifiers.pruning import REAPPruningModifier
from llmcompressor.modeling.moe.linearize import repack_moe
from llmcompressor.utils import load_context

model_id = "ibm-granite/granite-4.0-h-tiny"
output_dir = "./granite-4.0-h-tiny-REAP-50"

# Step 1: Load the BF16 model. load_context() splits the fused 3D expert tensors
# (block_sparse_moe.input_linear / output_linear) into per-expert linears so each
# expert's output can be hooked.
model_cls = getattr(transformers, AutoConfig.from_pretrained(model_id).architectures[0])
with load_context(model_cls):
    model = model_cls.from_pretrained(model_id, dtype=torch.bfloat16)
processor = AutoProcessor.from_pretrained(model_id)

# Step 2: Calibration set. 128 samples from allenai/tulu-3-sft-personas-math, rendered
# through the model's chat template and truncated to 1024 tokens (see reap_moe.py,
# section 6), named `dataset` below.

# Step 3: REAP recipe. Drop 50% of the experts in every MoE layer (64 -> 32).
recipe = REAPPruningModifier(sparsity=0.5, report_path=f"{output_dir}/retained_experts.json")

# Step 4: One-shot prune, one decoder layer at a time. batch_size=1 keeps every
# calibration token. All experts are not force-calibrated, since REAP needs the
# router's real activations.
oneshot(
    model=model,
    processor=processor,
    dataset=dataset,
    recipe=recipe,
    max_seq_length=1024,
    num_calibration_samples=128,
    batch_size=1,
    sequential_targets=["GraniteMoeHybridDecoderLayer"],
    moe_calibrate_all_experts=False,
)

# Step 5: Pack the per-expert linears back into fused 3D tensors, then save.
repack_moe(model)
model.save_pretrained(output_dir, save_compressed=True)
processor.save_pretrained(output_dir)

Quick Start

Use with vLLM

from vllm import LLM, SamplingParams

model = LLM(
    model="amd/granite-4.0-h-tiny-reap-50-llmcompressor",
    dtype="bfloat16",
)

sampling_params = SamplingParams(temperature=0.7, max_tokens=256)
outputs = model.generate(["Hello, how are you?"], sampling_params)
print(outputs[0].outputs[0].text)

Requirements

torch==2.14.0+cpu
transformers==5.20.2
vllm==0.34.0
llmcompressor==0.14.0
zentorch  # main

Built and validated on Python 3.12.16 with ZenDNN built from main.

OpenMP Setup

For optimal performance, set LD_PRELOAD with libomp.so (LLVM OpenMP) or libiomp5.so (Intel OpenMP):

# Using LLVM OpenMP (llvmopenmp)
export LD_PRELOAD=$(find /path/to/env -name "libomp.so" | head -1)

# Or using Intel OpenMP (libiomp)
export LD_PRELOAD=$(find /path/to/env -name "libiomp5.so" | head -1)

Note: Set LD_PRELOAD before launching vLLM or any inference script.

Evaluation

The model was evaluated against the BF16 (unpruned) baseline on standard benchmarks using lm-evaluation-harness with the vLLM engine.

Benchmark BF16 Baseline REAP-50 (this model) Recovery
GSM8K (5-shot) 0.8203 0.7619 92.88%

Evaluation Command

lm_eval \
    --model vllm \
    --model_args pretrained=amd/granite-4.0-h-tiny-reap-50-llmcompressor,dtype=bfloat16,max_model_len=4096 \
    --tasks gsm8k \
    --batch_size auto \
    --trust_remote_code \
    --num_fewshot 5 \
    --apply_chat_template \
    --log_samples \
    --gen_kwargs "max_gen_toks=2048" \
    --output_path .

Limitations

  • Version Lock: This model is validated against ZenDNN main / ZenTorch main / PyTorch v2.14.0+cpu / Transformers v5.20.2. It may not load correctly on other versions.
  • CPU Only: This model is optimized for AMD EPYC CPU inference via ZenDNN. It is not intended for GPU inference.
  • Accuracy Trade-off: Removing half of every layer's experts permanently removes capacity rather than approximating it, so the loss is not recoverable at inference time the way a quantization error partly is. On GSM8K this costs about 5.8 points (92.88% recovery), the largest drop among the REAP-50 models in this series. Starting from only 64 experts per layer with top-6 routing, this model has less redundancy to give up than the larger MoE checkpoints, so if accuracy matters more than footprint, prefer the unpruned model or a quantized variant.
  • Calibration Bias: The experts that survive were selected using a math instruction-tuning set truncated to 1024 tokens, so the GSM8K recovery above is measured on the kind of data the pruning was fitted to. Coding, multilingual, and long-context behavior is not represented in the calibration set and may degrade more than this number suggests.

License

This model is distributed under the same license as the source model. See the LICENSE file for details.

Modifications copyright (c) 2026 Advanced Micro Devices, Inc. All rights reserved.

Downloads last month
64
Safetensors
Model size
4B params
Tensor type
BF16
ยท
Inference Providers NEW
This model isn't deployed by any Inference Provider. ๐Ÿ™‹ Ask for provider support

Model tree for amd/granite-4.0-h-tiny-reap-50-llmcompressor

Quantized
(42)
this model