Skip to content

Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS

address review (codex): size a quant by its largest installable unit, not summed duplicates

[._.]/ Adam Eivy0e9d8d2f5e7a
diff --git a/server/services/huggingFaceCatalog.js b/server/services/huggingFaceCatalog.js
index 9b9500d6e6..ffd44474f3 100644
--- a/server/services/huggingFaceCatalog.js
+++ b/server/services/huggingFaceCatalog.js
@@ -320,24 +320,38 @@ function installIdForBackend(backend, repoId, file) {
// highest-quality build first. Files whose quant can't be parsed are skipped —
// they have no `:quant`/`@quant` tag a backend can pull. `usableBytes` annotates
// each variant with a fit verdict for the UI (null → 'unknown').
+// Collapse a multi-part shard filename to a key shared by its set
+// (`…-00001-of-00002.gguf` → `…-of-00002`); standalone files key to themselves.
+// Only files with the same key are one installable unit whose sizes sum.
+function shardSetKey(filename) {
+ const m = normalizeText(filename).match(/^(.*)-\d{5}-of-(\d{5})\.gguf$/i)
+ return m ? `${m[1]}-of-${m[2]}` : filename
+}
+
function buildVariants(model, backend, usableBytes) {
const repoId = repoIdOf(model)
+ // quant → (shard-set/standalone key → summed size). Backends install by quant
+ // tag (`:Q4_K_M` / `@Q4_K_M`), so one variant per quant — but the size is the
+ // largest single installable unit, not the sum across unrelated same-quant
+ // files (two standalone Q4_K_M builds must not read as one double-size variant).
const groups = new Map()
for (const file of ggufFilesOf(model)) {
const quant = quantFromFilename(file.name)
if (!quant) continue
- const group = groups.get(quant) || { quant, sizeBytes: 0 }
- group.sizeBytes += Number.isFinite(file.size) ? file.size : 0
- groups.set(quant, group)
+ const units = groups.get(quant) || new Map()
+ const key = shardSetKey(file.name)
+ units.set(key, (units.get(key) || 0) + (Number.isFinite(file.size) ? file.size : 0))
+ groups.set(quant, units)
}
- return [...groups.values()]
- .map((group) => {
- const sizeBytes = group.sizeBytes > 0 ? group.sizeBytes : null
+ return [...groups.entries()]
+ .map(([quant, units]) => {
+ const largestUnit = Math.max(0, ...units.values())
+ const sizeBytes = largestUnit > 0 ? largestUnit : null
return {
- quant: group.quant,
- installId: variantInstallId(backend, repoId, group.quant),
+ quant,
+ installId: variantInstallId(backend, repoId, quant),
sizeBytes,
- size: formatBytes(sizeBytes) || group.quant,
+ size: formatBytes(sizeBytes) || quant,
fit: classifyFit(sizeBytes, usableBytes)
}
})
diff --git a/server/services/huggingFaceCatalog.test.js b/server/services/huggingFaceCatalog.test.js
index aca41b814b..fce661b704 100644
--- a/server/services/huggingFaceCatalog.test.js
+++ b/server/services/huggingFaceCatalog.test.js
@@ -318,6 +318,23 @@ describe('huggingFaceCatalog', () => {
expect(result.id).toBe(`hf.co/${repo}:Q4_K_M`)
})
+ it('does not sum two standalone same-quant files into one double-size variant', async () => {
+ const repo = 'org/Dup-Quant-GGUF'
+ fetch
+ .mockResolvedValueOnce(listing(repo, ['Model-Q4_K_M.gguf', 'Model-v2-Q4_K_M.gguf']))
+ .mockResolvedValueOnce(blobs(repo, {
+ 'Model-Q4_K_M.gguf': 5_000_000_000,
+ 'Model-v2-Q4_K_M.gguf': 4_000_000_000,
+ }))
+
+ const [result] = await searchHuggingFaceModels({ backend: 'ollama', query: 'dup', systemMemoryBytes: 128 * 1024 ** 3 })
+
+ // One Q4_K_M variant (the tag installs one file), sized as the largest single
+ // unit (5 GB) — NOT 9 GB summed across two unrelated files.
+ expect(result.variants).toHaveLength(1)
+ expect(result.variants[0]).toMatchObject({ quant: 'Q4_K_M', sizeBytes: 5_000_000_000 })
+ })
+
it('treats a tiny machine (zero usable RAM) as a real budget: smallest variant, all too-large', async () => {
const repo = 'empero-ai/Qwythos-9B-Tiny-GGUF'
fetch