[LD] Resident WeightCache: memoize device uploads across decode tokens

Per-token forward re-read ~3 GiB of NVFP4/MXFP8 expert blobs from NVMe and
re-uploaded every layer/norm/query tensor. WeightCache borrows the archive and
memoizes raw tensors, BF16->F32 norms, per-layer weights, controllers and expert
matrices (Arc, interior mutability) so autoregressive decode reuses GPU-resident
weights. The forward path now takes &WeightCache; serve_gen creates one cache
per request shared across prefill + decode.

MEASURED (gfx1150, debug): 21 forwards 36s -> 8.8s (~4x); parity unchanged
(first tokens [152717,13,68014,32,13] exact). Release steady decode ~3.8 tok/s
(DONE 64: decode_ms 16909 over 64 tokens). Suite green: 18 ld GPU + 17 hip GPU.
This commit is contained in:
adm committed 2026-12-01 17:18:21 +01:00
1 parent 5ec55f753f
commit 1df8342f96
3 files changed
+152 -55

No files matched your search

+9 -4
View File
@@ -26,7 +26,7 @@ use vetta_infer_abi::sampler::{
use vetta_infer_abi::serve::{parse_serve_line, ParsedGen, ServeCommand};
use vetta_infer_hip::DeviceBuf;
use vetta_infer_ld::inkling::parse_config;
use vetta_infer_ld::layer::{forward_inkling_with_state, Dims, LayerState};
use vetta_infer_ld::layer::{forward_inkling_with_state, Dims, LayerState, WeightCache};
use vetta_infer_ld::SafetensorsArchive;
use crate::session::ServeSession;
@@ -105,12 +105,13 @@ impl InklingEngine {
fn forward(
&self,
cache: &WeightCache,
token: i32,
pos: i32,
max_seq: usize,
states: &mut [Option<LayerState>],
) -> Result<DeviceBuf, String> {
forward_inkling_with_state(&self.ar, &self.d, token, self.vocab, max_seq, pos, self.cap, states)
forward_inkling_with_state(cache, &self.d, token, self.vocab, max_seq, pos, self.cap, states)
}
}
@@ -152,6 +153,10 @@ pub fn serve_gen(
}
};
// Resident weight cache for this request: weights upload once and stay on
// the GPU across prefill + decode (no per-token NVMe expert re-reads).
let cache = WeightCache::new(&eng.ar);
// --- Prefill: run the forward over every prompt token, growing KV/history. ---
let t0 = Instant::now();
let mut pos = 0i32;
@@ -165,7 +170,7 @@ pub fn serve_gen(
stop.store(false, Ordering::Relaxed);
return;
}
match eng.forward(tok, pos, max_seq, &mut states) {
match eng.forward(&cache, tok, pos, max_seq, &mut states) {
Ok(lg) => logits = Some(lg),
Err(e) => {
emit_all(emit, sess.on_error(&e));
@@ -245,7 +250,7 @@ pub fn serve_gen(
finish = "length";
break;
}
match eng.forward(rep.token, pos, max_seq, &mut states) {
match eng.forward(&cache, rep.token, pos, max_seq, &mut states) {
Ok(l) => logits = l,
Err(e) => {
emit_all(emit, sess.on_error(&e));