Group what the mirror holds by model
Each model is a heading - how many versions, how much disk, and whether one is downloading, failed or in use - with its versions beneath it. Sorted by state alone, versions of one model were scattered down the table around unrelated downloads. A model with a download or a failure still comes first. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
1 parent
7c5938effe
commit
06ea02dd57
4 files changed
+89
-3
No files matched your search
@@ -103,6 +103,8 @@ type adminMirrorData struct {
|
||||
Addr string
|
||||
Base string
|
||||
Rows []mirrorRow
|
||||
// Groups are the same rows under their model.
|
||||
Groups []mirrorGroup
|
||||
|
||||
Fetching int
|
||||
Present int
|
||||
@@ -445,12 +447,57 @@ func (p *AccountPages) renderMirror(w http.ResponseWriter, r *http.Request,
|
||||
return a.File < b.File
|
||||
})
|
||||
|
||||
d.Groups = groupByModel(d.Rows)
|
||||
|
||||
if d.Fetching > 0 {
|
||||
d.RefreshSec = 5
|
||||
}
|
||||
render(w, "admin_mirror", d)
|
||||
}
|
||||
|
||||
// mirrorGroup is every version the mirror holds of one model.
|
||||
type mirrorGroup struct {
|
||||
Model string
|
||||
Rows []mirrorRow
|
||||
// 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.
|
||||
//
|
||||
// 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.
|
||||
func groupByModel(rows []mirrorRow) []mirrorGroup {
|
||||
var out []mirrorGroup
|
||||
at := map[string]int{}
|
||||
for _, r := range rows {
|
||||
i, ok := at[r.Model]
|
||||
if !ok {
|
||||
i = len(out)
|
||||
at[r.Model] = i
|
||||
out = append(out, mirrorGroup{Model: r.Model})
|
||||
}
|
||||
g := &out[i]
|
||||
g.Rows = append(g.Rows, r)
|
||||
g.Bytes += r.BytesDone
|
||||
switch r.State {
|
||||
case mirror.Fetching:
|
||||
g.Fetching++
|
||||
case mirror.Failed:
|
||||
g.Failed++
|
||||
}
|
||||
if len(r.UsedBy) > 0 {
|
||||
g.InUse = true
|
||||
}
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
func mirrorRank(s mirror.State) int {
|
||||
switch s {
|
||||
case mirror.Fetching:
|
||||
|
||||
@@ -600,3 +600,30 @@ func TestHowAModelRunsIsChangedWhereItsFileIsShown(t *testing.T) {
|
||||
t.Errorf("on demand was sent as %+v", cat.lastScale)
|
||||
}
|
||||
}
|
||||
|
||||
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.
|
||||
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},
|
||||
}}
|
||||
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)
|
||||
}
|
||||
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)
|
||||
}
|
||||
// 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)
|
||||
}
|
||||
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")
|
||||
}
|
||||
}
|
||||
@@ -543,3 +543,8 @@ td.load { white-space: nowrap; min-width: 8.5rem; }
|
||||
.minibar.hot > span { background: var(--bad); }
|
||||
.load-v { font-variant-numeric: tabular-nums; font-size: .85rem; }
|
||||
table.nodes td:first-child code { white-space: nowrap; }
|
||||
/* The mirror's table, grouped by model: a heading row, then its versions. */
|
||||
table.held tr.model-group > td { background: var(--bg); padding-top: .7rem; border-bottom: 1px solid var(--line); }
|
||||
table.held tr.model-group strong { font-size: .95rem; }
|
||||
table.held tr.model-version > td:first-child { padding-left: 1.4rem; }
|
||||
.tag.bad { color: var(--bad); border-color: var(--bad); }
|
||||
@@ -31,9 +31,15 @@ reachable from this machine.</p>
|
||||
<h2>What the mirror holds</h2>
|
||||
{{if .Rows}}
|
||||
<table class="compact held">
|
||||
<tr><th>Model</th><th>Files</th><th class="num">Size</th><th>Runs</th><th></th></tr>
|
||||
{{range .Rows}}<tr>
|
||||
<td><strong>{{.Model}}</strong> <span class="opt">{{.Version}}</span></td>
|
||||
<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>
|
||||
{{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>
|
||||
<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">
|
||||
@@ -163,6 +169,7 @@ job by name if you would rather pin it.</p>
|
||||
</td></tr>
|
||||
{{end}}
|
||||
{{end}}
|
||||
{{end}}
|
||||
</table>
|
||||
<p class="note">“copy address” gives what a catalog entry's <code>source</code>
|
||||
should say — the file, or for a version of several files the directory, with its
|
||||
|
||||
Reference in new issue
Block a user