interplane.Get Omega
Read in your language

aien-yardsticks

aien-dev/aien-yardsticks

Brought by drakestapleton

branch main Branches Tags History

aien-yardsticks / yardsticks / modular-nemotron-h-kvexp / README.md

84 lines · 3510 bytes Raw Blame History Source

YARDSTICK ONLY. Never part of AIEN. Nothing here ships in AIEN.

This is the Nemotron-H KV-head-expansion comparison adapter for Modular MAX, kept so AIEN can be measured against MAX. Modular MAX was removed from AIEN on 2026-10-15. This adapter is a frozen record only and is no longer run; the install, serve and test steps below are historical, so do not follow them. It was moved here, with its git history, from aien-dev/aien-sovereign-core (commit 5fdab70, path modular/nemotron_h_kvexp) because AIEN repos may contain no Python. The Python in this folder is scheduled for replacement by Rust (see the "Replace the Python yardstick with Rust" issue in this repo).

KV-Head Expanded Nemotron-H Architecture for Modular MAX

Custom architecture adapter enabling high-throughput serving of NVIDIA Nemotron-H models (such as nvidia/NVIDIA-Nemotron-3.5-Lightning-30B-A3B-BF16) on Modular MAX.

Architecture Rationale

Modular MAX employs optimized FlashAttention kernels for Grouped-Query Attention (GQA). In current MAX versions, the maximum supported GQA group size is 8 (group = num_attention_heads / num_key_value_heads <= 8).

Nemotron-3.5-Lightning-30B utilizes a GQA configuration where:

Because 16 > 8, loading the standard checkpoint triggers an unsupported group size error in the MAX attention kernel.

This adapter resolves the kernel limitation by calculating the minimum integer expansion factor:

expansion = math.ceil((n_heads / n_kv) / MAX_NVIDIA_GQA_GROUP)

For Nemotron-H (group 16), expansion = 2. Each KV head is replicated across the channel dimension during state dictionary weight loading:

This satisfies the FlashAttention kernel constraint without altering model activations, attention math, or output distributions.

Key Features

  1. Native Dynamic Expansion: Replicates KV heads on the fly during safe tensor loading and state dict conversion.
  2. Offline PEFT LoRA Folding: Set ATLAS_LORA_DIR to fold LoRA adapters (A and B matrices) directly into base weights prior to QKV fusion, eliminating runtime LoRA overhead.
  3. Lazy Registration Override: Overrides default NemotronHForCausalLM registration within the MAX pipeline registry to ensure transparent resolution from standard model checkpoints.

Installation & Usage

Install as an editable package:

pip install -e .

Serve using the MAX CLI:

max serve \
  --model nvidia/NVIDIA-Nemotron-3.5-Lightning-30B-A3B-BF16 \
  --served-model-name nemotron-lightning \
  --custom-architectures $(pwd) \
  --port 18006 \
  --max-batch-size 8 \
  --max-length 32768 \
  --kv-cache-format bfloat16

Testing

Run unit tests via standard Python unittest:

python3 -m unittest discover -s tests -v

License

Licensed under the Apache License, Version 2.0.

Benchmarks (NVIDIA DGX Spark / Grace Blackwell GB10)

Benchmarked on ARM64 Grace Neoverse V2 cores using realistic Nemotron-30B layer dimensions (4608x4096 expanded to 5120x4096):

MetricMeasured Value
Latency per Layer5.49 ms
Full Model Expansion (52 layers)285.63 ms
Memory Copy Throughput12.80 GB/s

Load-time expansion overhead is under 300 ms for the entire 30B model, introducing negligible startup delay while enabling high-throughput serving on Modular MAX.