diff --git a/internal/web/admin_mirror.go b/internal/web/admin_mirror.go index 358b3753..d9e5e57d 100644 --- a/internal/web/admin_mirror.go +++ b/internal/web/admin_mirror.go @@ -455,36 +455,58 @@ func (p *AccountPages) renderMirror(w http.ResponseWriter, r *http.Request, render(w, "admin_mirror", d) } -// mirrorGroup is every version the mirror holds of one model. +// mirrorGroup is a family of models the mirror holds — every qwen, every +// llama — and their versions. type mirrorGroup struct { - Model string - Rows []mirrorRow + Family string + Rows []mirrorRow + // Models is how many different models are in it; a family of one is + // shown without a heading, which would only repeat its row. + Models int // Bytes is what the versions take on disk, downloads so far included. Bytes int64 Fetching, Failed int InUse bool } -// groupByModel gathers rows under their model, in the order the rows are -// already in: a model downloading or failed comes first because its first row -// does, and its versions stay in that order beneath it. +// modelFamily is the family a model's name puts it in: the letters its name +// starts with. "qwen2.5-coder-7b-instruct" and "qwen3-8b" are qwen, +// "llama-3.1-8b-instruct" is llama, "deepseek-r1-distill-qwen-14b" is +// deepseek — which is how people talk about them, and all a name says. +func modelFamily(model string) string { + name := strings.ToLower(model) + end := strings.IndexFunc(name, func(r rune) bool { return r < 'a' || r > 'z' }) + if end <= 0 { + // Starts with a digit or a symbol: the first part whole. + first, _, _ := strings.Cut(name, "-") + return first + } + return name[:end] +} + +// groupByModel gathers rows by family, in the order the rows are already in: +// a family with a download or a failure comes first because its first row +// does, and its models and versions stay in that order beneath it. // -// Grouped because a model is what somebody looks for. Sorted by state alone, -// three versions of one model were three rows scattered down the table, and -// "which versions of this do we have" meant reading all of it. +// Grouped because a family is what somebody looks for. Sorted by state and +// name alone, "which qwens do we have" meant reading the whole table. func groupByModel(rows []mirrorRow) []mirrorGroup { var out []mirrorGroup at := map[string]int{} + models := map[string]map[string]bool{} for _, r := range rows { - i, ok := at[r.Model] + fam := modelFamily(r.Model) + i, ok := at[fam] if !ok { i = len(out) - at[r.Model] = i - out = append(out, mirrorGroup{Model: r.Model}) + at[fam] = i + out = append(out, mirrorGroup{Family: fam}) + models[fam] = map[string]bool{} } g := &out[i] g.Rows = append(g.Rows, r) g.Bytes += r.BytesDone + models[fam][r.Model] = true switch r.State { case mirror.Fetching: g.Fetching++ @@ -495,6 +517,9 @@ func groupByModel(rows []mirrorRow) []mirrorGroup { g.InUse = true } } + for i := range out { + out[i].Models = len(models[out[i].Family]) + } return out } diff --git a/internal/web/admin_mirror_test.go b/internal/web/admin_mirror_test.go index ba4e7df3..efe6e5c7 100644 --- a/internal/web/admin_mirror_test.go +++ b/internal/web/admin_mirror_test.go @@ -601,29 +601,50 @@ func TestHowAModelRunsIsChangedWhereItsFileIsShown(t *testing.T) { } } -func TestTheMirrorsTableIsGroupedByModel(t *testing.T) { - // Sorted by state alone, two versions of qwen sat either side of an - // unrelated download; grouped, they are together under one heading. +func TestTheMirrorsTableIsGroupedByFamily(t *testing.T) { + // Four qwens under four different names were four rows with nothing in + // common; grouped, they sit under one heading. A family of one gets no + // heading, which would only repeat its row. m := &fakeMirror{models: []mirror.Status{ - {Model: "qwen", Version: "v1", File: "a.gguf", State: mirror.Present, BytesDone: 100}, - {Model: "zeta", Version: "v1", File: "z.gguf", State: mirror.Present, BytesDone: 5}, - {Model: "qwen", Version: "v2", File: "b.gguf", State: mirror.Fetching, BytesDone: 50}, + {Model: "qwen2.5-coder-7b-instruct", Version: "v1", File: "a.gguf", State: mirror.Present, BytesDone: 100}, + {Model: "llama-3.1-8b-instruct", Version: "v1", File: "l.gguf", State: mirror.Present, BytesDone: 5}, + {Model: "qwen2.5-14b-instruct", Version: "v1", File: "b.gguf", State: mirror.Present, BytesDone: 40}, + {Model: "qwen3-8b", Version: "v2", File: "c.gguf", State: mirror.Fetching, BytesDone: 10}, }} body := mirrorGet(t, mirrorPage(t, m, true), "/admin/mirror").Body.String() - if n := strings.Count(body, `class="model-group"`); n != 2 { - t.Fatalf("%d model headings, want 2", n) + if n := strings.Count(body, `class="model-group"`); n != 1 { + t.Fatalf("%d family headings, want 1 (qwen)", n) } - qwen, zeta := strings.Index(body, "qwen"), strings.Index(body, "zeta") - if qwen < 0 || zeta < 0 || qwen > zeta { - t.Errorf("a model with a download should come first: qwen at %d, zeta at %d", qwen, zeta) + if !strings.Contains(body, "qwen") || !strings.Contains(body, "3 models · 150 B") || + !strings.Contains(body, `downloading`) { + t.Error("the qwen heading should count its models, total them and say one is downloading") } - // Both of qwen's versions come before zeta's heading. - v1, v2 := strings.Index(body, "v1"), strings.Index(body, "v2") - if v2 > zeta || v1 > zeta { - t.Errorf("qwen's versions are not under its heading: v1 %d v2 %d zeta %d", v1, v2, zeta) + // The downloading family first, its models together, then llama. + var at []int + for _, name := range []string{"qwen3-8b", "qwen2.5-14b-instruct", "qwen2.5-coder-7b-instruct", "llama-3.1-8b-instruct"} { + at = append(at, strings.Index(body, ""+name+"")) } - if !strings.Contains(body, "2 versions · 150 B") || !strings.Contains(body, `downloading`) { - t.Error("the heading should total its versions and say one is downloading") + for i := 1; i < len(at); i++ { + if at[i-1] < 0 || at[i] < at[i-1] { + t.Errorf("rows out of order: %v", at) + } + } +} + +func TestAModelsFamilyIsHowItsNameStarts(t *testing.T) { + for name, want := range map[string]string{ + "qwen2.5-coder-14b-instruct": "qwen", + "qwen3-8b": "qwen", + "Qwen2.5-14B-Instruct": "qwen", + "llama-3.1-8b-instruct": "llama", + "deepseek-r1-distill-qwen-14b": "deepseek", + "phi-4": "phi", + "bge-m3": "bge", + "4bit-thing": "4bit", + } { + if got := modelFamily(name); got != want { + t.Errorf("%s is %q, want %q", name, got, want) + } } } diff --git a/internal/web/templates/admin_mirror.html b/internal/web/templates/admin_mirror.html index 6a60152c..17b7345e 100644 --- a/internal/web/templates/admin_mirror.html +++ b/internal/web/templates/admin_mirror.html @@ -31,15 +31,17 @@ reachable from this machine.

What the mirror holds

{{if .Rows}} - -{{range .Groups}} - +{{range .Groups}}{{$grouped := gt .Models 1}} +{{if $grouped}} + -{{range .Rows}} - +{{end}} +{{range .Rows}} +
VersionFilesSizeRuns
{{.Model}} - {{len .Rows}} version{{if gt (len .Rows) 1}}s{{end}} · {{bytes .Bytes}} +
ModelFilesSizeRuns
{{.Family}} + {{.Models}} models · {{bytes .Bytes}} {{if .Fetching}}downloading{{end}} {{if .Failed}}failed{{end}} {{if .InUse}}in use{{end}}
{{.Version}}{{.Model}} {{.Version}} {{if gt .Files 1}}{{.Files}} files{{else}}{{.File}}{{end}}