Files
llmgw/internal/modelplan/cpuspeed_test.go
T
Ilker ManapandClaude Opus 5.5 84444e71c8
CI / test (push) Failing after 6m37s
How fast a model would answer on a CPU, before it is fetched
Each agent measures its node's memory read rate when it starts: every CPU
sums a share of a buffer past any cache, a tenth of free memory at most,
the best of four passes, in a fraction of a second; reported in Host
(mem_bandwidth_gbs) and NodeView. A token on a CPU reads every weight it
uses once, so one reply's speed is about that rate over those bytes:
modelplan.CPUTokensPerSecond, 0.68 of the measured rate plus 5 ms a token,
calibrated on the PoC against llama.cpp's predicted_per_second (node01
24.9 GB/s, qwen2.5-1.5b: 14.5 measured, 14.7 estimated; node05 41.9 GB/s,
qwen2.5-14b: 3.3 and 3.2). A model of experts named …-A3B reads its active
part (ActiveShare).

The explorer shows it as CPU tok/s, at Q4_K_M on the fastest node that
holds the model; a repository's page gives it for each GGUF by its size.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-27 00:09:47 +01:00

38 lines
1.1 KiB
Go

package modelplan
import (
"math"
"testing"
)
func TestCPUSpeedMatchesWhatThePoCMeasured(t *testing.T) {
for _, c := range []struct {
bytes int64
bw, want float64
}{
{1117320736, 24.9, 14.5}, // node01, qwen2.5-1.5b
{9_000_000_000, 41.9, 3.3}, // node05, qwen2.5-coder-14b
} {
got := CPUTokensPerSecond(c.bytes, c.bw)
if math.Abs(got-c.want)/c.want > 0.15 {
t.Errorf("%d bytes at %.1f GB/s: %.1f tok/s, measured %.1f", c.bytes, c.bw, got, c.want)
}
}
if CPUTokensPerSecond(0, 40) != 0 || CPUTokensPerSecond(1e9, 0) != 0 {
t.Error("an unknown size or bandwidth should give no figure")
}
}
func TestAModelOfExpertsReadsItsActiveShare(t *testing.T) {
for name, want := range map[string]float64{
"Qwen/Qwen3-30B-A3B-Instruct-2507-GGUF": 0.1,
"inclusionAI/Ling-flash-A2.5B": 2.5 / 30,
"Qwen/Qwen3-8B": 1,
"meta-llama/Llama-3.1-8B-Instruct": 1,
} {
if got := ActiveShare(name, 30e9); math.Abs(got-want) > 0.001 && !(want == 1 && got == 1) {
t.Errorf("%s: %.3f, want %.3f", name, got, want)
}
}
}