RFC: Integrating KVMem virtual working set for 256K context on 16GB VRAM (Working prototype ready in fork)

Ouverte
#192 27 commentaires 0 réactions 0 personnes assignées Voir sur GitHub

Personne n'a encore pris cette issue.

Évaluation

Difficulté
5/5
Temps estimé
Plus d'une semaine
Accessibilité débutants
8/100
Type d'issue
Fonctionnalité
Clarté
Plutôt claire
Activité
Active
Stack technique
cpp

Piste de recherche

This is an RFC, not a scoped task: it asks the maintainer to choose between upstreaming a ~36K LOC KVMem working-set engine and keeping it as a downstream fork, and the 27-comment thread is where that decision is being made. To follow it, read the fork branch beellama-kvmem and the referenced ggml-cuda/gated_delta_net.cu Blackwell fix, then the thread for the maintainer's answer. Done means an architectural decision plus, at most, a targeted PR such as the GDN CUDA fix; nothing here is a first contribution.

Rédigé par le modèle d'indexation à partir du texte de l'issue.

Description

RFC: Integrating KVMem virtual working set for 256K context on 16GB VRAM (Working prototype ready in fork)

Context & Motivation

Large context windows (128K–256K) on 27B+ models like Qwen3.8-27B (and hybrid architectures with Gated Delta Net) are traditionally difficult to run on consumer hardware (16GB VRAM cards like RTX 4080 / RTX 5060 Ti).

While BeeLlama's native KVarN (and SWA) provides substantial cache savings (~2.67x with kvarn6), pushing beyond 100K–128K on 16GB VRAM still pushes right up against physical memory limits.

We have successfully integrated the KVMem virtual working set engine (arXiv:2609.04852) into BeeLlama v0.4.6, maintaining full compatibility with BeeLlama's core optimizations while allowing true 256K context streaming.

A fully working implementation, benchmarks, and Windows binaries are available in the fork:
👉 Repository & Branch: Andgihat/beellama.cpp (branch: beellama-kvmem)
👉 Release & Binaries: v0.4.6-kvmem


How it works
  1. Host RAM Virtual Working Set: The complete 262,144 (256K) context lives in pinned Host RAM (DDR5, ~8–12 GB).
  2. Fixed GPU Slot Pool: Only an active working set (e.g. Budget $B = 36K$ + Reserve $R = 16K$) sits in VRAM (~14.6 GB total with weights, zero OOM).
  3. Graph Recall & Cache Quantization: Blocks (128 tokens) are staged in/out over PCIe on the fly using Hadamard-rotated quantized slots (q4_0 / q8_0).
  4. Blackwell sm_120 Fix: In the process, we resolved a GDN warp reduction bug in ggml-cuda/gated_delta_net.cu (lanes_per_col stride and pointer offset check keep_rs = K > 1), restoring 100% correct mathematics for hybrid Qwen3.8 on RTX 50-series GPUs.

Benchmark Results (Qwen3.8-27B-UD-Q3_K_XL on RTX 5060 Ti 16GB)

Tested on real text documents from 10K to 256K context:

  • Prompt Processing (Prefill @ 10K+ tokens): 915.84 tokens/s (10,196 tokens processed in 11.13s with -b 2048 -ub 1024).
  • Decode Speed: 35.6 - 40.3 tokens/s with built-in MTP (--spec-type draft-mtp).
  • MTP Acceptance Rate: 76.0% (consistent 2.46 tokens/round).
  • RAM Usage @ 10K: Only 187 MB with q4_0 cache.
  • VRAM Headroom: Fits comfortably within 15.3 GB on a 16GB GPU.

Question for Maintainer (@Anbeeld)

Because the KVMem integration is relatively substantial (~36K LOC including tests, standalone llama-kvmem-server, and runtime adapters), we wanted to check with you first:

  1. Upstream PR: Would you be interested in having KVMem integrated directly into upstream BeeLlama (e.g. as an optional feature / server target)?
  2. Specialized Fork: Or would you prefer we maintain this as a specialized downstream fork / companion project (beellama-kvmem), and only submit targeted PRs (such as the Blackwell GDN CUDA fixes in gated_delta_net.cu) to upstream?

Happy to adapt the changes or submit targeted PRs depending on your architectural preferences. Thank you for the awesome work on BeeLlama!

Langage dominant
C++
Étoiles
1.2k
Forks
80
Merge moyen
4 j 20 h
PR mergées (30 j)
2

Préparer son environnement

Ce projet ne fournit ni conteneur de développement, ni Dockerfile, ni guide de contribution : l'installation est à votre charge. Commencez par son README, et consultez notre guide de la première contribution pour les étapes générales.

Par où commencer

  1. Lisez l'issue en entier, puis le guide de contribution du projet.
  2. Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
  3. Forkez le dépôt et travaillez sur une branche.
  4. Ouvrez une pull request qui référence le numéro de l'issue.

Autres issues de Anbeeld/beellama.cpp

Toutes les issues de Anbeeld/beellama.cpp

Issues similaires

Plus d'issues C++

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.