Files
ollama/mlxrunner/cache/memory_test.go
Daniel Hiltgen 924cc286cc inkling2: faster Metal decode, prefill and draft rounds (#19843)
* inkling2: faster Metal decode, prefill and draft rounds

Add Inkling-only Metal kernels, each with a stock-graph fallback, gated
by GPU generation and size class: short BF16 products, deduplicated
NVFP4/MXFP8 expert gathers with fused SwiGLU, fused loop controllers and
residual mixing, relative-position split attention, fused short
convolutions, faster global prefill, an ordered window cache that
appends in place, and an 8-bit draft with a 4-bit vocabulary head
(proposals only; outputs stay exact).
2026-11-23 17:35:09 -08:00

54 lines
1.6 KiB
Go

package cache
import (
"testing"
"github.com/ollama/ollama/mlx"
"github.com/ollama/ollama/mlx/mlxtest"
)
func TestEstimateMemory(t *testing.T) {
mlxtest.Run(t, func(t *mlxtest.T) {
b := newKVBatch(0, 1)
k := mlx.Zeros(mlx.DTypeFloat16, 1, 4, 1, 8)
full := NewKVCache()
window := NewRotatingKVCache(4)
ordered := NewOrderedWindowKVCache(4)
full.Update(b, k, k)
window.Update(b, k, k)
ordered.Update(b, k, k)
defer ordered.Free()
recurrent := NewRecurrentCache(3, 8, 2, 4, 8)
recurrent.Get(b, mlx.DTypeFloat16)
recurrent.Put(b, []*mlx.Array{recurrent.convState}, []*mlx.Array{recurrent.deltaState})
defer full.Free()
defer window.Free()
defer recurrent.Free()
for _, tc := range []struct {
name string
cache Cache
tokens, checkpoints int
want int64
}{
{"full", full, 1024, 2, 2 * 1024 * 128},
{"capacity_rounding", full, 257, 0, 2 * 512 * 128},
{"window", window, 1024, 2, 4 * 4 * 128},
{"short_window", window, 2, 0, 2 * 2 * 128},
{"ordered_window", ordered, 1024, 2, int64(4*4+2*ordered.step) * 128},
{"recurrent", recurrent, 1024, 2, 4 * (3*8*2 + 2*4*8*4)},
{"shared_layer", nil, 1024, 2, 0},
} {
got, ok := EstimateMemory(tc.cache, tc.tokens, tc.checkpoints)
if !ok || got != tc.want {
t.Errorf("%s: bytes=%d known=%v, want %d", tc.name, got, ok, tc.want)
}
}
if _, ok := EstimateMemory(NewKVCache(), 1024, 2); ok {
t.Fatal("uninitialized attention cache was treated as known")
}
if _, ok := EstimateMemory(full, -1, 2); ok {
t.Fatal("invalid context was treated as known")
}
})
}