Group the mirror's table by model family, not by exact name
Grouped by name, the four qwens in the mirror were four groups of one and the table looked unchanged. A family is the letters a name starts with - qwen2.5-coder-7b and qwen3-8b are qwen, llama-3.1-8b is llama - and a family of two or more models gets a heading with how many and how much disk; a family of one stays a plain row. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
1 parent
06ea02dd57
commit
22bb098247
3 files changed
+83
-35
No files matched your search
@@ -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
|
||||
}
|
||||
|
||||
|
||||
@@ -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, "<strong>qwen</strong>"), strings.Index(body, "<strong>zeta</strong>")
|
||||
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, "<strong>qwen</strong>") || !strings.Contains(body, "3 models · 150 B") ||
|
||||
!strings.Contains(body, `<span class="tag new">downloading</span>`) {
|
||||
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, "<code>v1</code>"), strings.Index(body, "<code>v2</code>")
|
||||
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, "<strong>"+name+"</strong>"))
|
||||
}
|
||||
if !strings.Contains(body, "2 versions · 150 B") || !strings.Contains(body, `<span class="tag new">downloading</span>`) {
|
||||
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)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -31,15 +31,17 @@ reachable from this machine.</p>
|
||||
<h2>What the mirror holds</h2>
|
||||
{{if .Rows}}
|
||||
<table class="compact held">
|
||||
<tr><th>Version</th><th>Files</th><th class="num">Size</th><th>Runs</th><th></th></tr>
|
||||
{{range .Groups}}
|
||||
<tr class="model-group"><td colspan="5"><strong>{{.Model}}</strong>
|
||||
<span class="opt">{{len .Rows}} version{{if gt (len .Rows) 1}}s{{end}} · {{bytes .Bytes}}</span>
|
||||
<tr><th>Model</th><th>Files</th><th class="num">Size</th><th>Runs</th><th></th></tr>
|
||||
{{range .Groups}}{{$grouped := gt .Models 1}}
|
||||
{{if $grouped}}
|
||||
<tr class="model-group"><td colspan="5"><strong>{{.Family}}</strong>
|
||||
<span class="opt">{{.Models}} models · {{bytes .Bytes}}</span>
|
||||
{{if .Fetching}}<span class="tag new">downloading</span>{{end}}
|
||||
{{if .Failed}}<span class="tag bad">failed</span>{{end}}
|
||||
{{if .InUse}}<span class="tag">in use</span>{{end}}</td></tr>
|
||||
{{range .Rows}}<tr class="model-version">
|
||||
<td><code>{{.Version}}</code></td>
|
||||
{{end}}
|
||||
{{range .Rows}}<tr{{if $grouped}} class="model-version"{{end}}>
|
||||
<td><strong>{{.Model}}</strong> <span class="opt">{{.Version}}</span></td>
|
||||
<td class="file" title="{{.File}}{{if .SHA256}} · sha256 {{.SHA256}}{{end}}">
|
||||
{{if gt .Files 1}}{{.Files}} files{{else}}<code>{{.File}}</code>{{end}}</td>
|
||||
<td class="num">
|
||||
|
||||
Reference in new issue
Block a user