@bike4mind/cli 4.0.0 → 4.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +184 -4
- package/bin/bike4mind-cli.mjs +249 -40
- package/bin/envFlags.d.mts +17 -0
- package/bin/envFlags.mjs +89 -0
- package/dist/{AgentHistoryStore-DgqmcVLN.mjs → AgentHistoryStore-Bvmcy2kf.mjs} +3807 -1375
- package/dist/{ApiClient-_JrM_xWw.mjs → ApiClient-Yp2LPlX3.mjs} +22 -3
- package/dist/BubblewrapRuntime-OI4qFPNB.mjs +157 -0
- package/dist/ConfigStore-Bo4od3Eu.mjs +2 -0
- package/dist/ConfigStore-CP1W86Ui.mjs +3438 -0
- package/dist/{ConfigStore-BwqsQ0U9.mjs → Logger-3RbeTZ9o.mjs} +34769 -22138
- package/dist/{ProxyManager-B0-RuR2w.mjs → ProxyManager-TxEKlgdO.mjs} +88 -3
- package/dist/{RemoteSkillSource-qTvRkaNA.mjs → RemoteSkillSource-D_F99yBR.mjs} +5 -0
- package/dist/{SandboxOrchestrator-BcUv9fQ3.mjs → SandboxOrchestrator-lpxVEFO7.mjs} +26 -7
- package/dist/SandboxRuntimeAdapter-C3xICJtQ.mjs +190 -0
- package/dist/SandboxRuntimeAdapter-u6c_IrjP.mjs +2 -0
- package/dist/SeatbeltRuntime-Ccd_QbjX.mjs +194 -0
- package/dist/{WorkItemsClient-CERTDrhT.mjs → WorkItemsClient-D4sFGL9X.mjs} +1 -1
- package/dist/agents/defaults/review.md +8 -1
- package/dist/agents/defaults/test.md +8 -1
- package/dist/buildToolSearch-CqHKSLtG.mjs +417 -0
- package/dist/commands/acpCommand.mjs +26 -20
- package/dist/commands/apiCommand.mjs +3 -5
- package/dist/commands/doctorCommand.mjs +2 -2
- package/dist/commands/envCommand.mjs +1 -1
- package/dist/commands/headlessCommand.mjs +118 -37
- package/dist/commands/hostCommand.mjs +2344 -0
- package/dist/commands/mcpCommand.mjs +45 -30
- package/dist/commands/mirrorCommand.mjs +279 -0
- package/dist/commands/modelsCommand.mjs +1117 -0
- package/dist/commands/pluginCommand.mjs +9 -9
- package/dist/commands/skillsCommand.mjs +175 -30
- package/dist/commands/updateCommand.mjs +2 -2
- package/dist/curated-build.json +1 -0
- package/dist/dist-BPhZ0dCz.mjs +4776 -0
- package/dist/dist-K7a9yOUb.mjs +7864 -0
- package/dist/fit-BOnDsgbk.mjs +200 -0
- package/dist/{grepSearch-BgoOOwGe-B388GxRD.mjs → grepSearch-CLtEqT4j-BnKPtNWr.mjs} +2 -2
- package/dist/index.mjs +3215 -508
- package/dist/modelHub-BSB6qRFP.mjs +1963 -0
- package/dist/modelServers-B7zI5XnO.mjs +2465 -0
- package/dist/{package-CQaam4Dq.mjs → package-WlxLVpUb.mjs} +1 -1
- package/dist/{serve-CFxUhjml.mjs → serve-DpsV0mag.mjs} +599 -26
- package/dist/store-Bpdo9Syo.mjs +2 -0
- package/dist/{store-BbvSi3KK.mjs → store-xeJRhBtO.mjs} +2 -0
- package/dist/types-BFIvwByC.mjs +2 -0
- package/dist/{types-F61_hxmG.mjs → types-CxrzVXel.mjs} +9 -5
- package/dist/{updateChecker-CCLVVdH0.mjs → updateChecker-Boq0RruU.mjs} +7 -29
- package/package.json +17 -14
- package/dist/BubblewrapRuntime-5bLPTwEC.mjs +0 -72
- package/dist/SandboxRuntimeAdapter-BgLUVTJL.mjs +0 -57
- package/dist/SandboxRuntimeAdapter-Bt1wPpld.mjs +0 -2
- package/dist/SeatbeltRuntime-C_Y8q8Mr.mjs +0 -124
- package/dist/buildToolSearch-D9GEK91u.mjs +0 -2351
- package/dist/dist-Ul2qwn5x.mjs +0 -624
- package/dist/store-BYeE0shc.mjs +0 -2
- package/dist/types-I45lMh7Q.mjs +0 -2
|
@@ -0,0 +1,1963 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { z as z$1 } from "zod";
|
|
3
|
+
//#region ../../b4m-core/common/dist/modelHub/index.mjs
|
|
4
|
+
const MAX_LAYERS = 1024;
|
|
5
|
+
const MAX_CONTEXT = 2 ** 24;
|
|
6
|
+
const MAX_BYTES = 2 ** 50;
|
|
7
|
+
const MAX_ENTRIES = 500;
|
|
8
|
+
const MAX_FAMILIES = 200;
|
|
9
|
+
const MAX_BUILDS = 16;
|
|
10
|
+
const MAX_CHANGELOG = 200;
|
|
11
|
+
const MAX_TIERS = 32;
|
|
12
|
+
/** The highest curated list sequence; the publish script also caps each step over live. */
|
|
13
|
+
const HUB_MAX_SEQUENCE = 1e6;
|
|
14
|
+
const MAX_SEQUENCE = HUB_MAX_SEQUENCE;
|
|
15
|
+
/** The shortest trained context, in tokens, a chat entry may declare. */
|
|
16
|
+
const MIN_CHAT_CONTEXT = 16384;
|
|
17
|
+
function isPublicHttpsUrl(value) {
|
|
18
|
+
if (value.length > 2048) return false;
|
|
19
|
+
let url;
|
|
20
|
+
try {
|
|
21
|
+
url = new URL(value);
|
|
22
|
+
} catch {
|
|
23
|
+
return false;
|
|
24
|
+
}
|
|
25
|
+
if (url.protocol !== "https:" || url.username || url.password) return false;
|
|
26
|
+
const { hostname } = url;
|
|
27
|
+
return /^(?:[a-z0-9-]+\.)+(?:[a-z]{2,}|xn--[a-z0-9-]+)$/.test(hostname) && !/\.(?:localhost|local|internal)$/.test(hostname);
|
|
28
|
+
}
|
|
29
|
+
const HttpsUrlSchema = z$1.string().max(2048).regex(/^https:\/\//).refine(isPublicHttpsUrl, "Invalid URL");
|
|
30
|
+
const Sha256Schema = z$1.string().regex(/^[0-9a-f]{64}$/);
|
|
31
|
+
const CommitShaSchema = z$1.string().regex(/^[0-9a-f]{40}$/);
|
|
32
|
+
const ByteCountSchema$1 = z$1.number().int().positive().max(MAX_BYTES);
|
|
33
|
+
const SlugSchema = z$1.string().max(64).regex(/^[a-z0-9]+(?:-[a-z0-9]+)*$/);
|
|
34
|
+
const HfRepoSchema = z$1.string().max(200).regex(/^[A-Za-z0-9][A-Za-z0-9_.-]*\/[A-Za-z0-9][A-Za-z0-9_.-]*$/);
|
|
35
|
+
const RepoPathSchema = z$1.string().max(200).regex(/^(?:[A-Za-z0-9_][A-Za-z0-9_.-]*\/)?[A-Za-z0-9_][A-Za-z0-9_.-]*\.gguf$/);
|
|
36
|
+
const OllamaLibRefSchema = z$1.string().max(128).regex(/^[a-z0-9][a-z0-9._-]*:[a-z0-9][A-Za-z0-9_.-]*$/);
|
|
37
|
+
const OllamaNameSchema = z$1.string().max(32).regex(/^[a-z0-9][a-z0-9.-]*$/);
|
|
38
|
+
const SemverSchema = z$1.string().regex(/^[0-9]{1,4}\.[0-9]{1,4}\.[0-9]{1,4}$/);
|
|
39
|
+
const RuntimeVersionSchema = z$1.string().min(1).max(32);
|
|
40
|
+
const CountSchema$1 = z$1.number().int().nonnegative().max(1e6);
|
|
41
|
+
const TotalSchema = z$1.number().int().positive().max(1e6);
|
|
42
|
+
const RateSchema = z$1.number().positive().max(1e6);
|
|
43
|
+
const LayerCountSchema = z$1.number().int().nonnegative().max(MAX_LAYERS);
|
|
44
|
+
const ContextSchema = z$1.number().int().positive().max(MAX_CONTEXT);
|
|
45
|
+
const HUB_ROLES = [
|
|
46
|
+
"chat",
|
|
47
|
+
"code",
|
|
48
|
+
"vision",
|
|
49
|
+
"embeddings"
|
|
50
|
+
];
|
|
51
|
+
const HubRoleSchema = z$1.enum(HUB_ROLES);
|
|
52
|
+
const HUB_RUNTIMES = ["ollama", "llama-server"];
|
|
53
|
+
const HubRuntimeSchema = z$1.enum(HUB_RUNTIMES);
|
|
54
|
+
const VARIANT_TYPES = [
|
|
55
|
+
"official",
|
|
56
|
+
"requant",
|
|
57
|
+
"fine-tune",
|
|
58
|
+
"merge",
|
|
59
|
+
"abliterated",
|
|
60
|
+
"distill",
|
|
61
|
+
"expert-pruned"
|
|
62
|
+
];
|
|
63
|
+
const PRODUCER_TIERS = [
|
|
64
|
+
"A",
|
|
65
|
+
"B",
|
|
66
|
+
"C"
|
|
67
|
+
];
|
|
68
|
+
const LICENSE_CLASSES = [
|
|
69
|
+
"permissive",
|
|
70
|
+
"restricted-commercial",
|
|
71
|
+
"research",
|
|
72
|
+
"non-commercial"
|
|
73
|
+
];
|
|
74
|
+
const KV_CACHE_TYPES = [
|
|
75
|
+
"f16",
|
|
76
|
+
"q8_0",
|
|
77
|
+
"q4_0"
|
|
78
|
+
];
|
|
79
|
+
const RECURRENT_KINDS = ["mamba2", "gated-delta-net"];
|
|
80
|
+
const REASONING_EFFORTS = [
|
|
81
|
+
"off",
|
|
82
|
+
"low",
|
|
83
|
+
"medium",
|
|
84
|
+
"high"
|
|
85
|
+
];
|
|
86
|
+
const ROUTE_REASONS = [
|
|
87
|
+
"library-tag",
|
|
88
|
+
"renderer-known",
|
|
89
|
+
"sharded",
|
|
90
|
+
"no-ollama-renderer",
|
|
91
|
+
"expert-offload",
|
|
92
|
+
"per-model-kv",
|
|
93
|
+
"lazy-mode",
|
|
94
|
+
"draft-sidecar",
|
|
95
|
+
"template-override"
|
|
96
|
+
];
|
|
97
|
+
const EVIDENCE_KINDS = [
|
|
98
|
+
"kld",
|
|
99
|
+
"ppl",
|
|
100
|
+
"benchmark",
|
|
101
|
+
"tool-eval",
|
|
102
|
+
"own-eval",
|
|
103
|
+
"speed"
|
|
104
|
+
];
|
|
105
|
+
const SMOKE_CHECKS = [
|
|
106
|
+
"acquire",
|
|
107
|
+
"show",
|
|
108
|
+
"load",
|
|
109
|
+
"plain",
|
|
110
|
+
"think",
|
|
111
|
+
"tool",
|
|
112
|
+
"image",
|
|
113
|
+
"draft"
|
|
114
|
+
];
|
|
115
|
+
const EVIDENCE_GRADES = [
|
|
116
|
+
"A",
|
|
117
|
+
"B",
|
|
118
|
+
"C",
|
|
119
|
+
"D"
|
|
120
|
+
];
|
|
121
|
+
const AttnGroupSchema = z$1.object({
|
|
122
|
+
layers: LayerCountSchema,
|
|
123
|
+
kvHeads: z$1.number().int().positive().max(1024),
|
|
124
|
+
keyLength: z$1.number().int().positive().max(4096),
|
|
125
|
+
valueLength: z$1.number().int().positive().max(4096)
|
|
126
|
+
});
|
|
127
|
+
/**
|
|
128
|
+
* Per-layer-type shape that drives KV and state memory. `@bike4mind/local-models` extracts the same shape
|
|
129
|
+
* from GGUF headers and `/api/show`; keep the two in sync.
|
|
130
|
+
*/
|
|
131
|
+
const ModelArchSchema = z$1.object({
|
|
132
|
+
contextMax: ContextSchema,
|
|
133
|
+
blockCount: z$1.number().int().positive().max(MAX_LAYERS),
|
|
134
|
+
headCount: z$1.number().int().positive().max(4096).optional(),
|
|
135
|
+
embeddingLength: z$1.number().int().positive().max(65536).optional(),
|
|
136
|
+
activeFeedForwardLength: z$1.number().int().positive().max(1048576).optional(),
|
|
137
|
+
full: AttnGroupSchema,
|
|
138
|
+
swa: AttnGroupSchema.extend({ window: z$1.number().int().nonnegative().max(MAX_CONTEXT) }).optional(),
|
|
139
|
+
mla: z$1.object({
|
|
140
|
+
layers: LayerCountSchema.positive(),
|
|
141
|
+
kvLoraRank: z$1.number().int().positive().max(16384),
|
|
142
|
+
ropeDim: z$1.number().int().positive().max(4096)
|
|
143
|
+
}).optional(),
|
|
144
|
+
recurrent: z$1.object({
|
|
145
|
+
layers: LayerCountSchema.positive(),
|
|
146
|
+
stateBytesPerSeq: ByteCountSchema$1,
|
|
147
|
+
kind: z$1.string().min(1).max(32).optional()
|
|
148
|
+
}).optional(),
|
|
149
|
+
mtpLayers: LayerCountSchema.default(0),
|
|
150
|
+
moe: z$1.object({
|
|
151
|
+
experts: z$1.number().int().positive().max(4096),
|
|
152
|
+
used: z$1.number().int().positive().max(4096),
|
|
153
|
+
moeLayers: LayerCountSchema.positive()
|
|
154
|
+
}).optional(),
|
|
155
|
+
kvProbe: z$1.object({
|
|
156
|
+
bytesPerToken: z$1.number().positive().max(2 ** 24),
|
|
157
|
+
fixedBytes: z$1.number().nonnegative().max(MAX_BYTES),
|
|
158
|
+
source: z$1.literal("llama-fit-params"),
|
|
159
|
+
runtime: RuntimeVersionSchema
|
|
160
|
+
}).optional()
|
|
161
|
+
});
|
|
162
|
+
const GgufFileSchema = z$1.object({
|
|
163
|
+
path: RepoPathSchema,
|
|
164
|
+
sizeBytes: ByteCountSchema$1,
|
|
165
|
+
sha256: Sha256Schema
|
|
166
|
+
});
|
|
167
|
+
const QuantSchema = z$1.object({
|
|
168
|
+
label: z$1.string().regex(/^[A-Za-z0-9_.-]{2,40}$/),
|
|
169
|
+
family: z$1.enum([
|
|
170
|
+
"K",
|
|
171
|
+
"IQ",
|
|
172
|
+
"legacy",
|
|
173
|
+
"MXFP4",
|
|
174
|
+
"NVFP4",
|
|
175
|
+
"float",
|
|
176
|
+
"custom"
|
|
177
|
+
]),
|
|
178
|
+
scheme: z$1.enum([
|
|
179
|
+
"standard",
|
|
180
|
+
"imatrix",
|
|
181
|
+
"unsloth-dynamic",
|
|
182
|
+
"gsq-rco",
|
|
183
|
+
"byteshape",
|
|
184
|
+
"neo-imatrix",
|
|
185
|
+
"custom"
|
|
186
|
+
]),
|
|
187
|
+
bpw: z$1.number().positive().max(32)
|
|
188
|
+
});
|
|
189
|
+
const DraftSchema = z$1.discriminatedUnion("kind", [z$1.object({
|
|
190
|
+
kind: z$1.literal("mtp-embedded"),
|
|
191
|
+
layers: z$1.number().int().positive().max(16)
|
|
192
|
+
}), z$1.object({
|
|
193
|
+
kind: z$1.enum([
|
|
194
|
+
"mtp-sidecar",
|
|
195
|
+
"dflash",
|
|
196
|
+
"eagle3"
|
|
197
|
+
]),
|
|
198
|
+
file: GgufFileSchema
|
|
199
|
+
})]);
|
|
200
|
+
const ModelfileOverrideSchema = z$1.object({
|
|
201
|
+
renderer: OllamaNameSchema.optional(),
|
|
202
|
+
parser: OllamaNameSchema.optional(),
|
|
203
|
+
templateRef: SlugSchema.optional(),
|
|
204
|
+
dropStops: z$1.array(z$1.string().min(1).max(32)).max(8).default([]),
|
|
205
|
+
draftNumPredict: z$1.number().int().min(0).max(16).optional()
|
|
206
|
+
});
|
|
207
|
+
const OllamaLayersSchema = z$1.object({
|
|
208
|
+
template: Sha256Schema.nullable(),
|
|
209
|
+
params: Sha256Schema.nullable(),
|
|
210
|
+
license: Sha256Schema.nullable(),
|
|
211
|
+
numCtx: ContextSchema.nullable(),
|
|
212
|
+
projector: Sha256Schema.nullable().default(null),
|
|
213
|
+
projectorBytes: ByteCountSchema$1.optional(),
|
|
214
|
+
draft: Sha256Schema.nullable().default(null),
|
|
215
|
+
draftNumPredict: z$1.number().int().min(0).max(16).optional(),
|
|
216
|
+
installedTemplate: Sha256Schema.optional()
|
|
217
|
+
}).refine((layers) => layers.params !== null || layers.numCtx === null, { message: "numCtx needs a params layer" }).refine((layers) => layers.params !== null || layers.draftNumPredict === void 0, { message: "draftNumPredict needs a params layer" }).refine((layers) => layers.projector !== null || layers.projectorBytes === void 0, { message: "projectorBytes needs a projector layer" });
|
|
218
|
+
const OllamaSourceSchema = z$1.discriminatedUnion("kind", [
|
|
219
|
+
z$1.object({
|
|
220
|
+
kind: z$1.literal("library"),
|
|
221
|
+
ref: OllamaLibRefSchema,
|
|
222
|
+
sizeBytes: ByteCountSchema$1,
|
|
223
|
+
digest: Sha256Schema,
|
|
224
|
+
layers: OllamaLayersSchema.optional()
|
|
225
|
+
}),
|
|
226
|
+
z$1.object({
|
|
227
|
+
kind: z$1.literal("hf-pull"),
|
|
228
|
+
modelfile: ModelfileOverrideSchema,
|
|
229
|
+
layers: OllamaLayersSchema.optional()
|
|
230
|
+
}),
|
|
231
|
+
z$1.object({
|
|
232
|
+
kind: z$1.literal("create"),
|
|
233
|
+
modelfile: ModelfileOverrideSchema
|
|
234
|
+
})
|
|
235
|
+
]);
|
|
236
|
+
const KvPairSchema = z$1.object({
|
|
237
|
+
k: z$1.enum(KV_CACHE_TYPES),
|
|
238
|
+
v: z$1.enum(KV_CACHE_TYPES)
|
|
239
|
+
});
|
|
240
|
+
const LlamaServerPresetSchema = z$1.object({
|
|
241
|
+
kv: z$1.union([z$1.literal("auto"), KvPairSchema]).default("auto"),
|
|
242
|
+
flashAttn: z$1.enum([
|
|
243
|
+
"auto",
|
|
244
|
+
"on",
|
|
245
|
+
"off"
|
|
246
|
+
]).default("auto"),
|
|
247
|
+
ubatch: z$1.number().int().min(64).max(8192).default(512),
|
|
248
|
+
batch: z$1.number().int().min(64).max(8192).default(2048),
|
|
249
|
+
nCpuMoe: z$1.union([z$1.literal("auto"), LayerCountSchema]).default("auto"),
|
|
250
|
+
slots: z$1.literal(1).default(1),
|
|
251
|
+
speculative: z$1.object({
|
|
252
|
+
type: z$1.enum([
|
|
253
|
+
"none",
|
|
254
|
+
"draft-mtp",
|
|
255
|
+
"dflash",
|
|
256
|
+
"eagle3"
|
|
257
|
+
]),
|
|
258
|
+
draftMax: z$1.number().int().min(1).max(16)
|
|
259
|
+
}).default({
|
|
260
|
+
type: "none",
|
|
261
|
+
draftMax: 3
|
|
262
|
+
}),
|
|
263
|
+
lazyMode: z$1.enum([
|
|
264
|
+
"auto",
|
|
265
|
+
"on",
|
|
266
|
+
"off"
|
|
267
|
+
]).default("auto"),
|
|
268
|
+
loadMmproj: z$1.enum([
|
|
269
|
+
"vision-only",
|
|
270
|
+
"always",
|
|
271
|
+
"never"
|
|
272
|
+
]).default("vision-only"),
|
|
273
|
+
chatTemplateRef: SlugSchema.optional(),
|
|
274
|
+
ctxCap: ContextSchema.optional()
|
|
275
|
+
});
|
|
276
|
+
const RoutingSchema = z$1.object({
|
|
277
|
+
preferred: HubRuntimeSchema,
|
|
278
|
+
reasons: z$1.array(z$1.enum(ROUTE_REASONS)).max(16),
|
|
279
|
+
ollamaFallback: z$1.boolean()
|
|
280
|
+
});
|
|
281
|
+
const ToolCallSchema = z$1.object({
|
|
282
|
+
exact: CountSchema$1,
|
|
283
|
+
nearMiss: CountSchema$1,
|
|
284
|
+
malformed: CountSchema$1,
|
|
285
|
+
of: TotalSchema
|
|
286
|
+
});
|
|
287
|
+
const OwnEvalSchema = z$1.object({
|
|
288
|
+
suite: z$1.string().regex(/^b4m-local-v[0-9]{1,4}$/),
|
|
289
|
+
hardware: SlugSchema,
|
|
290
|
+
runtime: HubRuntimeSchema,
|
|
291
|
+
runtimeVersion: RuntimeVersionSchema,
|
|
292
|
+
presetHash: Sha256Schema,
|
|
293
|
+
context: ContextSchema,
|
|
294
|
+
kv: z$1.enum(KV_CACHE_TYPES),
|
|
295
|
+
toolCall: ToolCallSchema,
|
|
296
|
+
parentToolCall: ToolCallSchema.optional(),
|
|
297
|
+
coding: z$1.object({
|
|
298
|
+
passed: CountSchema$1,
|
|
299
|
+
of: TotalSchema
|
|
300
|
+
}),
|
|
301
|
+
recall: z$1.object({
|
|
302
|
+
passed: CountSchema$1,
|
|
303
|
+
of: TotalSchema
|
|
304
|
+
}),
|
|
305
|
+
decodeTokS: RateSchema,
|
|
306
|
+
prefillTokS: RateSchema,
|
|
307
|
+
peakBytes: ByteCountSchema$1,
|
|
308
|
+
estimateBytes: ByteCountSchema$1,
|
|
309
|
+
thinkingTokensMedian: CountSchema$1,
|
|
310
|
+
refusals: z$1.object({
|
|
311
|
+
n: CountSchema$1,
|
|
312
|
+
of: TotalSchema
|
|
313
|
+
}).optional()
|
|
314
|
+
});
|
|
315
|
+
const EvidenceSchema = z$1.object({
|
|
316
|
+
kind: z$1.enum(EVIDENCE_KINDS),
|
|
317
|
+
source: HttpsUrlSchema,
|
|
318
|
+
metric: z$1.string().min(1).max(80),
|
|
319
|
+
value: z$1.number().min(-0xe8d4a51000).max(0xe8d4a51000),
|
|
320
|
+
measured: z$1.object({
|
|
321
|
+
target: z$1.enum([
|
|
322
|
+
"exact",
|
|
323
|
+
"sibling",
|
|
324
|
+
"base"
|
|
325
|
+
]),
|
|
326
|
+
sha256: Sha256Schema.optional(),
|
|
327
|
+
file: z$1.string().max(200).optional(),
|
|
328
|
+
runtime: z$1.string().max(40).optional()
|
|
329
|
+
}),
|
|
330
|
+
independent: z$1.boolean(),
|
|
331
|
+
reproducible: z$1.boolean(),
|
|
332
|
+
samples: z$1.object({
|
|
333
|
+
n: TotalSchema,
|
|
334
|
+
seeds: TotalSchema.optional()
|
|
335
|
+
}).optional(),
|
|
336
|
+
date: z$1.iso.date(),
|
|
337
|
+
ownEval: OwnEvalSchema.optional()
|
|
338
|
+
});
|
|
339
|
+
const SmokeSchema = z$1.object({
|
|
340
|
+
runtime: HubRuntimeSchema,
|
|
341
|
+
runtimeVersion: RuntimeVersionSchema,
|
|
342
|
+
date: z$1.iso.date(),
|
|
343
|
+
pass: z$1.boolean(),
|
|
344
|
+
checks: z$1.array(z$1.enum(SMOKE_CHECKS)).max(16),
|
|
345
|
+
kv: z$1.enum(KV_CACHE_TYPES).optional()
|
|
346
|
+
});
|
|
347
|
+
const BuildSchema = z$1.object({
|
|
348
|
+
id: SlugSchema,
|
|
349
|
+
hf: z$1.object({
|
|
350
|
+
repo: HfRepoSchema,
|
|
351
|
+
revision: CommitShaSchema
|
|
352
|
+
}).optional(),
|
|
353
|
+
quant: QuantSchema,
|
|
354
|
+
weights: z$1.array(GgufFileSchema).max(64).default([]),
|
|
355
|
+
mmproj: GgufFileSchema.optional(),
|
|
356
|
+
draft: DraftSchema.optional(),
|
|
357
|
+
tensorStats: z$1.object({
|
|
358
|
+
expertBytesPerLayer: ByteCountSchema$1,
|
|
359
|
+
nonExpertBytes: ByteCountSchema$1
|
|
360
|
+
}).optional(),
|
|
361
|
+
ollama: OllamaSourceSchema.optional(),
|
|
362
|
+
runtimeMin: z$1.object({
|
|
363
|
+
ollama: SemverSchema.optional(),
|
|
364
|
+
llamaCppBuild: z$1.number().int().positive().max(1e6).optional()
|
|
365
|
+
}).optional(),
|
|
366
|
+
routing: RoutingSchema,
|
|
367
|
+
preset: LlamaServerPresetSchema.prefault({}),
|
|
368
|
+
smoke: z$1.array(SmokeSchema).max(32),
|
|
369
|
+
evidence: z$1.array(EvidenceSchema).max(32)
|
|
370
|
+
});
|
|
371
|
+
const LicenseRefSchema = z$1.object({
|
|
372
|
+
id: z$1.string().regex(/^[A-Za-z0-9.+-]{2,64}$/),
|
|
373
|
+
spdx: z$1.boolean(),
|
|
374
|
+
class: z$1.enum(LICENSE_CLASSES),
|
|
375
|
+
source: HttpsUrlSchema
|
|
376
|
+
});
|
|
377
|
+
const LicenseSchema = LicenseRefSchema.extend({
|
|
378
|
+
base: LicenseRefSchema,
|
|
379
|
+
cardTag: z$1.string().max(64).nullable(),
|
|
380
|
+
gated: z$1.boolean(),
|
|
381
|
+
requiresAck: z$1.boolean().default(false),
|
|
382
|
+
summary: z$1.string().min(1).max(160).optional(),
|
|
383
|
+
legal: z$1.enum([
|
|
384
|
+
"cleared",
|
|
385
|
+
"pending",
|
|
386
|
+
"blocked"
|
|
387
|
+
]),
|
|
388
|
+
legalNote: z$1.string().max(280).optional()
|
|
389
|
+
});
|
|
390
|
+
const LineageSchema = z$1.object({
|
|
391
|
+
base: HfRepoSchema,
|
|
392
|
+
variantType: z$1.enum(VARIANT_TYPES),
|
|
393
|
+
steps: z$1.array(z$1.enum([
|
|
394
|
+
"cpt",
|
|
395
|
+
"sft",
|
|
396
|
+
"rl",
|
|
397
|
+
"opd",
|
|
398
|
+
"distill",
|
|
399
|
+
"merge",
|
|
400
|
+
"abliterate",
|
|
401
|
+
"transplant",
|
|
402
|
+
"prune",
|
|
403
|
+
"requant"
|
|
404
|
+
])).max(16).default([]),
|
|
405
|
+
parents: z$1.array(HfRepoSchema).max(8).default([]),
|
|
406
|
+
producer: z$1.object({
|
|
407
|
+
name: z$1.string().regex(/^[A-Za-z0-9_.-]{1,64}$/),
|
|
408
|
+
tier: z$1.enum(PRODUCER_TIERS)
|
|
409
|
+
})
|
|
410
|
+
});
|
|
411
|
+
const SamplingSchema = z$1.object({
|
|
412
|
+
temperature: z$1.number().min(0).max(2),
|
|
413
|
+
top_p: z$1.number().gt(0).max(1),
|
|
414
|
+
top_k: z$1.number().int().positive().max(1e3).optional(),
|
|
415
|
+
min_p: z$1.number().min(0).max(1).default(0),
|
|
416
|
+
presence_penalty: z$1.number().min(0).max(2).default(0),
|
|
417
|
+
repeat_penalty: z$1.literal(1).default(1)
|
|
418
|
+
});
|
|
419
|
+
const ReasoningSchema = z$1.discriminatedUnion("via", [
|
|
420
|
+
z$1.object({
|
|
421
|
+
via: z$1.literal("kwarg"),
|
|
422
|
+
key: z$1.enum(["reasoning_effort", "enable_thinking"]),
|
|
423
|
+
levels: z$1.partialRecord(z$1.enum(REASONING_EFFORTS), z$1.union([z$1.string().max(16), z$1.boolean()]))
|
|
424
|
+
}),
|
|
425
|
+
z$1.object({
|
|
426
|
+
via: z$1.literal("system-prompt"),
|
|
427
|
+
levels: z$1.partialRecord(z$1.enum(REASONING_EFFORTS), z$1.string().max(64))
|
|
428
|
+
}),
|
|
429
|
+
z$1.object({ via: z$1.literal("none") })
|
|
430
|
+
]);
|
|
431
|
+
const FamilySchema = z$1.object({
|
|
432
|
+
ggufArch: z$1.string().max(64).regex(/^[a-z0-9_-]+$/),
|
|
433
|
+
sampling: z$1.object({
|
|
434
|
+
thinking: SamplingSchema.optional(),
|
|
435
|
+
nonThinking: SamplingSchema.optional()
|
|
436
|
+
}),
|
|
437
|
+
reasoning: ReasoningSchema,
|
|
438
|
+
ollama: z$1.object({
|
|
439
|
+
renderer: OllamaNameSchema.optional(),
|
|
440
|
+
parser: OllamaNameSchema.optional()
|
|
441
|
+
}),
|
|
442
|
+
templateRef: SlugSchema.optional(),
|
|
443
|
+
source: HttpsUrlSchema
|
|
444
|
+
});
|
|
445
|
+
const TOOL_USE_RATINGS = [
|
|
446
|
+
"unrated",
|
|
447
|
+
"weak",
|
|
448
|
+
"ok",
|
|
449
|
+
"strong"
|
|
450
|
+
];
|
|
451
|
+
const ToolUseSchema = z$1.object({
|
|
452
|
+
rating: z$1.enum(TOOL_USE_RATINGS),
|
|
453
|
+
note: z$1.string().min(1).max(200).optional()
|
|
454
|
+
});
|
|
455
|
+
const EntryHeaderSchema = z$1.object({
|
|
456
|
+
id: SlugSchema,
|
|
457
|
+
name: z$1.string().min(1).max(80),
|
|
458
|
+
family: SlugSchema,
|
|
459
|
+
roles: z$1.array(HubRoleSchema).min(1).max(8),
|
|
460
|
+
why: z$1.string().min(1).max(140),
|
|
461
|
+
lineage: LineageSchema,
|
|
462
|
+
license: LicenseSchema,
|
|
463
|
+
params: z$1.object({
|
|
464
|
+
totalB: z$1.number().positive().max(1e5),
|
|
465
|
+
activeB: z$1.number().positive().max(1e5).nullable()
|
|
466
|
+
}),
|
|
467
|
+
arch: ModelArchSchema,
|
|
468
|
+
capabilities: z$1.object({
|
|
469
|
+
tools: z$1.boolean(),
|
|
470
|
+
vision: z$1.boolean(),
|
|
471
|
+
thinking: z$1.boolean(),
|
|
472
|
+
embeddings: z$1.boolean()
|
|
473
|
+
}),
|
|
474
|
+
toolUse: ToolUseSchema.default({ rating: "unrated" }),
|
|
475
|
+
flags: z$1.object({
|
|
476
|
+
abliterated: z$1.boolean(),
|
|
477
|
+
experimental: z$1.boolean(),
|
|
478
|
+
licenseMismatch: z$1.boolean(),
|
|
479
|
+
customQuant: z$1.boolean()
|
|
480
|
+
}),
|
|
481
|
+
reviewedAt: z$1.iso.date(),
|
|
482
|
+
notesUrl: HttpsUrlSchema.nullable().optional(),
|
|
483
|
+
minDesktopVersion: SemverSchema.optional(),
|
|
484
|
+
minCliVersion: SemverSchema.optional()
|
|
485
|
+
});
|
|
486
|
+
const EntryObjectSchema = EntryHeaderSchema.extend({ builds: z$1.array(BuildSchema).min(1).max(MAX_BUILDS) });
|
|
487
|
+
const licenseRank = (c) => LICENSE_CLASSES.indexOf(c);
|
|
488
|
+
function headerIssues(entry) {
|
|
489
|
+
const issues = [];
|
|
490
|
+
const issue = (path, message) => issues.push({
|
|
491
|
+
path,
|
|
492
|
+
message
|
|
493
|
+
});
|
|
494
|
+
const { roles, capabilities, arch, flags, license, lineage } = entry;
|
|
495
|
+
if (new Set(roles).size !== roles.length) issue(["roles"], "roles must be unique");
|
|
496
|
+
if (roles.includes("vision") !== capabilities.vision) issue(["roles"], "vision role and capabilities.vision must agree");
|
|
497
|
+
if (roles.includes("embeddings") !== capabilities.embeddings) issue(["roles"], "embeddings role and capabilities.embeddings must agree");
|
|
498
|
+
if (!capabilities.tools && entry.toolUse.rating !== "unrated") issue(["toolUse", "rating"], "a tool-use rating needs capabilities.tools");
|
|
499
|
+
if (entry.params.activeB !== null && entry.params.activeB > entry.params.totalB) issue(["params", "activeB"], "activeB cannot exceed totalB");
|
|
500
|
+
if (roles.includes("chat") && arch.contextMax < 16384) issue(["arch", "contextMax"], "a chat model needs a context of at least 16384 tokens");
|
|
501
|
+
if (arch.full.layers + (arch.swa?.layers ?? 0) + (arch.mla?.layers ?? 0) + (arch.recurrent?.layers ?? 0) > arch.blockCount) issue(["arch"], "layer groups exceed blockCount");
|
|
502
|
+
if (arch.moe && arch.moe.used > arch.moe.experts) issue([
|
|
503
|
+
"arch",
|
|
504
|
+
"moe",
|
|
505
|
+
"used"
|
|
506
|
+
], "used exceeds experts");
|
|
507
|
+
if (arch.moe && arch.moe.moeLayers > arch.blockCount) issue([
|
|
508
|
+
"arch",
|
|
509
|
+
"moe",
|
|
510
|
+
"moeLayers"
|
|
511
|
+
], "exceeds blockCount");
|
|
512
|
+
if (lineage.variantType === "abliterated" || lineage.steps.includes("abliterate")) {
|
|
513
|
+
if (!flags.abliterated) issue(["flags", "abliterated"], "abliterated lineage requires flags.abliterated");
|
|
514
|
+
}
|
|
515
|
+
if (licenseRank(license.class) < licenseRank(license.base.class)) issue(["license", "class"], "license class cannot be less restrictive than the base license");
|
|
516
|
+
if (license.cardTag !== null && license.cardTag !== license.id && !flags.licenseMismatch) issue(["flags", "licenseMismatch"], "card tag differs from the LICENSE file");
|
|
517
|
+
if (license.class !== "permissive" && license.legal === "cleared" && !license.legalNote) issue(["license", "legalNote"], "a cleared non-permissive license needs a legalNote");
|
|
518
|
+
if (license.class !== "permissive" && !license.requiresAck) issue(["license", "requiresAck"], "a non-permissive license needs an acknowledgement");
|
|
519
|
+
if (license.requiresAck && !license.summary) issue(["license", "summary"], "an acknowledged license needs a plain summary");
|
|
520
|
+
return issues;
|
|
521
|
+
}
|
|
522
|
+
const toolCallOverflow = (t) => t.exact + t.nearMiss + t.malformed > t.of;
|
|
523
|
+
function buildIssues(entry, build, b) {
|
|
524
|
+
const issues = [];
|
|
525
|
+
const at = (...rest) => [
|
|
526
|
+
"builds",
|
|
527
|
+
b,
|
|
528
|
+
...rest
|
|
529
|
+
];
|
|
530
|
+
const issue = (path, message) => issues.push({
|
|
531
|
+
path,
|
|
532
|
+
message
|
|
533
|
+
});
|
|
534
|
+
const { arch, capabilities, flags } = entry;
|
|
535
|
+
if (build.quant.family === "custom" && !flags.customQuant) issue(["flags", "customQuant"], "custom quant requires flags.customQuant");
|
|
536
|
+
const library = build.ollama?.kind === "library";
|
|
537
|
+
if (!library && (!build.hf || build.weights.length === 0)) issue(at("weights"), "a build needs Hugging Face weights unless it is an Ollama library build");
|
|
538
|
+
const servedProjector = build.ollama?.kind === "hf-pull" && !!build.ollama.layers?.projector;
|
|
539
|
+
if (capabilities.vision && !build.mmproj && !library && !servedProjector) issue(at("mmproj"), "a vision build needs an mmproj, a pinned projector layer or an Ollama library source");
|
|
540
|
+
if (build.weights.length > 1) {
|
|
541
|
+
if (!build.routing.reasons.includes("sharded")) issue(at("routing", "reasons"), "sharded weights need sharded");
|
|
542
|
+
if (build.ollama && build.ollama.kind !== "create") issue(at("ollama", "kind"), "Ollama cannot pull shards; use create");
|
|
543
|
+
}
|
|
544
|
+
if (build.ollama?.kind === "hf-pull" && (build.weights.length > 1 || build.mmproj)) issue(at("ollama", "kind"), "hf-pull needs a single file and no separate mmproj; use create");
|
|
545
|
+
if ((build.routing.preferred === "ollama" || build.routing.ollamaFallback) && !build.ollama) issue(at("ollama"), "routing to Ollama needs an Ollama source");
|
|
546
|
+
if (build.tensorStats && !arch.moe) issue(at("tensorStats"), "tensorStats needs arch.moe");
|
|
547
|
+
if (build.tensorStats && arch.moe) {
|
|
548
|
+
const { expertBytesPerLayer, nonExpertBytes } = build.tensorStats;
|
|
549
|
+
const weightBytes = build.weights.reduce((sum, w) => sum + w.sizeBytes, 0);
|
|
550
|
+
if (expertBytesPerLayer * arch.moe.moeLayers + nonExpertBytes > weightBytes) issue(at("tensorStats"), "tensorStats exceed the weight files");
|
|
551
|
+
}
|
|
552
|
+
const { nCpuMoe } = build.preset;
|
|
553
|
+
if (typeof nCpuMoe === "number" && nCpuMoe > (arch.moe?.moeLayers ?? 0)) issue(at("preset", "nCpuMoe"), "nCpuMoe exceeds the MoE layer count");
|
|
554
|
+
if (typeof nCpuMoe === "number" && nCpuMoe > 0 && !build.tensorStats) issue(at("preset", "nCpuMoe"), "a fixed nCpuMoe needs tensorStats");
|
|
555
|
+
const spec = build.preset.speculative.type;
|
|
556
|
+
const draftKind = build.draft?.kind;
|
|
557
|
+
if (!(spec === "none" || spec === "draft-mtp" && (draftKind === "mtp-embedded" || draftKind === "mtp-sidecar") || spec === draftKind)) issue(at("preset", "speculative", "type"), `speculative ${spec} needs a matching draft`);
|
|
558
|
+
const kv = build.preset.kv;
|
|
559
|
+
if (kv !== "auto" && kv.v !== "f16" && build.preset.flashAttn !== "on") issue(at("preset", "kv"), "a quantized V cache requires flashAttn 'on'");
|
|
560
|
+
if (kv !== "auto" && arch.kvProbe && (kv.k !== "f16" || kv.v !== "f16")) issue(at("preset", "kv"), "a kvProbe arch is sized at f16 KV only");
|
|
561
|
+
const ownDigests = new Set(build.weights.map((w) => w.sha256));
|
|
562
|
+
if (build.ollama?.kind === "library") ownDigests.add(build.ollama.digest);
|
|
563
|
+
build.evidence.forEach((ev, e) => {
|
|
564
|
+
const evAt = (...rest) => at("evidence", e, ...rest);
|
|
565
|
+
if (ev.measured.target === "exact" && !(ev.measured.sha256 && ownDigests.has(ev.measured.sha256))) issue(evAt("measured", "sha256"), "exact evidence must name a weight or Ollama digest of this build");
|
|
566
|
+
if (ev.kind === "own-eval" !== (ev.ownEval !== void 0)) issue(evAt("ownEval"), "ownEval is required for, and only for, kind own-eval");
|
|
567
|
+
const own = ev.ownEval;
|
|
568
|
+
if (!own) return;
|
|
569
|
+
if (!ev.independent || !ev.reproducible || ev.measured.target !== "exact") issue(evAt("measured"), "an own eval is independent, reproducible and on the exact build");
|
|
570
|
+
if (toolCallOverflow(own.toolCall)) issue(evAt("ownEval", "toolCall"), "tool-call counts exceed of");
|
|
571
|
+
if (own.parentToolCall && toolCallOverflow(own.parentToolCall)) issue(evAt("ownEval", "parentToolCall"), "tool-call counts exceed of");
|
|
572
|
+
if (own.coding.passed > own.coding.of) issue(evAt("ownEval", "coding"), "passed exceeds of");
|
|
573
|
+
if (own.recall.passed > own.recall.of) issue(evAt("ownEval", "recall"), "passed exceeds of");
|
|
574
|
+
if (own.refusals && own.refusals.n > own.refusals.of) issue(evAt("ownEval", "refusals"), "n exceeds of");
|
|
575
|
+
});
|
|
576
|
+
return issues;
|
|
577
|
+
}
|
|
578
|
+
function refineEntry(entry, ctx) {
|
|
579
|
+
const issues = headerIssues(entry);
|
|
580
|
+
const buildIds = /* @__PURE__ */ new Set();
|
|
581
|
+
entry.builds.forEach((build, b) => {
|
|
582
|
+
if (buildIds.has(build.id)) issues.push({
|
|
583
|
+
path: [
|
|
584
|
+
"builds",
|
|
585
|
+
b,
|
|
586
|
+
"id"
|
|
587
|
+
],
|
|
588
|
+
message: `duplicate build id ${build.id}`
|
|
589
|
+
});
|
|
590
|
+
buildIds.add(build.id);
|
|
591
|
+
issues.push(...buildIssues(entry, build, b));
|
|
592
|
+
});
|
|
593
|
+
for (const { path, message } of issues) ctx.addIssue({
|
|
594
|
+
code: "custom",
|
|
595
|
+
path,
|
|
596
|
+
message
|
|
597
|
+
});
|
|
598
|
+
}
|
|
599
|
+
const HubEntrySchema = EntryObjectSchema.superRefine(refineEntry);
|
|
600
|
+
const HubPolicySchema = z$1.object({
|
|
601
|
+
abliterated: z$1.enum([
|
|
602
|
+
"hidden",
|
|
603
|
+
"explore-only",
|
|
604
|
+
"curated-opt-in"
|
|
605
|
+
]).default("curated-opt-in"),
|
|
606
|
+
restrictedLicense: z$1.enum([
|
|
607
|
+
"hidden",
|
|
608
|
+
"explore-only",
|
|
609
|
+
"curated-labelled"
|
|
610
|
+
]).default("curated-labelled"),
|
|
611
|
+
bestPickPermissiveOnly: z$1.boolean().default(false),
|
|
612
|
+
minGradeForBestPick: z$1.enum(EVIDENCE_GRADES).default("B")
|
|
613
|
+
});
|
|
614
|
+
const maxKeys = (n) => (record) => Object.keys(record).length <= n;
|
|
615
|
+
const SlugListSchema = z$1.array(SlugSchema).max(50);
|
|
616
|
+
const ChangelogItemSchema = z$1.object({
|
|
617
|
+
sequence: z$1.number().int().min(1).max(MAX_SEQUENCE),
|
|
618
|
+
date: z$1.iso.date(),
|
|
619
|
+
added: SlugListSchema,
|
|
620
|
+
removed: z$1.array(z$1.object({
|
|
621
|
+
id: SlugSchema,
|
|
622
|
+
name: z$1.string().min(1).max(80)
|
|
623
|
+
})).max(50),
|
|
624
|
+
changed: SlugListSchema,
|
|
625
|
+
notes: z$1.string().max(280)
|
|
626
|
+
});
|
|
627
|
+
const CURATED_SLOTS = [
|
|
628
|
+
"best",
|
|
629
|
+
"fast",
|
|
630
|
+
"long-context",
|
|
631
|
+
"light"
|
|
632
|
+
];
|
|
633
|
+
const TIER_KINDS = [
|
|
634
|
+
"discrete",
|
|
635
|
+
"unified",
|
|
636
|
+
"cpu"
|
|
637
|
+
];
|
|
638
|
+
const TIER_SLOTS = {
|
|
639
|
+
discrete: [
|
|
640
|
+
"best",
|
|
641
|
+
"fast",
|
|
642
|
+
"long-context"
|
|
643
|
+
],
|
|
644
|
+
unified: [
|
|
645
|
+
"best",
|
|
646
|
+
"fast",
|
|
647
|
+
"long-context"
|
|
648
|
+
],
|
|
649
|
+
cpu: [
|
|
650
|
+
"best",
|
|
651
|
+
"fast",
|
|
652
|
+
"light"
|
|
653
|
+
]
|
|
654
|
+
};
|
|
655
|
+
const TierPickSchema = z$1.object({
|
|
656
|
+
slot: z$1.enum(CURATED_SLOTS),
|
|
657
|
+
entry: SlugSchema,
|
|
658
|
+
build: SlugSchema
|
|
659
|
+
});
|
|
660
|
+
const TierSchema = z$1.object({
|
|
661
|
+
memoryKind: z$1.enum(TIER_KINDS),
|
|
662
|
+
minGiB: z$1.number().int().nonnegative().max(65536),
|
|
663
|
+
picks: z$1.array(TierPickSchema).max(3)
|
|
664
|
+
});
|
|
665
|
+
function pickIssue(pick, tier, entries) {
|
|
666
|
+
if (!TIER_SLOTS[tier.memoryKind].includes(pick.slot)) return `no ${pick.slot} slot in a ${tier.memoryKind} tier`;
|
|
667
|
+
const entry = entries.find((candidate) => candidate.id === pick.entry);
|
|
668
|
+
if (!entry) return `no entry ${pick.entry}`;
|
|
669
|
+
return entry.builds.some((build) => build.id === pick.build) ? null : `no build ${pick.build} in ${pick.entry}`;
|
|
670
|
+
}
|
|
671
|
+
const RevokedKeyIdsSchema = z$1.array(z$1.string().regex(/^[0-9a-f]{16}$/)).max(16).default([]);
|
|
672
|
+
const ManifestObjectSchema = z$1.object({
|
|
673
|
+
schemaVersion: z$1.literal(2),
|
|
674
|
+
sequence: z$1.number().int().min(1).max(MAX_SEQUENCE).optional(),
|
|
675
|
+
updatedAt: z$1.iso.datetime(),
|
|
676
|
+
notesUrl: HttpsUrlSchema.nullable().optional(),
|
|
677
|
+
changelog: z$1.array(ChangelogItemSchema).max(MAX_CHANGELOG).default([]),
|
|
678
|
+
revokedKeyIds: RevokedKeyIdsSchema,
|
|
679
|
+
policy: HubPolicySchema.prefault({}),
|
|
680
|
+
families: z$1.record(SlugSchema, FamilySchema).refine(maxKeys(MAX_FAMILIES), "too many families"),
|
|
681
|
+
rankings: z$1.partialRecord(HubRoleSchema, z$1.array(SlugSchema).max(MAX_ENTRIES)),
|
|
682
|
+
tiers: z$1.array(TierSchema).max(MAX_TIERS).default([]),
|
|
683
|
+
entries: z$1.array(HubEntrySchema).max(MAX_ENTRIES)
|
|
684
|
+
});
|
|
685
|
+
function refineManifest(manifest, ctx) {
|
|
686
|
+
manifest.tiers.forEach((tier, t) => {
|
|
687
|
+
const issue = (path, message) => ctx.addIssue({
|
|
688
|
+
code: "custom",
|
|
689
|
+
path: [
|
|
690
|
+
"tiers",
|
|
691
|
+
t,
|
|
692
|
+
...path
|
|
693
|
+
],
|
|
694
|
+
message
|
|
695
|
+
});
|
|
696
|
+
if (manifest.tiers.slice(0, t).some((o) => o.memoryKind === tier.memoryKind && o.minGiB === tier.minGiB)) issue([], "duplicate tier");
|
|
697
|
+
tier.picks.forEach((pick, p) => {
|
|
698
|
+
const reason = pickIssue(pick, tier, manifest.entries);
|
|
699
|
+
if (reason) issue(["picks", p], reason);
|
|
700
|
+
if (tier.picks.slice(0, p).some((other) => other.slot === pick.slot)) issue([
|
|
701
|
+
"picks",
|
|
702
|
+
p,
|
|
703
|
+
"slot"
|
|
704
|
+
], "slot taken");
|
|
705
|
+
});
|
|
706
|
+
});
|
|
707
|
+
const byId = /* @__PURE__ */ new Map();
|
|
708
|
+
manifest.entries.forEach((entry, i) => {
|
|
709
|
+
if (byId.has(entry.id)) ctx.addIssue({
|
|
710
|
+
code: "custom",
|
|
711
|
+
path: [
|
|
712
|
+
"entries",
|
|
713
|
+
i,
|
|
714
|
+
"id"
|
|
715
|
+
],
|
|
716
|
+
message: `duplicate entry id ${entry.id}`
|
|
717
|
+
});
|
|
718
|
+
byId.set(entry.id, entry);
|
|
719
|
+
if (!Object.hasOwn(manifest.families, entry.family)) ctx.addIssue({
|
|
720
|
+
code: "custom",
|
|
721
|
+
path: [
|
|
722
|
+
"entries",
|
|
723
|
+
i,
|
|
724
|
+
"family"
|
|
725
|
+
],
|
|
726
|
+
message: `unknown family ${entry.family}`
|
|
727
|
+
});
|
|
728
|
+
});
|
|
729
|
+
for (const role of HUB_ROLES) {
|
|
730
|
+
const ids = manifest.rankings[role] ?? [];
|
|
731
|
+
if (new Set(ids).size !== ids.length) ctx.addIssue({
|
|
732
|
+
code: "custom",
|
|
733
|
+
path: ["rankings", role],
|
|
734
|
+
message: "ranking lists an id twice"
|
|
735
|
+
});
|
|
736
|
+
ids.forEach((id, i) => {
|
|
737
|
+
const entry = byId.get(id);
|
|
738
|
+
if (!entry || !entry.roles.includes(role)) ctx.addIssue({
|
|
739
|
+
code: "custom",
|
|
740
|
+
path: [
|
|
741
|
+
"rankings",
|
|
742
|
+
role,
|
|
743
|
+
i
|
|
744
|
+
],
|
|
745
|
+
message: `no ${role} entry ${id}`
|
|
746
|
+
});
|
|
747
|
+
});
|
|
748
|
+
}
|
|
749
|
+
}
|
|
750
|
+
/** Curated local-model manifest for the Model Hub, validated whole; the catalog's own CI uses this. */
|
|
751
|
+
const HubManifestSchema = ManifestObjectSchema.superRefine(refineManifest);
|
|
752
|
+
function refinePublished(manifest, ctx) {
|
|
753
|
+
const issue = (path, message) => ctx.addIssue({
|
|
754
|
+
code: "custom",
|
|
755
|
+
path,
|
|
756
|
+
message
|
|
757
|
+
});
|
|
758
|
+
if (manifest.sequence === void 0) return issue(["sequence"], "a published catalog needs a sequence");
|
|
759
|
+
const [newest, ...older] = manifest.changelog;
|
|
760
|
+
if (newest?.sequence !== manifest.sequence) return issue([
|
|
761
|
+
"changelog",
|
|
762
|
+
0,
|
|
763
|
+
"sequence"
|
|
764
|
+
], "the newest changelog item must carry the catalog sequence");
|
|
765
|
+
older.forEach((item, i) => {
|
|
766
|
+
if (item.sequence >= manifest.changelog[i].sequence) issue([
|
|
767
|
+
"changelog",
|
|
768
|
+
i + 1,
|
|
769
|
+
"sequence"
|
|
770
|
+
], "changelog sequences must strictly decrease");
|
|
771
|
+
});
|
|
772
|
+
const ids = new Set(manifest.entries.map((entry) => entry.id));
|
|
773
|
+
for (const id of [...newest.added, ...newest.changed]) if (!ids.has(id)) issue(["changelog", 0], `no entry ${id}`);
|
|
774
|
+
for (const removed of newest.removed) if (ids.has(removed.id)) issue([
|
|
775
|
+
"changelog",
|
|
776
|
+
0,
|
|
777
|
+
"removed"
|
|
778
|
+
], `entry ${removed.id} is still listed`);
|
|
779
|
+
}
|
|
780
|
+
HubManifestSchema.superRefine(refinePublished);
|
|
781
|
+
const HUB_TIER_KINDS = TIER_KINDS;
|
|
782
|
+
const POLICY_FALLBACK = {
|
|
783
|
+
abliterated: "hidden",
|
|
784
|
+
restrictedLicense: "hidden",
|
|
785
|
+
bestPickPermissiveOnly: true,
|
|
786
|
+
minGradeForBestPick: "A"
|
|
787
|
+
};
|
|
788
|
+
const ManifestEnvelopeSchema = z$1.object({
|
|
789
|
+
schemaVersion: z$1.literal(2),
|
|
790
|
+
sequence: z$1.number().int().min(1).max(MAX_SEQUENCE).optional(),
|
|
791
|
+
updatedAt: z$1.iso.datetime(),
|
|
792
|
+
notesUrl: HttpsUrlSchema.nullable().optional(),
|
|
793
|
+
changelog: z$1.unknown().optional(),
|
|
794
|
+
revokedKeyIds: RevokedKeyIdsSchema,
|
|
795
|
+
tiers: z$1.unknown().optional(),
|
|
796
|
+
policy: z$1.record(z$1.string(), z$1.unknown()).nullable().optional(),
|
|
797
|
+
families: z$1.record(z$1.string(), z$1.unknown()).refine(maxKeys(MAX_FAMILIES), "too many families"),
|
|
798
|
+
rankings: z$1.record(z$1.string(), z$1.unknown()).refine(maxKeys(16), "too many rankings"),
|
|
799
|
+
entries: z$1.array(z$1.unknown()).max(MAX_ENTRIES)
|
|
800
|
+
});
|
|
801
|
+
const isRecord$1 = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
802
|
+
function knownOnly(value, known) {
|
|
803
|
+
return Array.isArray(value) ? value.filter((v) => typeof v === "string" && known.includes(v)) : value;
|
|
804
|
+
}
|
|
805
|
+
/** The rating is a label, so a problem with it (unknown rating, rating without tools, bad note) costs only the label. */
|
|
806
|
+
function knownToolUse(value, capabilities) {
|
|
807
|
+
if (value === void 0) return value;
|
|
808
|
+
if (!isRecord$1(value)) return { rating: "unrated" };
|
|
809
|
+
const known = TOOL_USE_RATINGS.includes(value.rating);
|
|
810
|
+
const tools = isRecord$1(capabilities) && capabilities.tools === true;
|
|
811
|
+
if (!known || !tools && value.rating !== "unrated") return { rating: "unrated" };
|
|
812
|
+
const note = ToolUseSchema.shape.note.safeParse(value.note);
|
|
813
|
+
return {
|
|
814
|
+
rating: value.rating,
|
|
815
|
+
...note.success && note.data !== void 0 ? { note: note.data } : {}
|
|
816
|
+
};
|
|
817
|
+
}
|
|
818
|
+
const describeIssue = (issue) => issue.path.length ? `${issue.path.map(String).join(".")}: ${issue.message}` : issue.message;
|
|
819
|
+
const firstIssue = (error) => describeIssue(error.issues[0]);
|
|
820
|
+
var TolerantReader = class {
|
|
821
|
+
dropped = [];
|
|
822
|
+
drop(path, reason) {
|
|
823
|
+
this.dropped.push({
|
|
824
|
+
path,
|
|
825
|
+
reason
|
|
826
|
+
});
|
|
827
|
+
}
|
|
828
|
+
policy(raw = {}) {
|
|
829
|
+
const field = (key) => {
|
|
830
|
+
const result = HubPolicySchema.shape[key].safeParse(raw[key]);
|
|
831
|
+
if (result.success) return result.data;
|
|
832
|
+
this.drop(`policy.${key}`, firstIssue(result.error));
|
|
833
|
+
return POLICY_FALLBACK[key];
|
|
834
|
+
};
|
|
835
|
+
return {
|
|
836
|
+
abliterated: field("abliterated"),
|
|
837
|
+
restrictedLicense: field("restrictedLicense"),
|
|
838
|
+
bestPickPermissiveOnly: field("bestPickPermissiveOnly"),
|
|
839
|
+
minGradeForBestPick: field("minGradeForBestPick")
|
|
840
|
+
};
|
|
841
|
+
}
|
|
842
|
+
families(raw) {
|
|
843
|
+
const families = {};
|
|
844
|
+
for (const [key, value] of Object.entries(raw)) {
|
|
845
|
+
const parsed = FamilySchema.safeParse(value);
|
|
846
|
+
if (!SlugSchema.safeParse(key).success) this.drop(`families.${key}`, "invalid family key");
|
|
847
|
+
else if (!parsed.success) this.drop(`families.${key}`, firstIssue(parsed.error));
|
|
848
|
+
else families[key] = parsed.data;
|
|
849
|
+
}
|
|
850
|
+
return families;
|
|
851
|
+
}
|
|
852
|
+
/** Keeps the valid items of a bounded list, dropping the rest; an oversized list is left for the schema. */
|
|
853
|
+
items(value, path, schema, prepare = (v) => v) {
|
|
854
|
+
if (!Array.isArray(value) || value.length > 64) return value;
|
|
855
|
+
return value.map(prepare).filter((item, i) => {
|
|
856
|
+
const result = schema.safeParse(item);
|
|
857
|
+
if (!result.success) this.drop(`${path}.${i}`, firstIssue(result.error));
|
|
858
|
+
return result.success;
|
|
859
|
+
});
|
|
860
|
+
}
|
|
861
|
+
build(raw, path) {
|
|
862
|
+
if (!isRecord$1(raw)) {
|
|
863
|
+
this.drop(path, "not an object");
|
|
864
|
+
return null;
|
|
865
|
+
}
|
|
866
|
+
const routing = isRecord$1(raw.routing) ? {
|
|
867
|
+
...raw.routing,
|
|
868
|
+
reasons: knownOnly(raw.routing.reasons, ROUTE_REASONS)
|
|
869
|
+
} : raw.routing;
|
|
870
|
+
const smoke = this.items(raw.smoke, `${path}.smoke`, SmokeSchema, (s) => isRecord$1(s) ? {
|
|
871
|
+
...s,
|
|
872
|
+
checks: knownOnly(s.checks, SMOKE_CHECKS)
|
|
873
|
+
} : s);
|
|
874
|
+
const evidence = this.items(raw.evidence, `${path}.evidence`, EvidenceSchema);
|
|
875
|
+
const parsed = BuildSchema.safeParse({
|
|
876
|
+
...raw,
|
|
877
|
+
routing,
|
|
878
|
+
smoke,
|
|
879
|
+
evidence
|
|
880
|
+
});
|
|
881
|
+
if (!parsed.success) {
|
|
882
|
+
this.drop(path, firstIssue(parsed.error));
|
|
883
|
+
return null;
|
|
884
|
+
}
|
|
885
|
+
return parsed.data;
|
|
886
|
+
}
|
|
887
|
+
entry(raw, path, families) {
|
|
888
|
+
if (!isRecord$1(raw)) {
|
|
889
|
+
this.drop(path, "not an object");
|
|
890
|
+
return null;
|
|
891
|
+
}
|
|
892
|
+
const header = EntryHeaderSchema.safeParse({
|
|
893
|
+
...raw,
|
|
894
|
+
roles: knownOnly(raw.roles, HUB_ROLES),
|
|
895
|
+
toolUse: knownToolUse(raw.toolUse, raw.capabilities)
|
|
896
|
+
});
|
|
897
|
+
if (!header.success) {
|
|
898
|
+
this.drop(path, firstIssue(header.error));
|
|
899
|
+
return null;
|
|
900
|
+
}
|
|
901
|
+
const problems = headerIssues(header.data);
|
|
902
|
+
if (!Object.hasOwn(families, header.data.family)) problems.push({
|
|
903
|
+
path: ["family"],
|
|
904
|
+
message: "unknown family"
|
|
905
|
+
});
|
|
906
|
+
if (problems.length) {
|
|
907
|
+
this.drop(path, describeIssue(problems[0]));
|
|
908
|
+
return null;
|
|
909
|
+
}
|
|
910
|
+
const rawBuilds = Array.isArray(raw.builds) && raw.builds.length <= MAX_BUILDS ? raw.builds : [];
|
|
911
|
+
const builds = [];
|
|
912
|
+
rawBuilds.forEach((rawBuild, b) => {
|
|
913
|
+
const buildPath = `${path}.builds.${b}`;
|
|
914
|
+
const build = this.build(rawBuild, buildPath);
|
|
915
|
+
if (!build) return;
|
|
916
|
+
const issues = buildIssues(header.data, build, b);
|
|
917
|
+
if (builds.some((other) => other.id === build.id)) issues.push({
|
|
918
|
+
path: ["id"],
|
|
919
|
+
message: "duplicate build id"
|
|
920
|
+
});
|
|
921
|
+
if (issues.length) this.drop(buildPath, describeIssue(issues[0]));
|
|
922
|
+
else builds.push(build);
|
|
923
|
+
});
|
|
924
|
+
if (builds.length === 0) {
|
|
925
|
+
this.drop(path, "no usable builds");
|
|
926
|
+
return null;
|
|
927
|
+
}
|
|
928
|
+
return {
|
|
929
|
+
...header.data,
|
|
930
|
+
builds
|
|
931
|
+
};
|
|
932
|
+
}
|
|
933
|
+
changelog(raw) {
|
|
934
|
+
if (raw === void 0) return [];
|
|
935
|
+
if (!Array.isArray(raw) || raw.length > MAX_CHANGELOG) {
|
|
936
|
+
this.drop("changelog", "not a list of at most 200 items");
|
|
937
|
+
return [];
|
|
938
|
+
}
|
|
939
|
+
return raw.flatMap((item, i) => {
|
|
940
|
+
const parsed = ChangelogItemSchema.safeParse(item);
|
|
941
|
+
if (parsed.success) return [parsed.data];
|
|
942
|
+
this.drop(`changelog.${i}`, firstIssue(parsed.error));
|
|
943
|
+
return [];
|
|
944
|
+
});
|
|
945
|
+
}
|
|
946
|
+
/** A pick whose entry or build was dropped leaves its slot empty; no other pick moves into it. */
|
|
947
|
+
tiers(raw, entries) {
|
|
948
|
+
if (raw === void 0) return [];
|
|
949
|
+
if (!Array.isArray(raw) || raw.length > MAX_TIERS) {
|
|
950
|
+
this.drop("tiers", "not a list of at most 32 tiers");
|
|
951
|
+
return [];
|
|
952
|
+
}
|
|
953
|
+
const tiers = [];
|
|
954
|
+
raw.forEach((rawTier, t) => {
|
|
955
|
+
const path = `tiers.${t}`;
|
|
956
|
+
const picks = isRecord$1(rawTier) ? this.items(rawTier.picks, `${path}.picks`, TierPickSchema) : void 0;
|
|
957
|
+
const parsed = TierSchema.safeParse(isRecord$1(rawTier) ? {
|
|
958
|
+
...rawTier,
|
|
959
|
+
picks
|
|
960
|
+
} : rawTier);
|
|
961
|
+
if (!parsed.success) return this.drop(path, firstIssue(parsed.error));
|
|
962
|
+
const tier = parsed.data;
|
|
963
|
+
if (tiers.some((other) => other.memoryKind === tier.memoryKind && other.minGiB === tier.minGiB)) return this.drop(path, "duplicate tier");
|
|
964
|
+
const kept = tier.picks.filter((pick, p) => {
|
|
965
|
+
const reason = pickIssue(pick, tier, entries) ?? (tier.picks.slice(0, p).some((o) => o.slot === pick.slot) && "slot taken");
|
|
966
|
+
if (reason) this.drop(`${path}.picks.${p}`, reason);
|
|
967
|
+
return !reason;
|
|
968
|
+
});
|
|
969
|
+
tiers.push({
|
|
970
|
+
...tier,
|
|
971
|
+
picks: kept
|
|
972
|
+
});
|
|
973
|
+
});
|
|
974
|
+
return tiers;
|
|
975
|
+
}
|
|
976
|
+
rankings(raw, entries) {
|
|
977
|
+
const rankings = {};
|
|
978
|
+
for (const [key, value] of Object.entries(raw)) {
|
|
979
|
+
const role = HubRoleSchema.safeParse(key);
|
|
980
|
+
if (!role.success || !Array.isArray(value)) {
|
|
981
|
+
this.drop(`rankings.${key}`, role.success ? "not a list" : "unknown role");
|
|
982
|
+
continue;
|
|
983
|
+
}
|
|
984
|
+
const ids = [];
|
|
985
|
+
value.slice(0, MAX_ENTRIES).forEach((id, i) => {
|
|
986
|
+
const listed = entries.some((e) => e.id === id && e.roles.includes(role.data));
|
|
987
|
+
if (typeof id === "string" && listed && !ids.includes(id)) ids.push(id);
|
|
988
|
+
else if (typeof id === "string") this.drop(`rankings.${key}.${i}`, `no ${key} entry ${id.slice(0, 64)}`);
|
|
989
|
+
else this.drop(`rankings.${key}.${i}`, `ranking id is not a string (${id === null ? "null" : typeof id})`);
|
|
990
|
+
});
|
|
991
|
+
rankings[role.data] = ids;
|
|
992
|
+
}
|
|
993
|
+
return rankings;
|
|
994
|
+
}
|
|
995
|
+
};
|
|
996
|
+
function deepFreeze(value) {
|
|
997
|
+
if (value !== null && typeof value === "object" && !Object.isFrozen(value)) {
|
|
998
|
+
Object.freeze(value);
|
|
999
|
+
for (const child of Object.values(value)) deepFreeze(child);
|
|
1000
|
+
}
|
|
1001
|
+
return value;
|
|
1002
|
+
}
|
|
1003
|
+
/**
|
|
1004
|
+
* Reads a fetched manifest the way a shipped client must: the envelope has to be valid, but an entry, build,
|
|
1005
|
+
* family, ranking id, smoke record or evidence item this client cannot read is dropped and reported, and unknown
|
|
1006
|
+
* roles, route reasons and smoke checks are ignored. Returns the manifest deep-frozen.
|
|
1007
|
+
*/
|
|
1008
|
+
function parseHubManifest(input) {
|
|
1009
|
+
const envelope = ManifestEnvelopeSchema.parse(input);
|
|
1010
|
+
const reader = new TolerantReader();
|
|
1011
|
+
const policy = reader.policy(envelope.policy ?? void 0);
|
|
1012
|
+
const families = reader.families(envelope.families);
|
|
1013
|
+
const entries = [];
|
|
1014
|
+
envelope.entries.forEach((raw, i) => {
|
|
1015
|
+
const entry = reader.entry(raw, `entries.${i}`, families);
|
|
1016
|
+
if (!entry) return;
|
|
1017
|
+
if (entries.some((e) => e.id === entry.id)) reader.drop(`entries.${i}`, `duplicate entry id ${entry.id}`);
|
|
1018
|
+
else entries.push(entry);
|
|
1019
|
+
});
|
|
1020
|
+
return {
|
|
1021
|
+
manifest: deepFreeze({
|
|
1022
|
+
schemaVersion: 2,
|
|
1023
|
+
...envelope.sequence === void 0 ? {} : { sequence: envelope.sequence },
|
|
1024
|
+
updatedAt: envelope.updatedAt,
|
|
1025
|
+
notesUrl: envelope.notesUrl,
|
|
1026
|
+
changelog: reader.changelog(envelope.changelog),
|
|
1027
|
+
revokedKeyIds: envelope.revokedKeyIds,
|
|
1028
|
+
policy,
|
|
1029
|
+
families,
|
|
1030
|
+
rankings: reader.rankings(envelope.rankings, entries),
|
|
1031
|
+
tiers: reader.tiers(envelope.tiers, entries),
|
|
1032
|
+
entries
|
|
1033
|
+
}),
|
|
1034
|
+
dropped: reader.dropped
|
|
1035
|
+
};
|
|
1036
|
+
}
|
|
1037
|
+
/** Bounds keep a hostile model host from making clients allocate without limit; a host clamps to them before parsing. */
|
|
1038
|
+
const MODEL_HOST_LIMITS = {
|
|
1039
|
+
text: 256,
|
|
1040
|
+
path: 4096,
|
|
1041
|
+
url: 2048,
|
|
1042
|
+
modelName: 1024,
|
|
1043
|
+
bytes: 2 ** 53 - 1,
|
|
1044
|
+
count: 65536,
|
|
1045
|
+
gpus: 64,
|
|
1046
|
+
loaded: 64,
|
|
1047
|
+
unreadable: 64,
|
|
1048
|
+
context: 2 ** 24
|
|
1049
|
+
};
|
|
1050
|
+
const L = MODEL_HOST_LIMITS;
|
|
1051
|
+
const TextSchema = z$1.string().max(L.text);
|
|
1052
|
+
const PathSchema = z$1.string().max(L.path);
|
|
1053
|
+
const ByteCountSchema = z$1.number().int().nonnegative().max(L.bytes);
|
|
1054
|
+
const CountSchema = z$1.number().int().nonnegative().max(L.count);
|
|
1055
|
+
const ConfidenceSchema = z$1.enum(["high", "low"]);
|
|
1056
|
+
/** Ollama settings a model host may change; `OLLAMA_HOST` only back to a loopback address. */
|
|
1057
|
+
const OLLAMA_WRITABLE_SETTING_KEYS = [
|
|
1058
|
+
"OLLAMA_CONTEXT_LENGTH",
|
|
1059
|
+
"OLLAMA_KEEP_ALIVE",
|
|
1060
|
+
"OLLAMA_NUM_PARALLEL",
|
|
1061
|
+
"OLLAMA_MAX_LOADED_MODELS",
|
|
1062
|
+
"OLLAMA_FLASH_ATTENTION",
|
|
1063
|
+
"OLLAMA_KV_CACHE_TYPE",
|
|
1064
|
+
"OLLAMA_NO_CLOUD",
|
|
1065
|
+
"OLLAMA_HOST"
|
|
1066
|
+
];
|
|
1067
|
+
/** Reported but never changed by a model host. */
|
|
1068
|
+
const OLLAMA_READ_ONLY_SETTING_KEYS = ["OLLAMA_MODELS", "OLLAMA_ORIGINS"];
|
|
1069
|
+
const OLLAMA_SETTING_KEYS = [...OLLAMA_WRITABLE_SETTING_KEYS, ...OLLAMA_READ_ONLY_SETTING_KEYS];
|
|
1070
|
+
/** `official` is Ollama under the system `ollama.service`, whoever wrote the unit; `manual` a process with no unit. */
|
|
1071
|
+
const OLLAMA_INSTALL_TYPES = [
|
|
1072
|
+
"official",
|
|
1073
|
+
"user-systemd",
|
|
1074
|
+
"manual",
|
|
1075
|
+
"docker",
|
|
1076
|
+
"snap",
|
|
1077
|
+
"unknown"
|
|
1078
|
+
];
|
|
1079
|
+
const OllamaSettingSchema = z$1.object({
|
|
1080
|
+
key: z$1.enum(OLLAMA_SETTING_KEYS),
|
|
1081
|
+
/** Null when unset and Ollama decides at runtime (flash attention, allowed origins, the store path). */
|
|
1082
|
+
value: z$1.string().max(L.path).nullable(),
|
|
1083
|
+
source: z$1.object({
|
|
1084
|
+
kind: z$1.enum([
|
|
1085
|
+
"default",
|
|
1086
|
+
"manager",
|
|
1087
|
+
"unit",
|
|
1088
|
+
"dropin",
|
|
1089
|
+
"override",
|
|
1090
|
+
"env-file",
|
|
1091
|
+
"process",
|
|
1092
|
+
"config",
|
|
1093
|
+
"unattributed"
|
|
1094
|
+
]),
|
|
1095
|
+
path: PathSchema.nullable()
|
|
1096
|
+
}),
|
|
1097
|
+
writable: z$1.boolean(),
|
|
1098
|
+
/** The running Ollama has this value, but its unit files now say otherwise; a restart applies theirs. */
|
|
1099
|
+
pendingRestart: z$1.boolean().optional()
|
|
1100
|
+
});
|
|
1101
|
+
const OllamaSettingsSchema = z$1.object({
|
|
1102
|
+
/** False for docker and unknown installs, and a process whose environment this user cannot read. */
|
|
1103
|
+
readable: z$1.boolean(),
|
|
1104
|
+
settings: z$1.array(OllamaSettingSchema).max(OLLAMA_SETTING_KEYS.length),
|
|
1105
|
+
/** Unit files, drop-ins or environment files that exist but could not be read; their values may be missing. */
|
|
1106
|
+
unreadablePaths: z$1.array(PathSchema).max(L.unreadable)
|
|
1107
|
+
});
|
|
1108
|
+
const OllamaInstallSchema = z$1.object({
|
|
1109
|
+
type: z$1.enum(OLLAMA_INSTALL_TYPES),
|
|
1110
|
+
/** The systemd unit file, for `official` and `user-systemd`. */
|
|
1111
|
+
unit: PathSchema.nullable(),
|
|
1112
|
+
binary: PathSchema.nullable()
|
|
1113
|
+
});
|
|
1114
|
+
const GpuVendorSchema = z$1.enum([
|
|
1115
|
+
"nvidia",
|
|
1116
|
+
"amd",
|
|
1117
|
+
"intel"
|
|
1118
|
+
]);
|
|
1119
|
+
const HardwareProfileSchema = z$1.object({
|
|
1120
|
+
platform: TextSchema,
|
|
1121
|
+
arch: TextSchema,
|
|
1122
|
+
memoryKind: z$1.enum([
|
|
1123
|
+
"unified",
|
|
1124
|
+
"discrete",
|
|
1125
|
+
"cpu"
|
|
1126
|
+
]),
|
|
1127
|
+
totalMemoryBytes: ByteCountSchema,
|
|
1128
|
+
gpuMemoryBytes: ByteCountSchema.nullable(),
|
|
1129
|
+
gpuName: TextSchema.nullable(),
|
|
1130
|
+
gpuCount: CountSchema,
|
|
1131
|
+
gpuVendor: z$1.enum([
|
|
1132
|
+
"nvidia",
|
|
1133
|
+
"amd",
|
|
1134
|
+
"intel",
|
|
1135
|
+
"apple"
|
|
1136
|
+
]).nullable().optional(),
|
|
1137
|
+
chip: TextSchema.nullable(),
|
|
1138
|
+
diskFreeBytes: ByteCountSchema.nullable(),
|
|
1139
|
+
confidence: ConfidenceSchema,
|
|
1140
|
+
gpuWorkingSetBytes: ByteCountSchema.nullable().optional()
|
|
1141
|
+
});
|
|
1142
|
+
const KvTypeSchema = z$1.enum(KV_CACHE_TYPES);
|
|
1143
|
+
const FitRuntimeSchema = z$1.object({
|
|
1144
|
+
kind: z$1.enum(HUB_RUNTIMES),
|
|
1145
|
+
kv: z$1.union([z$1.literal("auto"), z$1.object({
|
|
1146
|
+
k: KvTypeSchema,
|
|
1147
|
+
v: KvTypeSchema
|
|
1148
|
+
})]).optional(),
|
|
1149
|
+
flashAttn: z$1.enum([
|
|
1150
|
+
"auto",
|
|
1151
|
+
"on",
|
|
1152
|
+
"off"
|
|
1153
|
+
]).optional(),
|
|
1154
|
+
slots: z$1.number().int().min(1).max(1024).optional()
|
|
1155
|
+
});
|
|
1156
|
+
const HostFactsSchema = z$1.object({
|
|
1157
|
+
os: z$1.object({
|
|
1158
|
+
name: TextSchema.nullable(),
|
|
1159
|
+
kernel: TextSchema.nullable()
|
|
1160
|
+
}),
|
|
1161
|
+
cpu: z$1.object({
|
|
1162
|
+
model: TextSchema.nullable(),
|
|
1163
|
+
cores: CountSchema.nullable(),
|
|
1164
|
+
threads: CountSchema.nullable()
|
|
1165
|
+
}),
|
|
1166
|
+
memory: z$1.object({
|
|
1167
|
+
totalBytes: ByteCountSchema,
|
|
1168
|
+
availableBytes: ByteCountSchema.nullable()
|
|
1169
|
+
}),
|
|
1170
|
+
gpus: z$1.array(z$1.object({
|
|
1171
|
+
vendor: GpuVendorSchema,
|
|
1172
|
+
name: TextSchema.nullable(),
|
|
1173
|
+
memoryBytes: ByteCountSchema.nullable(),
|
|
1174
|
+
memoryUsedBytes: ByteCountSchema.nullable()
|
|
1175
|
+
})).max(L.gpus),
|
|
1176
|
+
/** Measured on the host; `diskFreeBytes` is the model store's filesystem. */
|
|
1177
|
+
hardware: HardwareProfileSchema,
|
|
1178
|
+
ollama: z$1.object({
|
|
1179
|
+
url: z$1.string().max(L.url),
|
|
1180
|
+
reachable: z$1.boolean(),
|
|
1181
|
+
version: TextSchema.nullable(),
|
|
1182
|
+
install: OllamaInstallSchema,
|
|
1183
|
+
store: z$1.object({
|
|
1184
|
+
path: PathSchema.nullable(),
|
|
1185
|
+
source: z$1.enum([
|
|
1186
|
+
"setting",
|
|
1187
|
+
"service-home",
|
|
1188
|
+
"process-home",
|
|
1189
|
+
"installed-model"
|
|
1190
|
+
]).nullable(),
|
|
1191
|
+
mountPoint: PathSchema.nullable(),
|
|
1192
|
+
freeBytes: ByteCountSchema.nullable(),
|
|
1193
|
+
/** Low when the store path could not be resolved through its symlinks, so the mount may be another. */
|
|
1194
|
+
confidence: ConfidenceSchema
|
|
1195
|
+
}),
|
|
1196
|
+
loaded: z$1.array(z$1.object({
|
|
1197
|
+
name: z$1.string().max(L.modelName),
|
|
1198
|
+
sizeBytes: ByteCountSchema,
|
|
1199
|
+
vramBytes: ByteCountSchema,
|
|
1200
|
+
contextLength: z$1.number().int().positive().max(L.context).nullable()
|
|
1201
|
+
})).max(L.loaded)
|
|
1202
|
+
}),
|
|
1203
|
+
fitRuntime: FitRuntimeSchema,
|
|
1204
|
+
/** Low when Ollama's settings were unreadable or set a KV cache type the planner can only approximate. */
|
|
1205
|
+
fitRuntimeConfidence: ConfidenceSchema,
|
|
1206
|
+
/** The context Ollama gives a request that sets none: `OLLAMA_CONTEXT_LENGTH`, else its VRAM-tiered default. */
|
|
1207
|
+
defaultContext: z$1.number().int().positive().max(L.context)
|
|
1208
|
+
});
|
|
1209
|
+
/** Ordered: each role can do everything the ones before it can. */
|
|
1210
|
+
const MODEL_HOST_ROLES = [
|
|
1211
|
+
"chat",
|
|
1212
|
+
"manage",
|
|
1213
|
+
"admin"
|
|
1214
|
+
];
|
|
1215
|
+
/** `GET /v1/hello`: what a client checks before any other call. `role` is the caller's. */
|
|
1216
|
+
const ModelHostHelloSchema = z$1.object({
|
|
1217
|
+
protocol: z$1.number().int().positive(),
|
|
1218
|
+
minClientProtocol: z$1.number().int().positive(),
|
|
1219
|
+
version: TextSchema,
|
|
1220
|
+
serverId: TextSchema,
|
|
1221
|
+
mode: z$1.enum(["system", "user"]),
|
|
1222
|
+
role: z$1.enum(MODEL_HOST_ROLES),
|
|
1223
|
+
ollama: z$1.object({
|
|
1224
|
+
url: z$1.string().max(L.url),
|
|
1225
|
+
reachable: z$1.boolean(),
|
|
1226
|
+
version: TextSchema.nullable()
|
|
1227
|
+
}),
|
|
1228
|
+
features: z$1.array(TextSchema).max(64)
|
|
1229
|
+
});
|
|
1230
|
+
z$1.object({
|
|
1231
|
+
code: TextSchema,
|
|
1232
|
+
message: z$1.string().max(L.path)
|
|
1233
|
+
});
|
|
1234
|
+
const HubBuildIdSchema = z$1.string().max(256).regex(/^(?:\w[\w.-]*\/)?\w[\w.-]*$/);
|
|
1235
|
+
const HubPullRefSchema = z$1.string().max(400).regex(/^(?:hf\.co|huggingface\.co)\/[A-Za-z0-9][\w.-]*\/[A-Za-z0-9][\w.-]*:[\w][\w.-]*$/);
|
|
1236
|
+
const CuratedIdSchema = z$1.string().max(128).regex(/^[a-z0-9][a-z0-9._-]*$/);
|
|
1237
|
+
const LicenseIdsSchema = z$1.array(z$1.string().max(128).regex(/^[A-Za-z0-9][A-Za-z0-9._+-]*$/)).max(16);
|
|
1238
|
+
/** Printable text: no control, format or line-separator characters, and not blank. */
|
|
1239
|
+
const LabelSchema = z$1.string().max(128).regex(/^[^\p{C}\p{Zl}\p{Zp}]+$/u, "must not contain control characters").refine((value) => value.trim().length > 0, "must not be blank");
|
|
1240
|
+
/** The device that asked, as it names itself; a label until devices hold tokens. */
|
|
1241
|
+
const PullDeviceSchema = z$1.object({
|
|
1242
|
+
id: LabelSchema,
|
|
1243
|
+
name: LabelSchema
|
|
1244
|
+
});
|
|
1245
|
+
/** The layer digests the user reviewed for a curated build; null or missing means the build pins none of that kind. */
|
|
1246
|
+
const PullApprovedLayersSchema = z$1.object({
|
|
1247
|
+
model: Sha256Schema,
|
|
1248
|
+
template: Sha256Schema.nullable().optional(),
|
|
1249
|
+
params: Sha256Schema.nullable().optional(),
|
|
1250
|
+
license: Sha256Schema.nullable().optional(),
|
|
1251
|
+
projector: Sha256Schema.nullable().optional(),
|
|
1252
|
+
draft: Sha256Schema.nullable().optional()
|
|
1253
|
+
});
|
|
1254
|
+
/** A curated build, named in the host's own curated list. */
|
|
1255
|
+
const PullApprovedCuratedSchema = z$1.object({
|
|
1256
|
+
entryId: CuratedIdSchema,
|
|
1257
|
+
buildId: HubBuildIdSchema,
|
|
1258
|
+
layers: PullApprovedLayersSchema
|
|
1259
|
+
});
|
|
1260
|
+
/**
|
|
1261
|
+
* `POST /v1/jobs`: what the pull dialog showed. `licenses` are the ids it listed: the Hub card's for a Hugging Face
|
|
1262
|
+
* repo, the curated entry's `license.id` for a library build. `ref` and `sha256` are what the client proved.
|
|
1263
|
+
*/
|
|
1264
|
+
const PullJobRequestSchema = z$1.discriminatedUnion("source", [z$1.object({
|
|
1265
|
+
source: z$1.literal("hf"),
|
|
1266
|
+
repo: HfRepoSchema,
|
|
1267
|
+
buildId: HubBuildIdSchema,
|
|
1268
|
+
revision: z$1.string().regex(/^[0-9a-f]{40}$/),
|
|
1269
|
+
ref: HubPullRefSchema,
|
|
1270
|
+
sha256: Sha256Schema,
|
|
1271
|
+
sizeBytes: z$1.number().int().positive().max(L.bytes),
|
|
1272
|
+
licenses: LicenseIdsSchema,
|
|
1273
|
+
licenseAccepted: z$1.boolean(),
|
|
1274
|
+
accessConfirmed: z$1.boolean(),
|
|
1275
|
+
curated: PullApprovedCuratedSchema.nullable().optional(),
|
|
1276
|
+
device: PullDeviceSchema
|
|
1277
|
+
}), z$1.object({
|
|
1278
|
+
source: z$1.literal("library"),
|
|
1279
|
+
ref: OllamaLibRefSchema,
|
|
1280
|
+
manifestDigest: Sha256Schema,
|
|
1281
|
+
sizeBytes: z$1.number().int().positive().max(L.bytes),
|
|
1282
|
+
licenses: LicenseIdsSchema,
|
|
1283
|
+
licenseAccepted: z$1.boolean(),
|
|
1284
|
+
curated: PullApprovedCuratedSchema,
|
|
1285
|
+
device: PullDeviceSchema
|
|
1286
|
+
})]);
|
|
1287
|
+
/** Optional body of a job's cancel, pause and resume, naming the device that asked. */
|
|
1288
|
+
const PullJobActionSchema = z$1.object({ device: PullDeviceSchema.optional() });
|
|
1289
|
+
const PULL_JOB_STATES = [
|
|
1290
|
+
"queued",
|
|
1291
|
+
"checking",
|
|
1292
|
+
"downloading",
|
|
1293
|
+
"verifying",
|
|
1294
|
+
"done",
|
|
1295
|
+
"failed",
|
|
1296
|
+
"cancelled",
|
|
1297
|
+
"paused",
|
|
1298
|
+
"interrupted"
|
|
1299
|
+
];
|
|
1300
|
+
/** States that hold a reservation on the store's disk. */
|
|
1301
|
+
const PULL_JOB_ACTIVE_STATES = [
|
|
1302
|
+
"queued",
|
|
1303
|
+
"checking",
|
|
1304
|
+
"downloading",
|
|
1305
|
+
"verifying"
|
|
1306
|
+
];
|
|
1307
|
+
const PULL_JOB_FINAL_STATES = [
|
|
1308
|
+
"done",
|
|
1309
|
+
"failed",
|
|
1310
|
+
"cancelled"
|
|
1311
|
+
];
|
|
1312
|
+
/** `user` is the login `dial-stdio` reported; `via` is `local` for a client on the socket directly. */
|
|
1313
|
+
const PullJobActorSchema = z$1.object({
|
|
1314
|
+
device: TextSchema,
|
|
1315
|
+
user: TextSchema.nullable(),
|
|
1316
|
+
via: z$1.enum(["ssh", "local"])
|
|
1317
|
+
});
|
|
1318
|
+
const TimestampSchema = z$1.string().max(64);
|
|
1319
|
+
const PullJobSchema = z$1.object({
|
|
1320
|
+
id: z$1.string().regex(/^[0-9a-f-]{36}$/),
|
|
1321
|
+
state: z$1.enum(PULL_JOB_STATES),
|
|
1322
|
+
source: z$1.enum(["hf", "library"]),
|
|
1323
|
+
/** The Hugging Face repo, or the library ref. */
|
|
1324
|
+
repo: z$1.string().max(200),
|
|
1325
|
+
buildId: z$1.string().max(256),
|
|
1326
|
+
/** What Ollama pulls. */
|
|
1327
|
+
ref: z$1.string().max(L.modelName),
|
|
1328
|
+
sizeBytes: ByteCountSchema,
|
|
1329
|
+
progress: z$1.object({
|
|
1330
|
+
status: TextSchema,
|
|
1331
|
+
completedBytes: ByteCountSchema,
|
|
1332
|
+
totalBytes: ByteCountSchema.nullable()
|
|
1333
|
+
}),
|
|
1334
|
+
startedBy: PullJobActorSchema,
|
|
1335
|
+
cancelledBy: PullJobActorSchema.nullable(),
|
|
1336
|
+
createdAt: TimestampSchema,
|
|
1337
|
+
updatedAt: TimestampSchema,
|
|
1338
|
+
finishedAt: TimestampSchema.nullable(),
|
|
1339
|
+
error: z$1.object({
|
|
1340
|
+
code: TextSchema,
|
|
1341
|
+
message: z$1.string().max(L.path)
|
|
1342
|
+
}).nullable(),
|
|
1343
|
+
/** Something the user should know that is not a failure, such as a resumed pull that may start over. */
|
|
1344
|
+
notice: z$1.string().max(L.path).nullable()
|
|
1345
|
+
});
|
|
1346
|
+
z$1.object({ jobs: z$1.array(PullJobSchema).max(1024) });
|
|
1347
|
+
z$1.object({
|
|
1348
|
+
path: PathSchema.nullable(),
|
|
1349
|
+
publicKey: z$1.string().max(1024).nullable(),
|
|
1350
|
+
message: z$1.string().max(L.path).nullable()
|
|
1351
|
+
});
|
|
1352
|
+
/** What a model produces or does; the cloud catalog's `type` values plus rerank, music and sound-effect. */
|
|
1353
|
+
const HUB_MODALITIES = [
|
|
1354
|
+
"text",
|
|
1355
|
+
"embedding",
|
|
1356
|
+
"rerank",
|
|
1357
|
+
"speech-to-text",
|
|
1358
|
+
"tts",
|
|
1359
|
+
"image",
|
|
1360
|
+
"video",
|
|
1361
|
+
"music",
|
|
1362
|
+
"sound-effect"
|
|
1363
|
+
];
|
|
1364
|
+
const HubModalitySchema = z$1.enum(HUB_MODALITIES);
|
|
1365
|
+
const HUB_SLOTS_V3 = [
|
|
1366
|
+
...CURATED_SLOTS,
|
|
1367
|
+
"streaming",
|
|
1368
|
+
"clone",
|
|
1369
|
+
"edit"
|
|
1370
|
+
];
|
|
1371
|
+
/** The slots a tier may fill per modality; text is further limited per memory kind by TIER_SLOTS. */
|
|
1372
|
+
const MODALITY_SLOTS = {
|
|
1373
|
+
text: CURATED_SLOTS,
|
|
1374
|
+
embedding: ["best", "fast"],
|
|
1375
|
+
rerank: ["best", "fast"],
|
|
1376
|
+
"speech-to-text": [
|
|
1377
|
+
"best",
|
|
1378
|
+
"fast",
|
|
1379
|
+
"streaming"
|
|
1380
|
+
],
|
|
1381
|
+
tts: [
|
|
1382
|
+
"best",
|
|
1383
|
+
"fast",
|
|
1384
|
+
"clone"
|
|
1385
|
+
],
|
|
1386
|
+
image: [
|
|
1387
|
+
"best",
|
|
1388
|
+
"fast",
|
|
1389
|
+
"edit"
|
|
1390
|
+
],
|
|
1391
|
+
video: ["best", "fast"],
|
|
1392
|
+
music: ["best"],
|
|
1393
|
+
"sound-effect": ["best"]
|
|
1394
|
+
};
|
|
1395
|
+
const HUB_PROFILE_IDS = ["quality", "fast"];
|
|
1396
|
+
const TEXT_ROLES = [
|
|
1397
|
+
"chat",
|
|
1398
|
+
"code",
|
|
1399
|
+
"vision"
|
|
1400
|
+
];
|
|
1401
|
+
const MAX_PICKS = 24;
|
|
1402
|
+
const MAX_METRICS = 16;
|
|
1403
|
+
const DISPLAY_TEXT = /^[\x21-\x7e]([\x20-\x7e]*[\x21-\x7e])?$/;
|
|
1404
|
+
const LicenseLabelSchema = z$1.string().max(48).regex(DISPLAY_TEXT);
|
|
1405
|
+
const LICENSE_LABELS = /* @__PURE__ */ new Map([
|
|
1406
|
+
["apache-2.0", "Apache 2.0"],
|
|
1407
|
+
["mit", "MIT"],
|
|
1408
|
+
["bsd-2-clause", "BSD 2-Clause"],
|
|
1409
|
+
["bsd-3-clause", "BSD 3-Clause"],
|
|
1410
|
+
["isc", "ISC"],
|
|
1411
|
+
["gemma", "Gemma Terms of Use"]
|
|
1412
|
+
]);
|
|
1413
|
+
const labelKey = (text) => text.toLowerCase().replace(/(\d)\.0\b/g, "$1").replace(/\b(the|version|software)\b/g, "").replace(/[^a-z0-9]/g, "").replace(/licen[cs]e/g, "");
|
|
1414
|
+
const LABEL_OWNERS = new Map([...LICENSE_LABELS].flatMap(([id, label]) => [[labelKey(label), id], [labelKey(id), id]]));
|
|
1415
|
+
/** A build's own license, with the label clients show beside it. */
|
|
1416
|
+
const BuildLicenseSchema = LicenseRefSchema.extend({ label: LicenseLabelSchema });
|
|
1417
|
+
const EntryLicenseSchema = LicenseSchema.extend({ label: LicenseLabelSchema });
|
|
1418
|
+
const TextProfileSettingsObjectSchema = z$1.object({
|
|
1419
|
+
numCtx: ContextSchema,
|
|
1420
|
+
kv: z$1.enum(KV_CACHE_TYPES),
|
|
1421
|
+
flashAttn: z$1.enum([
|
|
1422
|
+
"on",
|
|
1423
|
+
"auto",
|
|
1424
|
+
"off"
|
|
1425
|
+
]),
|
|
1426
|
+
draftNumPredict: z$1.number().int().min(0).max(16).optional(),
|
|
1427
|
+
numBatch: z$1.number().int().min(64).max(8192)
|
|
1428
|
+
});
|
|
1429
|
+
const TextProfileSettingsSchema = z$1.preprocess((raw) => typeof raw === "object" && raw !== null && !Array.isArray(raw) ? { ...raw } : raw, TextProfileSettingsObjectSchema);
|
|
1430
|
+
const ProfileSchema = z$1.object({
|
|
1431
|
+
id: z$1.enum(HUB_PROFILE_IDS),
|
|
1432
|
+
settings: TextProfileSettingsSchema,
|
|
1433
|
+
evidenceRunId: z$1.string().max(120).regex(/^[A-Za-z0-9][A-Za-z0-9:._-]*$/),
|
|
1434
|
+
measuredOn: z$1.object({
|
|
1435
|
+
date: z$1.iso.date(),
|
|
1436
|
+
hardware: SlugSchema,
|
|
1437
|
+
runtime: HubRuntimeSchema,
|
|
1438
|
+
runtimeVersion: RuntimeVersionSchema
|
|
1439
|
+
}),
|
|
1440
|
+
metrics: z$1.record(z$1.string().regex(/^[a-z][A-Za-z0-9]{0,39}$/), z$1.number().min(0).max(1e9)).refine(maxKeys(MAX_METRICS), "too many metrics").refine((metrics) => Object.hasOwn(metrics, "gpuPeakMiB") && Number.isFinite(metrics.gpuPeakMiB) && metrics.gpuPeakMiB > 0, {
|
|
1441
|
+
message: "metrics needs a positive gpuPeakMiB",
|
|
1442
|
+
path: ["gpuPeakMiB"]
|
|
1443
|
+
}),
|
|
1444
|
+
note: z$1.string().max(160).regex(DISPLAY_TEXT).optional()
|
|
1445
|
+
});
|
|
1446
|
+
const BuildV3Schema = BuildSchema.extend({
|
|
1447
|
+
license: BuildLicenseSchema,
|
|
1448
|
+
profiles: z$1.array(ProfileSchema).max(HUB_PROFILE_IDS.length).default([])
|
|
1449
|
+
});
|
|
1450
|
+
const TextEntryObjectSchema = EntryHeaderSchema.omit({
|
|
1451
|
+
roles: true,
|
|
1452
|
+
capabilities: true,
|
|
1453
|
+
license: true
|
|
1454
|
+
}).extend({
|
|
1455
|
+
modality: z$1.literal("text"),
|
|
1456
|
+
roles: z$1.array(z$1.enum(TEXT_ROLES)).min(1).max(8),
|
|
1457
|
+
license: EntryLicenseSchema,
|
|
1458
|
+
capabilities: z$1.object({
|
|
1459
|
+
tools: z$1.boolean(),
|
|
1460
|
+
vision: z$1.boolean(),
|
|
1461
|
+
thinking: z$1.boolean()
|
|
1462
|
+
}),
|
|
1463
|
+
builds: z$1.array(BuildV3Schema).min(1).max(16)
|
|
1464
|
+
});
|
|
1465
|
+
/** The v2 header a text entry stands for, so v2's entry and build checks apply unchanged. */
|
|
1466
|
+
const v2Header = (entry) => ({
|
|
1467
|
+
...entry,
|
|
1468
|
+
capabilities: {
|
|
1469
|
+
...entry.capabilities,
|
|
1470
|
+
embeddings: false
|
|
1471
|
+
}
|
|
1472
|
+
});
|
|
1473
|
+
function profileIssues(entry, build, b) {
|
|
1474
|
+
const issues = [];
|
|
1475
|
+
const pins = build.ollama?.kind === "library" || build.ollama?.kind === "hf-pull" ? build.ollama.layers : void 0;
|
|
1476
|
+
const hasDraft = entry.arch.mtpLayers > 0 || build.draft !== void 0 || !!pins?.draft;
|
|
1477
|
+
build.profiles.forEach((profile, p) => {
|
|
1478
|
+
const at = (...rest) => [
|
|
1479
|
+
"builds",
|
|
1480
|
+
b,
|
|
1481
|
+
"profiles",
|
|
1482
|
+
p,
|
|
1483
|
+
...rest
|
|
1484
|
+
];
|
|
1485
|
+
const { settings } = profile;
|
|
1486
|
+
if (build.profiles.slice(0, p).some((other) => other.id === profile.id)) issues.push({
|
|
1487
|
+
path: at("id"),
|
|
1488
|
+
message: `duplicate profile ${profile.id}`
|
|
1489
|
+
});
|
|
1490
|
+
if (settings.numCtx > entry.arch.contextMax) issues.push({
|
|
1491
|
+
path: at("settings", "numCtx"),
|
|
1492
|
+
message: "numCtx exceeds arch.contextMax"
|
|
1493
|
+
});
|
|
1494
|
+
if (settings.kv !== "f16" && settings.flashAttn === "off") issues.push({
|
|
1495
|
+
path: at("settings", "kv"),
|
|
1496
|
+
message: "a quantized KV cache needs flash attention"
|
|
1497
|
+
});
|
|
1498
|
+
if ((settings.draftNumPredict ?? 0) > 0 && !hasDraft) issues.push({
|
|
1499
|
+
path: at("settings", "draftNumPredict"),
|
|
1500
|
+
message: "draftNumPredict needs a draft or MTP layer"
|
|
1501
|
+
});
|
|
1502
|
+
});
|
|
1503
|
+
return issues;
|
|
1504
|
+
}
|
|
1505
|
+
function labelIssue(license, path) {
|
|
1506
|
+
const id = license.id.toLowerCase();
|
|
1507
|
+
const known = LICENSE_LABELS.get(id);
|
|
1508
|
+
if (known !== void 0) return known === license.label ? [] : [{
|
|
1509
|
+
path,
|
|
1510
|
+
message: `the label for ${license.id} is ${known}`
|
|
1511
|
+
}];
|
|
1512
|
+
const owner = LABEL_OWNERS.get(labelKey(license.label));
|
|
1513
|
+
return owner === void 0 || owner === id ? [] : [{
|
|
1514
|
+
path,
|
|
1515
|
+
message: `${license.label} reads as ${owner}`
|
|
1516
|
+
}];
|
|
1517
|
+
}
|
|
1518
|
+
function licenseIssues(entry, build, b) {
|
|
1519
|
+
const issues = [...labelIssue(build.license, [
|
|
1520
|
+
"builds",
|
|
1521
|
+
b,
|
|
1522
|
+
"license",
|
|
1523
|
+
"label"
|
|
1524
|
+
])];
|
|
1525
|
+
const rank = licenseRank(build.license.class);
|
|
1526
|
+
if (rank < licenseRank(entry.license.base.class)) issues.push({
|
|
1527
|
+
path: [
|
|
1528
|
+
"builds",
|
|
1529
|
+
b,
|
|
1530
|
+
"license",
|
|
1531
|
+
"class"
|
|
1532
|
+
],
|
|
1533
|
+
message: "less restrictive than the base license"
|
|
1534
|
+
});
|
|
1535
|
+
if (rank > licenseRank(entry.license.class)) issues.push({
|
|
1536
|
+
path: [
|
|
1537
|
+
"builds",
|
|
1538
|
+
b,
|
|
1539
|
+
"license",
|
|
1540
|
+
"class"
|
|
1541
|
+
],
|
|
1542
|
+
message: "more restrictive than the entry license"
|
|
1543
|
+
});
|
|
1544
|
+
return issues;
|
|
1545
|
+
}
|
|
1546
|
+
function refineTextEntry(entry, ctx) {
|
|
1547
|
+
const header = v2Header(entry);
|
|
1548
|
+
const issues = [...headerIssues(header), ...labelIssue(entry.license, ["license", "label"])];
|
|
1549
|
+
const buildIds = /* @__PURE__ */ new Set();
|
|
1550
|
+
entry.builds.forEach((build, b) => {
|
|
1551
|
+
if (buildIds.has(build.id)) issues.push({
|
|
1552
|
+
path: [
|
|
1553
|
+
"builds",
|
|
1554
|
+
b,
|
|
1555
|
+
"id"
|
|
1556
|
+
],
|
|
1557
|
+
message: `duplicate build id ${build.id}`
|
|
1558
|
+
});
|
|
1559
|
+
buildIds.add(build.id);
|
|
1560
|
+
issues.push(...buildIssues(header, build, b), ...licenseIssues(entry, build, b), ...profileIssues(entry, build, b));
|
|
1561
|
+
});
|
|
1562
|
+
for (const { path, message } of issues) ctx.addIssue({
|
|
1563
|
+
code: "custom",
|
|
1564
|
+
path,
|
|
1565
|
+
message
|
|
1566
|
+
});
|
|
1567
|
+
}
|
|
1568
|
+
/** A v3 entry. Only text entries exist so far; other modalities gain their capability shapes with their runtimes. */
|
|
1569
|
+
const HubEntryV3Schema = TextEntryObjectSchema.superRefine(refineTextEntry);
|
|
1570
|
+
const TierPickV3Schema = z$1.object({
|
|
1571
|
+
modality: HubModalitySchema.default("text"),
|
|
1572
|
+
slot: z$1.enum(HUB_SLOTS_V3),
|
|
1573
|
+
entry: SlugSchema,
|
|
1574
|
+
build: SlugSchema,
|
|
1575
|
+
profile: z$1.enum(HUB_PROFILE_IDS).optional(),
|
|
1576
|
+
numCtx: ContextSchema.optional()
|
|
1577
|
+
});
|
|
1578
|
+
const TierV3Schema = z$1.object({
|
|
1579
|
+
memoryKind: z$1.enum(HUB_TIER_KINDS),
|
|
1580
|
+
minGiB: z$1.number().int().nonnegative().max(65536),
|
|
1581
|
+
picks: z$1.array(TierPickV3Schema).max(MAX_PICKS)
|
|
1582
|
+
});
|
|
1583
|
+
/** What the curated-v2 channel publishes from this list; curatedV2FromV3 turns it into the v2 manifest. */
|
|
1584
|
+
const V2ChannelSchema = z$1.object({
|
|
1585
|
+
sequence: z$1.number().int().min(1).max(HUB_MAX_SEQUENCE),
|
|
1586
|
+
contentSha256: z$1.record(z$1.string().regex(/^[1-9][0-9]{0,8}$/), z$1.string().regex(/^[0-9a-f]{64}$/)).refine(maxKeys(200), "too many sequences"),
|
|
1587
|
+
updatedAt: z$1.iso.datetime(),
|
|
1588
|
+
changelog: z$1.array(ChangelogItemSchema).max(200),
|
|
1589
|
+
rankings: z$1.partialRecord(HubRoleSchema, z$1.array(SlugSchema).max(500)),
|
|
1590
|
+
tiers: z$1.array(TierSchema).max(32),
|
|
1591
|
+
entries: z$1.array(z$1.object({
|
|
1592
|
+
entry: SlugSchema,
|
|
1593
|
+
builds: z$1.array(SlugSchema).min(1).max(16)
|
|
1594
|
+
})).max(500)
|
|
1595
|
+
});
|
|
1596
|
+
const ManifestV3ObjectSchema = z$1.object({
|
|
1597
|
+
schemaVersion: z$1.literal(3),
|
|
1598
|
+
sequence: z$1.number().int().min(1).max(HUB_MAX_SEQUENCE).optional(),
|
|
1599
|
+
updatedAt: z$1.iso.datetime(),
|
|
1600
|
+
notesUrl: HttpsUrlSchema.nullable().optional(),
|
|
1601
|
+
changelog: z$1.array(ChangelogItemSchema).max(200).default([]),
|
|
1602
|
+
revokedKeyIds: RevokedKeyIdsSchema,
|
|
1603
|
+
policy: HubPolicySchema.prefault({}),
|
|
1604
|
+
families: z$1.record(SlugSchema, FamilySchema).refine(maxKeys(200), "too many families"),
|
|
1605
|
+
rankings: z$1.partialRecord(HubModalitySchema, z$1.array(SlugSchema).max(500)).default({}),
|
|
1606
|
+
tiers: z$1.array(TierV3Schema).max(32).default([]),
|
|
1607
|
+
entries: z$1.array(HubEntryV3Schema).max(500),
|
|
1608
|
+
v2Channel: V2ChannelSchema.optional()
|
|
1609
|
+
});
|
|
1610
|
+
function pickV3Issue(pick, tier, byId) {
|
|
1611
|
+
if (!MODALITY_SLOTS[pick.modality].includes(pick.slot)) return `no ${pick.slot} slot for ${pick.modality}`;
|
|
1612
|
+
const kindSlots = TIER_SLOTS[tier.memoryKind];
|
|
1613
|
+
if (pick.modality === "text" && !kindSlots.includes(pick.slot)) return `no ${pick.slot} slot in a ${tier.memoryKind} tier`;
|
|
1614
|
+
const entry = byId.get(pick.entry);
|
|
1615
|
+
if (!entry) return `no entry ${pick.entry}`;
|
|
1616
|
+
if (entry.modality !== pick.modality) return `${pick.entry} is not a ${pick.modality} entry`;
|
|
1617
|
+
const build = entry.builds.find((candidate) => candidate.id === pick.build);
|
|
1618
|
+
if (!build) return `no build ${pick.build} in ${pick.entry}`;
|
|
1619
|
+
if (pick.profile && !build.profiles.some((profile) => profile.id === pick.profile)) return `no ${pick.profile} profile on ${pick.entry}/${pick.build}`;
|
|
1620
|
+
if (pick.numCtx !== void 0 && pick.numCtx > entry.arch.contextMax) return "numCtx exceeds arch.contextMax";
|
|
1621
|
+
return null;
|
|
1622
|
+
}
|
|
1623
|
+
function refineManifestV3(manifest, ctx) {
|
|
1624
|
+
const issue = (path, message) => ctx.addIssue({
|
|
1625
|
+
code: "custom",
|
|
1626
|
+
path,
|
|
1627
|
+
message
|
|
1628
|
+
});
|
|
1629
|
+
const byId = /* @__PURE__ */ new Map();
|
|
1630
|
+
manifest.entries.forEach((entry, i) => {
|
|
1631
|
+
if (byId.has(entry.id)) issue([
|
|
1632
|
+
"entries",
|
|
1633
|
+
i,
|
|
1634
|
+
"id"
|
|
1635
|
+
], `duplicate entry id ${entry.id}`);
|
|
1636
|
+
byId.set(entry.id, entry);
|
|
1637
|
+
if (!Object.hasOwn(manifest.families, entry.family)) issue([
|
|
1638
|
+
"entries",
|
|
1639
|
+
i,
|
|
1640
|
+
"family"
|
|
1641
|
+
], `unknown family`);
|
|
1642
|
+
});
|
|
1643
|
+
manifest.tiers.forEach((tier, t) => {
|
|
1644
|
+
if (manifest.tiers.slice(0, t).some((o) => o.memoryKind === tier.memoryKind && o.minGiB === tier.minGiB)) issue(["tiers", t], "duplicate tier");
|
|
1645
|
+
tier.picks.forEach((pick, p) => {
|
|
1646
|
+
const reason = pickV3Issue(pick, tier, byId);
|
|
1647
|
+
if (reason) issue([
|
|
1648
|
+
"tiers",
|
|
1649
|
+
t,
|
|
1650
|
+
"picks",
|
|
1651
|
+
p
|
|
1652
|
+
], reason);
|
|
1653
|
+
if (tier.picks.slice(0, p).some((o) => o.modality === pick.modality && o.slot === pick.slot)) issue([
|
|
1654
|
+
"tiers",
|
|
1655
|
+
t,
|
|
1656
|
+
"picks",
|
|
1657
|
+
p,
|
|
1658
|
+
"slot"
|
|
1659
|
+
], "slot taken");
|
|
1660
|
+
});
|
|
1661
|
+
});
|
|
1662
|
+
for (const modality of HUB_MODALITIES) {
|
|
1663
|
+
const ids = manifest.rankings[modality] ?? [];
|
|
1664
|
+
if (new Set(ids).size !== ids.length) issue(["rankings", modality], "ranking lists an id twice");
|
|
1665
|
+
ids.forEach((id, i) => {
|
|
1666
|
+
if (byId.get(id)?.modality !== modality) issue([
|
|
1667
|
+
"rankings",
|
|
1668
|
+
modality,
|
|
1669
|
+
i
|
|
1670
|
+
], `no ${modality} entry ${id}`);
|
|
1671
|
+
});
|
|
1672
|
+
}
|
|
1673
|
+
const channel = manifest.v2Channel;
|
|
1674
|
+
if (channel) {
|
|
1675
|
+
for (const key of Object.keys(channel.contentSha256)) if (Number(key) > channel.sequence) issue([
|
|
1676
|
+
"v2Channel",
|
|
1677
|
+
"contentSha256",
|
|
1678
|
+
key
|
|
1679
|
+
], "a later sequence");
|
|
1680
|
+
}
|
|
1681
|
+
manifest.v2Channel?.entries.forEach(({ entry: id, builds }, i) => {
|
|
1682
|
+
const path = [
|
|
1683
|
+
"v2Channel",
|
|
1684
|
+
"entries",
|
|
1685
|
+
i
|
|
1686
|
+
];
|
|
1687
|
+
const entry = byId.get(id);
|
|
1688
|
+
if (entry?.modality !== "text") return issue(path, `no text entry ${id}`);
|
|
1689
|
+
if (manifest.v2Channel?.entries.slice(0, i).some((other) => other.entry === id)) issue(path, `entry ${id} listed twice`);
|
|
1690
|
+
if (new Set(builds).size !== builds.length) issue([...path, "builds"], "a build is listed twice");
|
|
1691
|
+
builds.forEach((buildId, b) => {
|
|
1692
|
+
if (!entry.builds.some((build) => build.id === buildId)) issue([
|
|
1693
|
+
...path,
|
|
1694
|
+
"builds",
|
|
1695
|
+
b
|
|
1696
|
+
], `no build ${buildId}`);
|
|
1697
|
+
});
|
|
1698
|
+
});
|
|
1699
|
+
}
|
|
1700
|
+
ManifestV3ObjectSchema.superRefine(refineManifestV3).superRefine(refinePublished);
|
|
1701
|
+
const GIB$2 = 1024 ** 3;
|
|
1702
|
+
const GB = 1e9;
|
|
1703
|
+
const DECODE_CONSTANTS = {
|
|
1704
|
+
bandwidthEfficiency: .8,
|
|
1705
|
+
moeOverhead: 2,
|
|
1706
|
+
speculativeGain: 1.5
|
|
1707
|
+
};
|
|
1708
|
+
const apple = (chip, gbps) => ({
|
|
1709
|
+
match: new RegExp(`^Apple ${chip}$`, "i"),
|
|
1710
|
+
gbps
|
|
1711
|
+
});
|
|
1712
|
+
const geforce = (card, gbps) => ({
|
|
1713
|
+
match: new RegExp(`\\bRTX ${card}$`, "i"),
|
|
1714
|
+
gbps
|
|
1715
|
+
});
|
|
1716
|
+
200 * GIB$2 / GB / DECODE_CONSTANTS.bandwidthEfficiency, apple("M1 Pro", 200), apple("M1 Max", 400), apple("M1 Ultra", 800), apple("M2", 100), apple("M2 Pro", 200), apple("M2 Max", 400), apple("M2 Ultra", 800), apple("M3", 100), apple("M3 Pro", 150), apple("M3 Max", 300), apple("M3 Ultra", 819), apple("M4", 120), apple("M4 Pro", 273), apple("M4 Max", 410), apple("M5", 153), apple("M5 Pro", 307), apple("M5 Max", 460), geforce("5060 Ti", 448), geforce("5070", 672), geforce("5070 Ti", 896), geforce("5080", 960), geforce("5090", 1792);
|
|
1717
|
+
const MIB = 1024 ** 2;
|
|
1718
|
+
const GIB$1 = 1024 ** 3;
|
|
1719
|
+
const FIT_CONSTANTS = {
|
|
1720
|
+
marginBytes: {
|
|
1721
|
+
cpu: 256 * MIB,
|
|
1722
|
+
unified: GIB$1,
|
|
1723
|
+
discrete: 2 * GIB$1
|
|
1724
|
+
},
|
|
1725
|
+
intelPoolBytes: 512 * MIB,
|
|
1726
|
+
recurrentActivationWidths: 20,
|
|
1727
|
+
uncalibratedRecurrentBytesPerToken: 2 * MIB,
|
|
1728
|
+
assumedEmbeddingLength: 16384,
|
|
1729
|
+
kvCellPadding: 256,
|
|
1730
|
+
unifiedLargeMinBytes: 36 * GIB$1,
|
|
1731
|
+
unifiedLargeFraction: .75,
|
|
1732
|
+
unifiedSmallFraction: .66,
|
|
1733
|
+
discreteOffloadRamFraction: .7,
|
|
1734
|
+
cpuFraction: .75,
|
|
1735
|
+
projectorComputeFraction: .45,
|
|
1736
|
+
faOffAssumedHeads: 128
|
|
1737
|
+
};
|
|
1738
|
+
const padCells = (n) => Math.ceil(n / FIT_CONSTANTS.kvCellPadding) * FIT_CONSTANTS.kvCellPadding;
|
|
1739
|
+
/** Ollama 0.40.11's -b/-ub for a generation load, from its context across all slots (server/sched.go). */
|
|
1740
|
+
function ollamaUbatch(context, slots = 1) {
|
|
1741
|
+
const total = context * slots;
|
|
1742
|
+
if (total > 32768) return 2048;
|
|
1743
|
+
return total > 4096 ? 1024 : 512;
|
|
1744
|
+
}
|
|
1745
|
+
/**
|
|
1746
|
+
* Compute buffer growth with flash attention off: the F32 KQ matrix plus an F32 mask, cells x ubatch x (heads + 1)
|
|
1747
|
+
* x 4 bytes. Measured exactly on llama-server b11889; with flash attention on the mask is F16 and there is no KQ.
|
|
1748
|
+
*/
|
|
1749
|
+
function flashAttnOffBytes(context, ubatch, headCount) {
|
|
1750
|
+
return padCells(context) * ubatch * 4 * (headCount + 1);
|
|
1751
|
+
}
|
|
1752
|
+
/**
|
|
1753
|
+
* F32 graph activations per ubatch token, measured on Ollama 0.40.11's CPU backend; without the widths, a bound
|
|
1754
|
+
* from the bytes per layer that holds at 2.4 bits per weight or more.
|
|
1755
|
+
*/
|
|
1756
|
+
function activationBytesPerToken(model) {
|
|
1757
|
+
const { arch } = model;
|
|
1758
|
+
const extra = (arch.moe ? 2 * arch.moe.experts : 0) + 32;
|
|
1759
|
+
let bytes;
|
|
1760
|
+
if (arch.embeddingLength && arch.activeFeedForwardLength) {
|
|
1761
|
+
const ff = arch.activeFeedForwardLength;
|
|
1762
|
+
const ffn = arch.moe ? Math.max(3 * ff, ff + arch.moe.used * arch.embeddingLength) : 3 * ff;
|
|
1763
|
+
const mla = arch.mla && arch.headCount ? arch.headCount * 2 * (arch.mla.kvLoraRank + arch.mla.ropeDim) : 0;
|
|
1764
|
+
const transformer = Math.max(ffn, mla) + 5 * arch.embeddingLength + extra;
|
|
1765
|
+
const recurrent = arch.recurrent ? FIT_CONSTANTS.recurrentActivationWidths * arch.embeddingLength : 0;
|
|
1766
|
+
bytes = 4 * Math.max(transformer, recurrent);
|
|
1767
|
+
} else {
|
|
1768
|
+
let active = model.weightsBytes;
|
|
1769
|
+
if (arch.moe) {
|
|
1770
|
+
const idle = 1 - arch.moe.used / arch.moe.experts;
|
|
1771
|
+
const expertBytes = arch.moe.moeLayers * (model.expertBytesPerLayer ?? 0);
|
|
1772
|
+
active = expertBytes && expertBytes < active ? active - expertBytes * idle : active * Math.max(1 - idle, .25);
|
|
1773
|
+
}
|
|
1774
|
+
bytes = Math.ceil((arch.recurrent ? 60 : 44) * Math.sqrt(active / arch.blockCount)) + 4 * extra;
|
|
1775
|
+
}
|
|
1776
|
+
const calibrated = RECURRENT_KINDS.includes(arch.recurrent?.kind ?? "");
|
|
1777
|
+
if (arch.recurrent && !calibrated) return Math.max(bytes, FIT_CONSTANTS.uncalibratedRecurrentBytesPerToken);
|
|
1778
|
+
return bytes;
|
|
1779
|
+
}
|
|
1780
|
+
/** F16 KQ masks under flash attention: one per attention kind, cache cells x ubatch. */
|
|
1781
|
+
function attentionMaskBytes(arch, context, ubatch) {
|
|
1782
|
+
const cells = padCells(context);
|
|
1783
|
+
return ((arch.full.layers > 0 || arch.mla || arch.kvProbe ? cells : 0) + (arch.swa ? Math.min(cells, padCells(arch.swa.window + ubatch)) : 0)) * ubatch * 2;
|
|
1784
|
+
}
|
|
1785
|
+
/**
|
|
1786
|
+
* Metal reserves an F16 copy of one layer's K and V across all slots inside every flash attention op; CUDA converts
|
|
1787
|
+
* a quantized cache the same way in its pool. From llama.cpp source, not measured.
|
|
1788
|
+
*/
|
|
1789
|
+
function kvScratchBytes(arch, context, ubatch, slots) {
|
|
1790
|
+
const cells = padCells(context);
|
|
1791
|
+
if (arch.kvProbe) return Math.ceil(arch.kvProbe.bytesPerToken * cells * slots / arch.blockCount);
|
|
1792
|
+
const { full, swa, mla } = arch;
|
|
1793
|
+
const fullBytes = full.layers > 0 ? cells * full.kvHeads * (full.keyLength + full.valueLength) : 0;
|
|
1794
|
+
const swaCells = swa ? Math.min(cells, padCells(swa.window + ubatch)) : 0;
|
|
1795
|
+
const swaBytes = swa ? swaCells * swa.kvHeads * (swa.keyLength + swa.valueLength) : 0;
|
|
1796
|
+
const mlaBytes = mla ? cells * (mla.kvLoraRank + mla.ropeDim) : 0;
|
|
1797
|
+
return Math.max(fullBytes, swaBytes, mlaBytes) * 2 * slots;
|
|
1798
|
+
}
|
|
1799
|
+
/**
|
|
1800
|
+
* The runtime's compute buffers at this ubatch. CPU figures are measured; GPU additions (host mask copy on unified
|
|
1801
|
+
* memory, KV scratch, pipeline input copies) come from llama.cpp source.
|
|
1802
|
+
*/
|
|
1803
|
+
function computeBufferBytes(model, context, ubatch, options) {
|
|
1804
|
+
const { arch } = model;
|
|
1805
|
+
const devices = options.devices ?? 1;
|
|
1806
|
+
const masks = attentionMaskBytes(arch, context, ubatch);
|
|
1807
|
+
const attention = options.flashAttnOff ? flashAttnOffBytes(context, ubatch, arch.headCount ?? FIT_CONSTANTS.faOffAssumedHeads) : masks;
|
|
1808
|
+
const scratch = options.memoryKind === "cpu" ? 0 : kvScratchBytes(arch, context, ubatch, options.slots ?? 1);
|
|
1809
|
+
let bytes = devices * (ubatch * activationBytesPerToken(model) + attention + scratch);
|
|
1810
|
+
const maskCopy = options.flashAttnOff ? 2 * masks : masks;
|
|
1811
|
+
if (options.memoryKind === "unified") bytes += maskCopy;
|
|
1812
|
+
if (devices > 1) {
|
|
1813
|
+
const input = ubatch * 4 * (arch.embeddingLength ?? FIT_CONSTANTS.assumedEmbeddingLength);
|
|
1814
|
+
bytes += devices * (3 * maskCopy + 4 * input);
|
|
1815
|
+
}
|
|
1816
|
+
return bytes;
|
|
1817
|
+
}
|
|
1818
|
+
/** GPUs a layer split spans; HardwareProfile only sums their VRAM. */
|
|
1819
|
+
function splitDevices(hw) {
|
|
1820
|
+
return hw.memoryKind === "discrete" && hw.gpuMemoryBytes ? Math.max(1, hw.gpuCount) : 1;
|
|
1821
|
+
}
|
|
1822
|
+
const intelPool = (hw) => hw.gpuVendor === "intel" ? FIT_CONSTANTS.intelPoolBytes : 0;
|
|
1823
|
+
/** The headroom a plan keeps free on this machine; see FIT_CONSTANTS.marginBytes. */
|
|
1824
|
+
function fitMarginBytes(hw) {
|
|
1825
|
+
const { cpuOnly } = memoryBudgets(hw);
|
|
1826
|
+
if (cpuOnly) return FIT_CONSTANTS.marginBytes.cpu;
|
|
1827
|
+
if (hw.memoryKind === "unified") return FIT_CONSTANTS.marginBytes.unified + intelPool(hw);
|
|
1828
|
+
return (FIT_CONSTANTS.marginBytes.discrete + intelPool(hw)) * splitDevices(hw);
|
|
1829
|
+
}
|
|
1830
|
+
/**
|
|
1831
|
+
* The machine as Ollama uses it. Ollama drops integrated GPUs it reaches through Vulkan unless OLLAMA_IGPU_ENABLE=1
|
|
1832
|
+
* (discover/runner.go), and Intel's are Vulkan-only there, so an Intel integrated GPU is planned as CPU only.
|
|
1833
|
+
*/
|
|
1834
|
+
function ollamaHardware(hw) {
|
|
1835
|
+
if (hw.gpuVendor !== "intel" || hw.memoryKind !== "unified") return hw;
|
|
1836
|
+
return {
|
|
1837
|
+
...hw,
|
|
1838
|
+
memoryKind: "cpu",
|
|
1839
|
+
gpuMemoryBytes: null,
|
|
1840
|
+
gpuName: null,
|
|
1841
|
+
gpuCount: 0,
|
|
1842
|
+
gpuVendor: null
|
|
1843
|
+
};
|
|
1844
|
+
}
|
|
1845
|
+
/** Says why an Intel integrated GPU is planned as CPU only (ollamaHardware), for a machine description. */
|
|
1846
|
+
const OLLAMA_SKIPS_INTEL_IGPU = "Ollama does not use Intel integrated graphics, so picks and badges assume the CPU.";
|
|
1847
|
+
/**
|
|
1848
|
+
* An Intel card on Linux of unknown memory: the kernel does not report it, and the probe reads it from a SYCL or Vulkan
|
|
1849
|
+
* build of llama-server (`--list-devices`) when one is found (local-models hardware.ts).
|
|
1850
|
+
*/
|
|
1851
|
+
function vramNeedsLlamaServer(hw) {
|
|
1852
|
+
return hw.platform === "linux" && hw.memoryKind === "discrete" && hw.gpuVendor === "intel" && hw.gpuMemoryBytes === null;
|
|
1853
|
+
}
|
|
1854
|
+
function memoryBudgets(hw) {
|
|
1855
|
+
if (hw.memoryKind === "unified") {
|
|
1856
|
+
const fraction = hw.totalMemoryBytes >= FIT_CONSTANTS.unifiedLargeMinBytes ? FIT_CONSTANTS.unifiedLargeFraction : FIT_CONSTANTS.unifiedSmallFraction;
|
|
1857
|
+
const gpu = hw.gpuMemoryBytes || hw.gpuWorkingSetBytes || hw.totalMemoryBytes * fraction;
|
|
1858
|
+
const cpuRam = hw.totalMemoryBytes * FIT_CONSTANTS.cpuFraction;
|
|
1859
|
+
return {
|
|
1860
|
+
gpu,
|
|
1861
|
+
ramPool: gpu > hw.totalMemoryBytes ? cpuRam : Math.max(0, cpuRam - gpu),
|
|
1862
|
+
cpuOnly: false
|
|
1863
|
+
};
|
|
1864
|
+
}
|
|
1865
|
+
if (hw.memoryKind === "discrete" && hw.gpuMemoryBytes) return {
|
|
1866
|
+
gpu: hw.gpuMemoryBytes,
|
|
1867
|
+
ramPool: hw.totalMemoryBytes * FIT_CONSTANTS.discreteOffloadRamFraction,
|
|
1868
|
+
cpuOnly: false
|
|
1869
|
+
};
|
|
1870
|
+
return {
|
|
1871
|
+
gpu: hw.totalMemoryBytes * FIT_CONSTANTS.cpuFraction,
|
|
1872
|
+
ramPool: 0,
|
|
1873
|
+
cpuOnly: true
|
|
1874
|
+
};
|
|
1875
|
+
}
|
|
1876
|
+
const DEFAULT_MAX_NUM_CTX = 32768;
|
|
1877
|
+
/** The num_ctx the Ollama backend requests for a model reporting a `reported`-token window. */
|
|
1878
|
+
function ollamaNumCtx(reported) {
|
|
1879
|
+
const configuredCap = Number(process.env.OLLAMA_MAX_NUM_CTX);
|
|
1880
|
+
return Math.min(reported, Number.isFinite(configuredCap) && configuredCap > 0 ? configuredCap : DEFAULT_MAX_NUM_CTX);
|
|
1881
|
+
}
|
|
1882
|
+
const SIZE_HEADROOM = .8;
|
|
1883
|
+
const SIZE_ONLY_LAYERS = 24;
|
|
1884
|
+
/** One token-wide attention layer: compute gets the context's mask, and the cache it cannot size stays out. */
|
|
1885
|
+
const sizeOnlyArch = (context) => ({
|
|
1886
|
+
contextMax: context,
|
|
1887
|
+
blockCount: SIZE_ONLY_LAYERS,
|
|
1888
|
+
full: {
|
|
1889
|
+
layers: 1,
|
|
1890
|
+
kvHeads: 1,
|
|
1891
|
+
keyLength: 1,
|
|
1892
|
+
valueLength: 1
|
|
1893
|
+
},
|
|
1894
|
+
mtpLayers: 0
|
|
1895
|
+
});
|
|
1896
|
+
/**
|
|
1897
|
+
* A rough Ollama verdict from a download's size alone, for a model whose layer shapes are unknown: the compute
|
|
1898
|
+
* and margin terms on top of the file, with headroom for the context memory it cannot size. Planned on the machine
|
|
1899
|
+
* as Ollama uses it (ollamaHardware).
|
|
1900
|
+
*/
|
|
1901
|
+
function estimateFitFromSize(sizeBytes, machine, context) {
|
|
1902
|
+
const hardware = ollamaHardware(machine);
|
|
1903
|
+
const tokens = Math.max(1, Math.round(context));
|
|
1904
|
+
const { gpu: budgetBytes, ramPool, cpuOnly } = memoryBudgets(hardware);
|
|
1905
|
+
const needBytes = sizeBytes + computeBufferBytes({
|
|
1906
|
+
arch: sizeOnlyArch(tokens),
|
|
1907
|
+
weightsBytes: sizeBytes
|
|
1908
|
+
}, tokens, ollamaUbatch(tokens), { memoryKind: cpuOnly ? "cpu" : hardware.memoryKind });
|
|
1909
|
+
const marginBytes = fitMarginBytes(hardware);
|
|
1910
|
+
const plannedBytes = needBytes + marginBytes;
|
|
1911
|
+
const over = plannedBytes - budgetBytes;
|
|
1912
|
+
const base = {
|
|
1913
|
+
needBytes,
|
|
1914
|
+
budgetBytes,
|
|
1915
|
+
offloadBytes: Math.max(0, over),
|
|
1916
|
+
marginBytes,
|
|
1917
|
+
ramPoolBytes: ramPool,
|
|
1918
|
+
cpuOnly,
|
|
1919
|
+
context: tokens
|
|
1920
|
+
};
|
|
1921
|
+
if (over > 0) {
|
|
1922
|
+
const roomy = over <= ramPool - budgetBytes * .19999999999999996;
|
|
1923
|
+
const level = cpuOnly || over > sizeBytes || !roomy ? "too-large" : "tight";
|
|
1924
|
+
return {
|
|
1925
|
+
...base,
|
|
1926
|
+
level
|
|
1927
|
+
};
|
|
1928
|
+
}
|
|
1929
|
+
return {
|
|
1930
|
+
...base,
|
|
1931
|
+
level: plannedBytes > budgetBytes * SIZE_HEADROOM ? "tight" : "fits"
|
|
1932
|
+
};
|
|
1933
|
+
}
|
|
1934
|
+
const GIB = 1024 ** 3;
|
|
1935
|
+
const SOLD_SIZE_SLACK = .94;
|
|
1936
|
+
/**
|
|
1937
|
+
* A discrete machine whose GPU memory is unknown is planned, and so classed, as CPU only. Classed as Ollama, which
|
|
1938
|
+
* pulls the Curated picks, uses the machine (ollamaHardware), as the fit badges plan it.
|
|
1939
|
+
*/
|
|
1940
|
+
function hardwareClass(machine) {
|
|
1941
|
+
const hw = ollamaHardware(machine);
|
|
1942
|
+
if (hw.memoryKind === "unified") return {
|
|
1943
|
+
memoryKind: "unified",
|
|
1944
|
+
memoryBytes: hw.gpuMemoryBytes && hw.gpuMemoryBytes > 0 ? hw.gpuMemoryBytes : hw.totalMemoryBytes
|
|
1945
|
+
};
|
|
1946
|
+
if (hw.memoryKind === "discrete" && hw.gpuMemoryBytes) return {
|
|
1947
|
+
memoryKind: "discrete",
|
|
1948
|
+
memoryBytes: hw.gpuMemoryBytes
|
|
1949
|
+
};
|
|
1950
|
+
return {
|
|
1951
|
+
memoryKind: "cpu",
|
|
1952
|
+
memoryBytes: hw.totalMemoryBytes
|
|
1953
|
+
};
|
|
1954
|
+
}
|
|
1955
|
+
/** The largest tier with picks of this machine's class that its memory reaches; null when the list has none. */
|
|
1956
|
+
function curatedTier(tiers, hw) {
|
|
1957
|
+
const { memoryKind, memoryBytes } = hardwareClass(hw);
|
|
1958
|
+
let best = null;
|
|
1959
|
+
for (const tier of tiers) if (tier.picks.length > 0 && tier.memoryKind === memoryKind && memoryBytes >= tier.minGiB * GIB * SOLD_SIZE_SLACK && (!best || tier.minGiB > best.minGiB)) best = tier;
|
|
1960
|
+
return best;
|
|
1961
|
+
}
|
|
1962
|
+
//#endregion
|
|
1963
|
+
export { vramNeedsLlamaServer as S, curatedTier as _, MODEL_HOST_LIMITS as a, ollamaNumCtx as b, OLLAMA_SETTING_KEYS as c, OllamaSettingsSchema as d, PULL_JOB_ACTIVE_STATES as f, PullJobSchema as g, PullJobRequestSchema as h, MIN_CHAT_CONTEXT as i, OLLAMA_SKIPS_INTEL_IGPU as l, PullJobActionSchema as m, HostFactsSchema as n, MODEL_HOST_ROLES as o, PULL_JOB_FINAL_STATES as p, KV_CACHE_TYPES as r, ModelHostHelloSchema as s, CURATED_SLOTS as t, OLLAMA_WRITABLE_SETTING_KEYS as u, estimateFitFromSize as v, parseHubManifest as x, ollamaHardware as y };
|