ollama/mlxrunner/cache/hidden_test.go
Daniel Hiltgen a00d083bb5
mlx: System one support (#18701)
* mlxrunner: restore System One scoring

Carry the MLX implementation and its tests from the original System One
commit. The API/compiler and llama-server implementation already exist on
the release branch, so retain those versions. Adapt the optional model test
to the renamed decision package and its explicit rendering/context setup.

(cherry picked from commit 26e546ddb3)

* Enable MLX System One and add regression coverage

* mlxrunner: add Laya support for System One

Import Laya checkpoints and implement bidirectional decision scoring.

* mlxrunner: release cached buffers after System One scoring

* decision: match Tev1 and Nimble publisher prompt formats

Select Tev1 prompts using renderer metadata and fix JSON formatting, with regression coverage for GGUF and MLX.

* mlx: support Clef and Clef Flash decision models

Add model import, quantization safeguards, and text/image scoring with the Clef joint decision head.

* support vision capabilities for decision models

* Make Clef scoring cancellable between prefill chunks

Preserve joint-head inputs and test cancellation, cleanup, and recovery.

* mlx: separate decision preparation and readout from forward

Let serial and batched scoring share model-owned preparation and readout
without duplicating architecture-specific logic in the runner.

* mlx: add Strands Decider support

* implement caching

---------

Co-authored-by: ParthSareen <parth.sareen@ollama.com>
2026-10-03 13:17:21 -07:00

54 lines
1.5 KiB
Go

package cache
import (
"slices"
"testing"
"github.com/ollama/ollama/mlx"
"github.com/ollama/ollama/mlx/mlxtest"
)
func TestHiddenCacheSnapshots(t *testing.T) {
mlxtest.Run(t, func(t *mlxtest.T) {
c := NewHiddenCache()
defer c.Free()
c.PrepareSnapshots([]int{2, 3})
c.Append(mlx.FromValues([]float32{1, 2, 3, 4}, 1, 4, 1))
captured := c.TakeSnapshots()
whole := c.Snapshot(0)
defer whole.Close()
if !c.Restore(nil, 2) {
t.Fatal("could not rewind")
}
c.Append(mlx.FromValues([]float32{30, 40}, 1, 2, 1))
mlx.Eval(c.State()...)
if got := c.State()[0].Floats(); !slices.Equal(got, []float32{1, 2, 30, 40}) {
t.Fatalf("branch = %v", got)
}
c.Free()
if !c.Restore(captured[0], 2) || !c.Restore(captured[1], 3) || !c.Restore(whole, 4) {
t.Fatal("could not restore captured prefix")
}
for _, s := range captured {
s.Close()
}
mlx.Eval(c.State()...)
if got := c.State()[0].Floats(); !slices.Equal(got, []float32{1, 2, 3, 4}) {
t.Fatalf("restored original = %v", got)
}
left, right := c.Split(c.Snapshot(0), 1)
if left.Size() < 16 || right.Size() < 16 {
t.Fatal("snapshot view undercounts backing storage")
}
joined := c.Merge(left, right)
defer joined.Close()
c.Free()
if !c.Restore(joined, 4) || c.Restore(nil, 5) || c.Restore(nil, -1) {
t.Fatal("incorrect restore bounds")
}
mlx.Eval(c.State()...)
if got := c.State()[0].Floats(); !slices.Equal(got, []float32{1, 2, 3, 4}) {
t.Fatalf("merged original = %v", got)
}
})
}