Llama-3.1-8B-Instruct-SPECTRA-Flash
Built with Llama.
SPECTRA-Flash params for meta-llama/Llama-3.1-8B-Instruct: a 7Γ smaller KV cache and decode as fast as dense at batch 1, up to 4.3Γ dense throughput on one H100.
This repo is a delta. It holds only the SPECTRA-Flash record maps (params.safetensors, 1.5 GB) and their config.
The base model weights come from Meta and are not changed.
Code: github.com/nokia-applied-research/SPECTRA Β· Paper: arXiv:2608.07915
What it is
Each layer keeps one record per token in the layout that FlashMLA reads natively (512 latent + 64 RoPE dims, fp8). The record maps start from SPECTRA's closed-form fit (an activation-weighted SVD) and are refined by block-wise distillation on calibration text (WikiText-2 train + Python code), 2.6 H100 GPU hours. At decode, attention reads the fp8 record through FlashMLA plus a small exact window (the first 4 and the latest 123 tokens), and merges the two in one softmax. Nothing is reconstructed.
Usage
git clone https://github.com/nokia-applied-research/SPECTRA.git && pip install -e 'SPECTRA[flash]'
# SPECTRA-Flash kernels (FlashMLA, via vLLM 0.29); needs a Hopper GPU (H100 / H200)
Accept the Llama 3.1 license for the base model first.
π€ Transformers
import torch, spectra.flash
from transformers import AutoModelForCausalLM, AutoTokenizer
name = "meta-llama/Llama-3.1-8B-Instruct"
tok = AutoTokenizer.from_pretrained(name)
model = AutoModelForCausalLM.from_pretrained(name, dtype=torch.bfloat16).cuda()
spectra.flash.enable(model, "morriszjm/Llama-3.1-8B-Instruct-SPECTRA-Flash")
# model.generate(...) now uses the SPECTRA-Flash cache
vLLM 0.29 (use exact prefill, the evaluated setting)
vllm serve meta-llama/Llama-3.1-8B-Instruct --max-model-len 32768 \
--no-enable-prefix-caching --no-enable-chunked-prefill --max-num-batched-tokens 32768 \
--hf-overrides '{"architectures": ["SpectraFlashLlamaForCausalLM"],
"spectra_flash": "morriszjm/Llama-3.1-8B-Instruct-SPECTRA-Flash"}'
Results
LongBench, 8 English tasks (official prompts and scorer, full test split, greedy), through the SPECTRA-Flash engine and the same engine with a dense cache:
| Qasper | QMSum | MultiNews | TREC | TriviaQA | SAMSum | LCC | RepoBench-P | Avg | |
|---|---|---|---|---|---|---|---|---|---|
| Dense (bf16) | 46.44 | 25.52 | 26.86 | 72.50 | 91.64 | 43.83 | 64.85 | 58.76 | 53.80 |
| SPECTRA-Flash | 44.68 | 25.02 | 25.62 | 72.50 | 92.19 | 42.80 | 65.07 | 59.70 | 53.45 (99.3%) |
KV compression on these prompts is 6.4Γ (record and exact window both counted; median prompt 5.7K tokens).
Speed (H100 NVL, 32K context, vs dense bf16 with FlashAttention-3, CUDA graphs):
| KV cache per token | Decode step, batch 1 | Decode step, batch 16 | Max decode throughput | vLLM serving throughput | |
|---|---|---|---|---|---|
| Dense | 128 KiB | 7.24 ms | 24.89 ms | 643 tok/s (batch 16) | 1.00Γ |
| SPECTRA-Flash | 18.5 KiB | 7.24 ms | 10.56 ms | 2,732 tok/s (batch 64), 4.3Γ | 1.21β2.26Γ |
vLLM serving: one memory budget, all requests submitted at once; 32K prompts + 256 output tokens (1.21Γ) and 8K prompts + 2K output tokens (2.26Γ).
Reproduce:
python scripts/run_longbench.py --model meta-llama/Llama-3.1-8B-Instruct --flash morriszjm/Llama-3.1-8B-Instruct-SPECTRA-Flash --out runs/flash.json
spectra-flash bench decode --params morriszjm/Llama-3.1-8B-Instruct-SPECTRA-Flash
How these params were made (51 min on 4 x H100 NVL):
spectra-flash convert --model meta-llama/Llama-3.1-8B-Instruct --out spectra-flash --gpus 0,1,2,3
Limits
- Llama-3.1-8B-Instruct only; bfloat16; one GPU (vLLM tensor parallel size 1); Hopper GPUs.
- vLLM: no prefix caching, no speculative decoding, no KV connectors.
- π€ Transformers: unpadded batches only (batch size 1 or equal-length prompts).
License
These params are derived from Llama 3.1 and are distributed under the Llama 3.1 Community License (see also the Acceptable Use Policy). Llama 3.1 is licensed under the Llama 3.1 Community License, Copyright Β© Meta Platforms, Inc. All Rights Reserved. The SPECTRA code is MIT.
Citation
@misc{zhang2026spectrapushingkvcache,
title={SPECTRA: Pushing the KV Cache Beyond the 2-Bit Cliff via Spectral Transform Coding},
author={Jiamu Zhang and Liang Wu and Kelly Wan and Hanjie Chen and Liangjie Hong},
year={2026},
eprint={2608.07915},
archivePrefix={arXiv},
primaryClass={cs.LG},
url={https://arxiv.org/abs/2608.07915},
}
Model tree for morriszjm/Llama-3.1-8B-Instruct-SPECTRA-Flash
Base model
meta-llama/Llama-3.1-8B