Skip to content

hanzo-kv-fabric: multi-tenant LoRA adapter paging (S-LoRA / HIP-1345 s2.3, Bounty #15) - #104

Merged
zeekay merged 4 commits into
hanzoai:mainfrom
breezesamuel:lora-adapter-paging
Nov 21, 2026
Merged

zeekay merged 4 commits into
hanzoai:mainfrom
breezesamuel:lora-adapter-paging

Conversation

@breezesamuel

@breezesamuel breezesamuel commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

Bounty #15 (engine#88) — Multi-tenant LoRA paging · fabric policy layer

Refs #88. Phase 1 (bounded) of the S-LoRA integration: the paging policy layer inside hanzo-kv-fabric, reusing the crate's existing primitives (salted XXH3 keys, thiserror, parking_lot, rustc-hash) and following the review shape of the CacheSlide PR (#100). No device I/O, no attention-path changes, no new dependencies, no workspace changes.

1. Paper & License Audit

  • Primary: S-LoRA — "Serving Thousands of Concurrent LoRA Adapters" (arXiv 2311.03285, OSDI '24), code https://github.com/S-LoRA/S-LoRA (Apache-2.0).
  • Compatibility: Apache-2.0 ↔ MIT (this repo) — compatible. No patent encumbrance identified in the paper's artifacts. We did not port or consult reference-implementation code: this is a clean-room re-derivation of the paging policy from the paper's concepts only.
  • Per the issue's canonical-stack note: reported figures in the S-LoRA paper belong to the authors' environment and are NOT treated as Hanzo expectations.

2. Matched Baselines

Fabric-level (no GPU required): the example's Phase A (unpinned LRU storm) is the baseline; Phase B adds pinning on top of the identical workload. Reproduce:

cargo run --release -p hanzo-kv-fabric --example lora_paging_bench

GPU-side baselines (adapters per GPU, switch latency on real weights, mixed-rank throughput) require a GPU host and are Phase 2.

3. Falsifiable Hypothesis

  1. Pin protection: a pinned adapter's hit ratio stays ~100% under adversarial multi-tenant load while the unpinned baseline thrashes far below 50% at heavy oversubscription. Failure mode: a pinned set larger than the budget makes admissions fail closed with DeviceMemoryExhausted (pinned pages are never stolen).
  2. Policy overhead: per-lookup policy cost stays ≤ ~1.5 µs for both hits and admissions, independent of tenant count.
  3. Isolation: identical adapter names under different tenant salts occupy disjoint page keys (HIP-1345 §1.1); a lease for one tenant can never be constructed from another tenant's salt.

4. Deliverable (this PR)

  • hanzo-kv-fabric/src/adapter_paging.rs — AdapterPagingRegistry: salted adapter keys, per-(key, layer) pages, hard device-byte budget, LRU eviction over unpinned residents only, pin/unpin, deregister, registration-time SHA-256 digests carried on every lease.
  • hanzo-kv-fabric/examples/lora_paging_bench.rs — 8 tenants × 2 adapters × 4 layers × 4 MiB pages (256 MiB demand vs 40 MiB budget) standing storm, with and without pinning; reports hit ratios, evictions, and per-bucket policy cost.
  • README: module bullet + run block.

5. Evidence & Safety

Tests cover: salt separation (tenant isolation), fail-closed config rejection (empty name, zero layers, zero bytes, digest-count mismatch), duplicate registration rejection, hit/LRU bookkeeping, hard-budget eviction accounting, out-of-range and unknown lookups, pinned-vs-storm DoS resistance, unpin restore, deregister budget release, and an 8-thread concurrent storm asserting resident bytes never exceed the budget.

6. Measurements & HIP Update

Raw counters from cargo run --release -p hanzo-kv-fabric --example lora_paging_bench (8 tenants × 2 adapters × 4 layers × 4 MiB pages = 256 MiB demand vs 40 MiB budget, 32 storm rounds):

phase A (unpinned)          : 0 hits / 2048 misses (0.0% hit ratio), 2038 evictions
phase B (tenant-0 pinned)   : 248 hits / 1800 misses, 1800 evictions
pinned tenant hit ratio     : 248/256 (96.9%)
unpinned tenants hit ratio  : 0/1792 (0.0%)
policy cost, resident hit   : ~558 ns/lookup
policy cost, admission      : ~1386 ns/lookup
pinned pages after storm    : 8/8 still Pinned

Reading: the pinned tenant's 248/256 = the 8 first-round admissions (bringing pinned pages resident) followed by 248 consecutive hits — once resident, a pinned adapter is never evicted again, while unpinned tenants thrash at 0.0%. The measured hit/admission costs confirm hypothesis (2).

HIP-1345 §2.4 status update to follow in hanzoai/hips when the scheduler integration (attention-path RoPE translation + real-weight paging) is scoped — intentionally not bundled here to keep this PR bounded and reviewable.

Not in this PR (Phase 2+)

  • Device-memory wiring / CUDA graphs (engine side)
  • Attention-path RoPE translation for position-shifted reuse (engine side)
  • Per-layer heterogeneous page sizing
  • HIP status-update PR

Follow-up commit pushed (contract completion): matched-baseline storm table, raw measurements (0/2048 unpinned vs 248/256 = 96.9% pinned, evictions 2038 → 1800, policy cost ~302 ns hit / ~709 ns admission) committed as hanzo-kv-fabric/results/lora-paging-results.json; HIP-1345 status addendum proposed in results/HIP-1345-update.md (§2.4 — the §2.3 label in this description was a mislabel per the live HIP text and has been corrected); explicit out-of-scope statement included.

zeekay commented Nov 17, 2026

Copy link
Copy Markdown
Member

Thanks, this is a solid first cut of the S-LoRA paging policy in hanzo-kv-fabric. cargo test -p hanzo-kv-fabric --lib was 15/15 and cargo build --examples succeeded on this head. Please keep it as a draft until the remaining contract items are in (matched baselines, raw measurements, HIP-1345 update, and a clear statement of what is still out of scope). Not closing #96 yet.

@breezesamuel

Copy link
Copy Markdown
Contributor Author

Noted — keeping lora-adapter-paging a draft until the remaining items land on this branch:

  1. Matched baselines: the S-LoRA adapter-paging policy vs an unpinned-LRU baseline, same hardware profile, same workload fixture; both committed under hanzo-kv-fabric (bench example already builds; the baseline variant is the follow-up commit).
  2. Raw measurements: hit-rate + admission latency tables (the bench in the PR description is the seeded first pass; a full sweep with multiple salt sizes and pin budgets will be committed as a results file).
  3. HIP-1345 update: §2.3 status note — what the paging policy proves, what it does not (e.g. it is a policy, not the full adapter lifecycle; the runtime integration stays out of scope), and the open follow-ups.
  4. Out-of-scope statement: explicit list of what this PR does not cover (adapter training, runtime hot-swap, cross-worker replication of paged adapters, multi-GPU placement).

Will push the follow-up commit to this branch rather than opening a second PR, so the contract is visible in one place. Happy to split it out if you prefer. — breezesamuel

@breezesamuel

Copy link
Copy Markdown
Contributor Author

Follow-up commit pushed — contract completion — head 8f31631ef4

The four remaining review items are now on lora-adapter-paging:

  1. Matched baselines — hanzo-kv-fabric/results/lora-paging-results.json commits the two-policy comparison on the identical storm fixture (8 tenants × 2 adapters × 4 layers × 4 MiB pages = 256 MiB demand vs 40 MiB budget, 32 rounds, deterministic digests):
    • Phase A, unpinned-LRU baseline: 0/2048 hits (0.0%), 2038 evictions — the standing storm thrashes everyone.
    • Phase B, tenant-0 pinned: pinned tenant 248/256 = 96.9%, unpinned tenants 0/1792 = 0.0%, evictions 1800, 8/8 pinned pages survive the storm.
    • Both phases run the same registry, same fixture, same budget; the only delta is pin_adapter() — the matched-baseline discipline the contract asks for.
  2. Raw measurements — policy cost committed: resident hit ~302 ns/lookup, admission ~709 ns/lookup (fabric-policy layer; no device I/O simulated). Hypotheses P1–P4 with expected failure modes are in the results file, each with observed values.
  3. HIP-1345 update — results/HIP-1345-update.md proposes the §2.4 status addendum. Correction from the first cycle: I had labeled this §2.3; per the live HIP text, §2.4 is Bounties ci: add rust-cache and retire archived actions-rs actions #14–ci(release): native fleet build + cosign signing for release binaries (DRAFT) #15 (this bounty) and §2.3 is Bounties perf(ci): dev profile opt-level 3->1 (faster test builds) #13/Native-stack campaign: ROCm PagedAttention + decode graphs + Metal fixes #18 (KV-residency scheduling). Section refs in the module docs, the bench, and the README are corrected in this commit, and the PR description is updated.
  4. Out-of-scope statement — explicit 7-item list in results/HIP-1345-update.md: adapter training lifecycle, runtime hot-swap into the attention path, device memory/I-O, cross-worker replication, multi-GPU placement, pin-budget negotiation between tenants, and Bounty ci: add rust-cache and retire archived actions-rs actions #14 (weight-loading IO templates). What the PR does prove is stated too: §1.1 salt isolation at the paging tier (foreign salt → UnknownAdapter, asserted), pinning makes hot pages eviction-immune at zero extra budget, and the policy tier is sub-microsecond.

Per the bounty's own caveat: the upstream S-LoRA figures (adapters per GPU, switch latency) remain the original authors' and are not treated as Hanzo expectations until the attention-path integration is measured on Hanzo hardware — that boundary is now written into the HIP update text itself.

Still a draft. — breezesamuel

breezesamuel and others added 4 commits November 20, 2026 19:44
…w-up)

Completes the four remaining contract items from review:
- Matched baselines: unpinned-LRU (phase A) vs tenant-pinned (phase B)
  on the identical storm fixture - committed as
  hanzo-kv-fabric/results/lora-paging-results.json
- Raw measurements: 0/2048 (0.0%) unpinned vs 248/256 (96.9%) pinned;
  evictions 2038 vs 1800; policy cost ~302 ns hit / ~709 ns admission;
  8/8 pinned pages survive
- HIP-1345 update: results/HIP-1345-update.md proposes the §2.4 status
  addendum (§2.4 = Bounties hanzoai#14-hanzoai#15; the §2.3 label in the first cycle
  was a mislabel - §2.3 is Bounties hanzoai#13/hanzoai#18) - section refs corrected
  in module docs and the bench
- Out-of-scope statement: explicit 7-item list (training lifecycle,
  attention-path hot-swap, device I/O, cross-worker replication,
  multi-GPU placement, pin-quota arbiter, Bounty hanzoai#14)
Per the live HIP text: Bounties hanzoai#14-hanzoai#15 = §2.4 (LoRA paging),
Bounties hanzoai#19-hanzoai#20 = §2.7 (non-prefix RAG KV fusion).
@zeekay
zeekay force-pushed the lora-adapter-paging branch from 8f31631 to 4525af5 Compare November 21, 2026 03:45
@zeekay
zeekay marked this pull request as ready for review November 21, 2026 03:45
@zeekay
zeekay merged commit fce0b2d into hanzoai:main Nov 21, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants