FastShortQ-8K / README.md
Yingbing's picture
Publish FastShortQ-8K research checkpoint
7dc976a verified
|
Raw History Blame Contribute Delete
4.12 kB
metadata
license: llama3.1
base_model: meta-llama/Llama-3.1-8B-Instruct
library_name: pytorch
tags:
  - graph-neural-network
  - knowledge-distillation
  - long-context
  - kv-cache
  - llama

FastShortQ-8K

FastShortQ-8K is a standalone block-importance ranker for hierarchical KV-cache placement. It distills a ShortQ teacher based on Llama 3.1 8B hidden states into a compact token-embedding and graph-neural-network student. The student does not load or execute an LLM during ranking inference.

FastShortQ is built with Llama. The compact token embedding was initialized from a random projection of the Llama 3.1 8B embedding table. Use and redistribution are subject to the Llama 3.1 Community License.

Architecture

  • 34,480,389 total parameters
  • 256-dimensional compact token embedding
  • mean/max pooling over 16-token blocks
  • two-layer GraphSAGE graph encoder
  • question-to-block ShortQ attention
  • graph cross-attention and four-level block classification
  • output tiers: drop, disk, CPU, and GPU

The checkpoint is approximately 132 MB and records llm_required_at_inference: false.

Evaluation

The current evaluation uses 1,000 examples with an 80/10/10 random split from the same dataset and graph.

Metric Test result
Block accuracy 91.78%
Macro-F1 92.17%
Adjacent-level accuracy 99.00%
High-importance GPU recall 99.85%
Mean GPU-tier fraction 15.43%

Generalization limitation

These are preliminary in-domain, block-level results. The test partition has 100 questions (51,200 correlated block decisions), and all splits share the same graph. Grouped, multi-seed, and out-of-distribution evaluation is required before interpreting the reported accuracy as generalization to unseen passage groups or graphs.

MI210 inference benchmark

Batch-one ShortQ ranking latency was measured on an AMD Instinct MI210. Results include block pooling, graph-conditioned ranking, and tier-policy computation; they exclude model loading, one-time graph encoding, KV-cache construction, and language-model text generation.

Context Llama-8B teacher pipeline FastShortQ Speedup
1,024 tokens 159.81 ms 3.92 ms 40.8x
2,048 tokens 307.32 ms 4.03 ms 76.2x
4,096 tokens 620.81 ms 4.01 ms 155.0x
8,192 tokens 1,633.65 ms 4.00 ms 408.7x

At 8K tokens, resident GPU memory was 248 MiB for FastShortQ versus 15,446 MiB for the teacher pipeline. See inference_benchmark.json for full measurements.

Loading the checkpoint

The checkpoint contains state_dict and config fields. The model expects:

  • Llama 3.1 tokenizer-compatible token IDs and attention masks;
  • graph node features with dimension 768;
  • encoded graph representations and up to five retrieved node IDs per sample;
  • sequences of at most 8,192 tokens (512 blocks).
from pathlib import Path
import torch

from fast_shortq_distill import FastShortQStudent

payload = torch.load("model.pt", map_location="cpu", weights_only=False)
cfg = payload["config"]
model = FastShortQStudent(
    vocab_size=cfg["vocab_size"],
    embedding_dim=cfg["embedding_dim"],
    pad_token_id=cfg["pad_token_id"],
    node_dim=cfg["node_dim"],
    hidden_dim=cfg["hidden_dim"],
    gnn_layers=cfg["gnn_layers"],
    num_heads=cfg["num_heads"],
    dropout=cfg["dropout"],
    max_retrieved=cfg["max_retrieved"],
    max_blocks=cfg["max_blocks"],
    block_size=cfg["block_size"],
)
model.load_state_dict(payload["state_dict"], strict=True)
model.eval()

fast_shortq_distill.py, integrated_shortq.py, and rag_query_gnn_predictor.py contain the architecture and training utilities.

Intended use

This is a research checkpoint for studying efficient block-level KV-cache placement in long-context retrieval-augmented inference. It is not a language model and does not generate text. It should not be used as a substitute for task-specific validation of cache-placement quality.

Acknowledgement

This work was supported in part by Advanced Micro Devices, Inc. under the AMD University Program's AI & HPC Cluster.