-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfetch.js
More file actions
426 lines (403 loc) · 13.3 KB
/
Copy pathfetch.js
File metadata and controls
426 lines (403 loc) · 13.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
/**
* fetch.js
* Node.js utility to refresh Hugging Face model metadata and config specifications,
* merging them with consumer GPU specifications to rebuild data/cache.json.
*/
const fs = require('fs');
const path = require('path');
const https = require('https');
// Define output file location
const CACHE_DIR = path.join(__dirname, 'data');
const CACHE_FILE = path.join(CACHE_DIR, 'cache.json');
// Core models we track
const MODELS_TO_REFRESH = [
{
model_id: "meta-llama/Meta-Llama-3.1-8B-Instruct",
name: "Llama 3.1 8B Instruct",
developer: "Meta",
parameters: 8.03,
quality_score: 68.2,
description: "Meta's flagship lightweight model, optimized for multilingual dialogue and general tasks with 128k context.",
tags: ["chat", "coding", "multilingual", "rag"]
},
{
model_id: "meta-llama/Meta-Llama-3.1-70B-Instruct",
name: "Llama 3.1 70B Instruct",
developer: "Meta",
parameters: 70.6,
quality_score: 79.3,
description: "Meta's highly capable 70B model. Outstanding for complex reasoning, planning, and coding.",
tags: ["chat", "coding", "reasoning", "complex"]
},
{
model_id: "mistralai/Mistral-7B-Instruct-v0.3",
name: "Mistral 7B Instruct v0.3",
developer: "Mistral AI",
parameters: 7.25,
quality_score: 65.8,
description: "An updated version of the classic 7B model. Supports function calling, native vLLM and has an extended vocab.",
tags: ["chat", "coding", "function-calling"]
},
{
model_id: "google/gemma-2-9b-it",
name: "Gemma 2 9B IT",
developer: "Google",
parameters: 9.24,
quality_score: 71.5,
description: "Google's 9B model built on the Gemma 2 architecture. Highly efficient with quality matching larger models.",
tags: ["chat", "reasoning", "general"]
},
{
model_id: "google/gemma-2-27b-it",
name: "Gemma 2 27B IT",
developer: "Google",
parameters: 27.2,
quality_score: 77.2,
description: "A highly competitive 27B parameter model, providing near-frontier class intelligence on high-end consumer hardware.",
tags: ["chat", "reasoning", "coding"]
},
{
model_id: "microsoft/Phi-3.5-mini-instruct",
name: "Phi-3.5 Mini Instruct",
developer: "Microsoft",
parameters: 3.82,
quality_score: 61.8,
description: "A lightweight, state-of-the-art open model built on Phi-3 datasets. Excels in reasoning and math.",
tags: ["chat", "reasoning", "math", "fast"]
},
{
model_id: "microsoft/Phi-3-medium-128k-instruct",
name: "Phi-3 Medium Instruct (128k)",
developer: "Microsoft",
parameters: 14.0,
quality_score: 69.1,
description: "A 14B parameter model with huge 128k context length support, delivering excellent RAG and summarization performance.",
tags: ["chat", "rag", "long-context"]
},
{
model_id: "Qwen/Qwen2.5-7B-Instruct",
name: "Qwen 2.5 7B Instruct",
developer: "Alibaba",
parameters: 7.62,
quality_score: 70.8,
description: "Alibaba's highly acclaimed 7B model. Incredible multilingual and coding capabilities for its size.",
tags: ["chat", "coding", "multilingual", "fast"]
},
{
model_id: "Qwen/Qwen2.5-72B-Instruct",
name: "Qwen 2.5 72B Instruct",
developer: "Alibaba",
parameters: 72.7,
quality_score: 81.2,
description: "Top-tier open source model. Matches closed models on complex coding tasks, maths, and multilingual queries.",
tags: ["coding", "reasoning", "complex", "multilingual"]
},
{
model_id: "CohereForAI/c4ai-command-r-plus",
name: "Command R+",
developer: "Cohere",
parameters: 104.0,
quality_score: 75.5,
description: "A massive 104B model optimized for RAG, tool use, and enterprise tasks. Huge multi-step tool agent capabilities.",
tags: ["rag", "agents", "tool-use", "enterprise"]
}
];
// GPU configuration template (re-merged upon rebuild)
const GPU_SPECIFICATIONS = [
{
id: "rtx_5090",
name: "NVIDIA GeForce RTX 5090",
vram: 32,
bandwidth: 1792,
type: "gpu",
description: "Next-gen flagship consumer card. Outstanding bandwidth and 32GB VRAM capacity."
},
{
id: "rtx_4090",
name: "NVIDIA GeForce RTX 4090",
vram: 24,
bandwidth: 1008,
type: "gpu",
description: "Current flagship consumer GPU. Perfect for 8B models and 70B offloaded configurations."
},
{
id: "rtx_4080s",
name: "NVIDIA GeForce RTX 4080 Super",
vram: 16,
bandwidth: 736,
type: "gpu",
description: "High-end consumer card. Fast, but bound by 16GB VRAM capacity."
},
{
id: "rtx_4070ti_super",
name: "NVIDIA GeForce RTX 4070 Ti Super",
vram: 16,
bandwidth: 672,
type: "gpu",
description: "Excellent price-to-VRAM value with 16GB high-bandwidth VRAM."
},
{
id: "rtx_4070s",
name: "NVIDIA GeForce RTX 4070 Super",
vram: 12,
bandwidth: 504,
type: "gpu",
description: "Highly popular mid-range card. Comfortable for 7B/8B Q4 quantizations."
},
{
id: "rtx_4060ti_16gb",
name: "NVIDIA GeForce RTX 4060 Ti 16GB",
vram: 16,
bandwidth: 288,
type: "gpu",
description: "Affordable large capacity VRAM (16GB) but bottlenecked by 128-bit memory bus bandwidth."
},
{
id: "rtx_3090",
name: "NVIDIA GeForce RTX 3090",
vram: 24,
bandwidth: 936,
type: "gpu",
description: "Legacy king of consumer VRAM. 24GB high bandwidth makes it perfect for local LLMs."
},
{
id: "rtx_3060_12gb",
name: "NVIDIA GeForce RTX 3060 12GB",
vram: 12,
bandwidth: 360,
type: "gpu",
description: "Budget choice. Good memory capacity and decent bus width."
},
{
id: "nvidia_a100",
name: "NVIDIA A100 Tensor Core 80GB",
vram: 80,
bandwidth: 2039,
type: "gpu",
description: "Enterprise-class GPU. Elite bandwidth and 80GB HBM2e memory."
},
{
id: "nvidia_h100",
name: "NVIDIA H100 Tensor Core 80GB SXM",
vram: 80,
bandwidth: 3350,
type: "gpu",
description: "State-of-the-art enterprise graphics. Astronomical memory bandwidth."
},
{
id: "dual_rtx_3090",
name: "Dual NVIDIA GeForce RTX 3090",
vram: 48,
bandwidth: 1872,
type: "multi_gpu",
description: "Dual workstation setup. Combines VRAM to run 70B models at full local speed."
},
{
id: "dual_rtx_4090",
name: "Dual NVIDIA GeForce RTX 4090",
vram: 48,
bandwidth: 2016,
type: "multi_gpu",
description: "Elite multi-GPU consumer workstation. Phenomenal speed and capacity."
},
{
id: "amd_7900xtx",
name: "AMD Radeon RX 7900 XTX",
vram: 24,
bandwidth: 960,
type: "gpu",
description: "AMD flagship gaming card. Outstanding 24GB VRAM and high memory bandwidth."
},
{
id: "amd_7900xt",
name: "AMD Radeon RX 7900 XT",
vram: 20,
bandwidth: 800,
type: "gpu",
description: "Strong high-end AMD card. Generous 20GB VRAM pool."
},
{
id: "amd_7800xt",
name: "AMD Radeon RX 7800 XT",
vram: 16,
bandwidth: 624,
type: "gpu",
description: "Popular mid-range AMD card with solid 16GB VRAM specs."
},
{
id: "mac_m2_ultra",
name: "Apple M2 Ultra (192GB Unified)",
vram: 144,
bandwidth: 800,
type: "mac",
description: "Unified Architecture. Allows allocating up to 144GB of unified memory as VRAM, running 70B+ models in FP16 locally."
},
{
id: "mac_m3_max",
name: "Apple M3 Max (128GB Unified)",
vram: 96,
bandwidth: 400,
type: "mac",
description: "High-end MacBook Pro spec. Up to 96GB available for model weights with high bandwidth."
},
{
id: "mac_m2_max",
name: "Apple M2 Max (96GB Unified)",
vram: 72,
bandwidth: 400,
type: "mac",
description: "Unified memory architecture. Outstanding balance for 30B class models."
},
{
id: "mac_m3_pro",
name: "Apple M3 Pro (36GB Unified)",
vram: 27,
bandwidth: 150,
type: "mac",
description: "Mid-tier Unified Memory. Decent speed, perfect for 8B models at high precision."
},
{
id: "intel_a770",
name: "Intel Arc A770 16GB",
vram: 16,
bandwidth: 560,
type: "gpu",
description: "Intel flagship GPU. Great budget option for a spacious 16GB VRAM buffer."
},
{
id: "generic_cpu_ddr5",
name: "System CPU-Only (DDR5 Dual-Channel)",
vram: 0,
bandwidth: 80,
type: "cpu",
description: "CPU execution bound by standard DDR5 speed. Extremely slow but limitless size."
},
{
id: "generic_cpu_quad",
name: "System CPU-Only (DDR5 Quad-Channel)",
vram: 0,
bandwidth: 150,
type: "cpu",
description: "Workstation CPU execution. Quad-channel bus gives moderate speeds for CPU inference."
},
{
id: "custom",
name: "Custom Hardware Configuration",
vram: 24,
bandwidth: 1008,
type: "gpu",
description: "Configure your own active VRAM limits and bus performance."
}
];
// Helper to fetch content over HTTPS
function fetchUrl(url) {
return new Promise((resolve, reject) => {
const options = {
headers: {
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) LocalModelOptimizer/1.0'
}
};
https.get(url, options, (res) => {
if (res.statusCode === 301 || res.statusCode === 302) {
// Handle redirect
return fetchUrl(res.headers.location).then(resolve).catch(reject);
}
if (res.statusCode !== 200) {
reject(new Error(`Failed with status: ${res.statusCode} at URL: ${url}`));
return;
}
let body = '';
res.on('data', (chunk) => body += chunk);
res.on('end', () => resolve(body));
}).on('error', reject);
});
}
// Fetch JSON wrapper
async function fetchJson(url) {
const content = await fetchUrl(url);
return JSON.parse(content);
}
// Core execution
async function run() {
console.log("⚡ Starting Hugging Face Model Sync...");
console.log(`📡 Fetching metadata for ${MODELS_TO_REFRESH.length} tracking models...`);
const updatedModels = [];
for (const template of MODELS_TO_REFRESH) {
try {
console.log(`\n🔍 Fetching: ${template.model_id}`);
// 1. Fetch HF Model details (downloads etc.)
const apiInfo = await fetchJson(`https://huggingface.co/api/models/${template.model_id}`);
const downloads = apiInfo.downloads || 0;
console.log(` └─ Downloads: ${downloads.toLocaleString()}`);
// 2. Fetch config.json to get exact layers/heads/dimensions
const configUrl = `https://huggingface.co/${template.model_id}/raw/main/config.json`;
const config = await fetchJson(configUrl);
// Normalize different config patterns in HF
const num_layers = config.num_hidden_layers || config.num_layers || config.n_layer || 32;
const hidden_size = config.hidden_size || config.n_embd || 4096;
const num_attn_heads = config.num_attention_heads || config.n_head || 32;
const num_kv_heads = config.num_key_value_heads || num_attn_heads; // Default to MHA if GQA is not set
const vocab_size = config.vocab_size || 32000;
console.log(` └─ Architecture: L:${num_layers} | H:${hidden_size} | A:${num_attn_heads} | KV:${num_kv_heads}`);
// Push sanitized results
updatedModels.push({
model_id: template.model_id,
name: template.name,
developer: template.developer,
parameters: template.parameters,
base_model_id: template.model_id.replace('-Instruct', '').replace('-it', ''),
quality_score: template.quality_score,
downloads: downloads,
description: template.description,
config: {
num_layers,
hidden_size,
num_kv_heads,
num_attn_heads,
vocab_size
},
tags: template.tags
});
// Simple rate limiting spacing
await new Promise(r => setTimeout(r, 600));
} catch (error) {
console.warn(` ⚠️ Error fetching ${template.model_id}: ${error.message}`);
console.log(` ↳ Keeping default specifications for ${template.name}`);
// Add default specifications if API fetch failed
updatedModels.push({
model_id: template.model_id,
name: template.name,
developer: template.developer,
parameters: template.parameters,
base_model_id: template.model_id.replace('-Instruct', '').replace('-it', ''),
quality_score: template.quality_score,
description: template.description,
config: {
num_layers: template.model_id.includes('70B') || template.model_id.includes('72B') ? 80 : 32,
hidden_size: template.model_id.includes('70B') || template.model_id.includes('72B') ? 8192 : 4096,
num_kv_heads: 8,
num_attn_heads: template.model_id.includes('70B') || template.model_id.includes('72B') ? 64 : 32,
vocab_size: 128000
},
tags: template.tags
});
}
}
// 3. Write cache.json file
const cacheData = {
generated_at: new Date().toISOString(),
models: updatedModels,
gpus: GPU_SPECIFICATIONS
};
try {
if (!fs.existsSync(CACHE_DIR)){
fs.mkdirSync(CACHE_DIR, { recursive: true });
}
fs.writeFileSync(CACHE_FILE, JSON.stringify(cacheData, null, 2), 'utf-8');
console.log(`\n🎉 Success! Successfully updated ${CACHE_FILE}`);
console.log(`⏰ Saved at: ${cacheData.generated_at}`);
} catch (err) {
console.error(`❌ Failed to write cache.json: ${err.message}`);
}
}
run();