@simplexai/localmodels-win32-x64 0.1.0-dev.103 → 0.1.0-dev.104
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/LICENSE +201 -0
- package/{modules/simplex_localmodels-0.1.0.dev103.dist-info/licenses/NOTICE → NOTICE} +42 -13
- package/README.md +10 -0
- package/bootstrap.identity +1 -1
- package/bootstrap.sha256 +126 -127
- package/modules/localmodels/__init__.py +1 -1
- package/modules/localmodels/catalog.json +130 -127
- package/modules/localmodels/catalog.py +7 -3
- package/modules/localmodels/catalog_recipes.py +3 -3
- package/modules/localmodels/cli_parser.py +3 -3
- package/modules/localmodels/component.py +1 -1
- package/modules/localmodels/console.py +1 -1
- package/modules/localmodels/context_policy.py +6 -5
- package/modules/localmodels/debug_cli.py +0 -12
- package/modules/localmodels/debug_mode.py +0 -6
- package/modules/localmodels/decode_calibration.json +3 -4
- package/modules/localmodels/decode_calibration.py +5 -2
- package/modules/localmodels/deployment_lifecycle.py +1 -1
- package/modules/localmodels/download-mirrors.json +1 -1
- package/modules/localmodels/engine_adapters/base.py +11 -1
- package/modules/localmodels/engine_adapters/strata_poly.py +65 -3
- package/modules/localmodels/engine_adapters/suite_plan.py +57 -20
- package/modules/localmodels/engines-b11583.json +6 -26
- package/modules/localmodels/engines-b12588-mix-c0c3de8.json +3 -15
- package/modules/localmodels/engines-b12757-mix-ef2df21.json +3 -15
- package/modules/localmodels/engines-prism-b12178-03ec600.json +3 -15
- package/modules/localmodels/engines-speechcpp-v0.11.3.json +4 -20
- package/modules/localmodels/engines-strata-0.1.47.json +1 -5
- package/modules/localmodels/engines-strata-0.1.49.2.json +1 -5
- package/modules/localmodels/engines-strata-0.1.59.1.json +1 -5
- package/modules/localmodels/engines-strata-poly-0.2.20-poly.1.json +6 -30
- package/modules/localmodels/engines-strata-poly-0.2.20-poly.9.json +129 -0
- package/modules/localmodels/engines-whisper-b5454.json +6 -30
- package/modules/localmodels/engines.json +13 -61
- package/modules/localmodels/estimator.py +10 -5
- package/modules/localmodels/gpu_specs.py +1 -1
- package/modules/localmodels/hosts.py +12 -16
- package/modules/localmodels/kokoro-tts-0.6.1.txt +1 -1
- package/modules/localmodels/library_elastic.py +135 -6
- package/modules/localmodels/library_kept.py +9 -1
- package/modules/localmodels/library_model.py +28 -1
- package/modules/localmodels/library_poly.py +109 -11
- package/modules/localmodels/library_pricing.py +12 -3
- package/modules/localmodels/library_serve.py +134 -67
- package/modules/localmodels/library_smoke.py +63 -5
- package/modules/localmodels/library_state.py +3 -2
- package/modules/localmodels/library_status.py +8 -1
- package/modules/localmodels/llm_rank.py +13 -8
- package/modules/localmodels/metal.py +1 -2
- package/modules/localmodels/plan_envelope.py +29 -11
- package/modules/localmodels/planning/budget.py +14 -12
- package/modules/localmodels/planning/memory_pools.py +7 -1
- package/modules/localmodels/privacy_acceptance.py +6 -5
- package/modules/localmodels/py.typed +0 -0
- package/modules/localmodels/quant_formats.py +1 -1
- package/modules/localmodels/recommend_cli.py +1 -1
- package/modules/localmodels/remote_ops_launchd.py +8 -1
- package/modules/localmodels/runtime_process.py +1 -1
- package/modules/localmodels/service_deployment.py +2 -4
- package/modules/localmodels/service_probe.py +59 -13
- package/modules/localmodels/setup_inspection.py +72 -70
- package/modules/localmodels/setup_text.py +7 -56
- package/modules/localmodels/sidecar_downloads.py +34 -0
- package/modules/localmodels/sidecar_http.py +61 -5
- package/modules/localmodels/sidecar_state.py +52 -2
- package/modules/localmodels/speech_admission.py +20 -4
- package/modules/localmodels/speech_catalog.py +23 -0
- package/modules/localmodels/speech_cli.py +10 -2
- package/modules/localmodels/speech_jobs.py +42 -17
- package/modules/localmodels/speech_server.py +182 -81
- package/modules/localmodels/speech_state.py +4 -1
- package/modules/localmodels/speech_workers.py +11 -0
- package/modules/localmodels/stack.py +1 -1
- package/modules/localmodels/stack_args.py +6 -6
- package/modules/localmodels/stack_auto.py +1 -1
- package/modules/localmodels/stack_aux_gpu.py +1 -1
- package/modules/localmodels/stack_cleanup.py +21 -18
- package/modules/localmodels/stack_cli.py +6 -2
- package/modules/localmodels/stack_compose.py +11 -4
- package/modules/localmodels/stack_debug.py +1 -2
- package/modules/localmodels/stack_decision.py +4 -4
- package/modules/localmodels/stack_doctor.py +2 -2
- package/modules/localmodels/stack_events.py +1 -1
- package/modules/localmodels/stack_gpu_memory.py +1 -1
- package/modules/localmodels/stack_hardware.py +3 -3
- package/modules/localmodels/stack_mcp.py +1 -2
- package/modules/localmodels/stack_picks.py +1 -1
- package/modules/localmodels/stack_plan.py +9 -9
- package/modules/localmodels/stack_ports.py +31 -4
- package/modules/localmodels/stack_rollback.py +1 -1
- package/modules/localmodels/stack_run.py +1 -1
- package/modules/localmodels/stack_suite.py +61 -12
- package/modules/localmodels/stack_view_agent.py +1 -1
- package/modules/localmodels/stack_view_serve.py +0 -2
- package/modules/localmodels/stack_view_words.py +2 -2
- package/modules/localmodels/stack_warm.py +2 -2
- package/modules/localmodels/stack_whatif.py +524 -41
- package/modules/localmodels/stack_whatif_html.py +903 -0
- package/modules/localmodels/startlux-decide-83fe6c7d.txt +2 -2
- package/modules/localmodels/{strata-poly-serve-0.2.20-poly.7.txt → strata-poly-serve-0.2.20-poly.9.txt} +1 -1
- package/modules/localmodels/strata_poly_server.py +114 -3
- package/modules/localmodels/suite.py +137 -5
- package/modules/localmodels/tts_admission.py +2 -17
- package/modules/localmodels/tts_catalog.py +29 -1
- package/modules/localmodels/tts_cli.py +23 -4
- package/modules/localmodels/tts_http.py +10 -4
- package/modules/localmodels/tts_jobs.py +49 -19
- package/modules/localmodels/tts_server.py +1 -1
- package/modules/localmodels/tts_sidecar.py +66 -28
- package/modules/localmodels/tts_state.py +7 -2
- package/modules/localmodels/vision.py +5 -3
- package/modules/localmodels/web/view/ASSET-SOURCES.md +4 -7
- package/modules/localmodels/web/view/view.css +0 -1
- package/modules/localmodels/web/view/view.js +2 -5
- package/modules/localmodels/web/whatif/app.js +730 -0
- package/modules/localmodels/web/whatif/page.html +1172 -0
- package/modules/localmodels/web/whatif/sim.js +303 -0
- package/modules/localmodels/windows_job.py +179 -11
- package/modules/simplex_localmodels-0.1.0.dev104.dist-info/METADATA +14 -0
- package/modules/{simplex_localmodels-0.1.0.dev103.dist-info → simplex_localmodels-0.1.0.dev104.dist-info}/RECORD +118 -114
- package/modules/simplex_localmodels-0.1.0.dev104.dist-info/licenses/LICENSE +201 -0
- package/modules/simplex_localmodels-0.1.0.dev104.dist-info/licenses/NOTICE +126 -0
- package/package.json +11 -2
- package/tool.json +1 -1
- package/modules/localmodels/engines-strata-poly-0.2.20-poly.7.json +0 -94
- package/modules/localmodels/fixtures/stack-research-demo-plan.json +0 -1059
- package/modules/localmodels/stack_research.py +0 -716
- package/modules/localmodels/stack_research_demo.py +0 -125
- package/modules/localmodels/stack_research_plan.py +0 -146
- package/modules/localmodels/web/index.html +0 -2605
- package/modules/localmodels/web/sizecalc/app.js +0 -1306
- package/modules/localmodels/web/sizecalc/calc.js +0 -269
- package/modules/localmodels/web/sizecalc/page.html +0 -520
- package/modules/localmodels/web/view/logo-claude.svg +0 -3
- package/modules/localmodels/web/view/logo-codex.png +0 -0
- package/modules/simplex_localmodels-0.1.0.dev103.dist-info/METADATA +0 -9
- /package/modules/{simplex_localmodels-0.1.0.dev103.dist-info → simplex_localmodels-0.1.0.dev104.dist-info}/WHEEL +0 -0
- /package/modules/{simplex_localmodels-0.1.0.dev103.dist-info → simplex_localmodels-0.1.0.dev104.dist-info}/entry_points.txt +0 -0
- /package/modules/{simplex_localmodels-0.1.0.dev103.dist-info → simplex_localmodels-0.1.0.dev104.dist-info}/licenses/localmodels/HERMES-LICENSE +0 -0
|
@@ -1,1306 +0,0 @@
|
|
|
1
|
-
// The page: reads the controls, prices them with SizeCalc (calc.js) and draws the answer.
|
|
2
|
-
const ATT_ZH = { full: "全注意力 GQA", swa: "滑窗混合", hybrid: "线性 / SSM 混合", mla: "MLA 潜向量" };
|
|
3
|
-
const EXACT_ZH = {
|
|
4
|
-
"active parameters cannot exceed total parameters": "激活参数量不能大于总参数量",
|
|
5
|
-
"active parameters must be positive and at most the total": "激活参数量必须大于 0 且不能大于总参数量",
|
|
6
|
-
"parameters must be greater than zero": "参数量必须大于 0",
|
|
7
|
-
"weight file size must be greater than zero": "权重文件大小必须大于 0",
|
|
8
|
-
"parameters and file size must be positive": "参数量和权重文件大小必须大于 0",
|
|
9
|
-
"give two of params, format and file size": "请提供总参数、量化格式和权重文件大小中的至少两项",
|
|
10
|
-
"context must be at least 1 token": "上下文长度至少为 1 token",
|
|
11
|
-
"slots must be at least 1": "并发槽位数至少为 1",
|
|
12
|
-
"exl bits per weight must be between 1 and 16": "EXL3 自定义位数需在 1–16 bpw 之间",
|
|
13
|
-
};
|
|
14
|
-
|
|
15
|
-
function zhMsg(msg) {
|
|
16
|
-
if (msg == null) return "";
|
|
17
|
-
const s = String(msg).trim();
|
|
18
|
-
if (!s) return "";
|
|
19
|
-
if (EXACT_ZH[s]) return EXACT_ZH[s];
|
|
20
|
-
if (s.startsWith("unknown format: ")) return `未知格式:${s.slice("unknown format: ".length)}`;
|
|
21
|
-
if (s.startsWith("unknown format ")) return `未知格式:${s.slice("unknown format ".length)}`;
|
|
22
|
-
if (s.startsWith("unknown KV cache type: ")) return `未知 KV 缓存类型:${s.slice("unknown KV cache type: ".length)}`;
|
|
23
|
-
let m = s.match(/^(.+) bits per weight is outside 1-32$/);
|
|
24
|
-
if (m) return `每权重位数 ${m[1]} 超出 1–32 范围`;
|
|
25
|
-
m = s.match(/^guessed for (\S+) attention$/);
|
|
26
|
-
if (m) return `按${ATT_ZH[m[1]] || m[1]}注意力参数量估算`;
|
|
27
|
-
m = s.match(/^([\d.]+[A-Za-z]*) parameters inferred from the file size at ([\d.]+) bpw$/);
|
|
28
|
-
if (m) return `按 ${m[2]} bpw 从权重文件大小反推出总参数量约为 ${m[1]}`;
|
|
29
|
-
m = s.match(/^([\d.]+) bits per weight; the nearest listed format is (.+)$/);
|
|
30
|
-
if (m) return `按文件大小折合每权重 ${m[1]} bits;表中最接近的格式是 ${m[2]}`;
|
|
31
|
-
m = s.match(/^the file holds ([\d.]+) bits per weight, (.+?) is typically ([\d.]+): check the parameter count \(embeddings, vision tower, MTP heads\)$/);
|
|
32
|
-
if (m) return `该文件每权重占 ${m[1]} bits,而 ${m[2]} 通常约为 ${m[3]} bpw:请核对总参数量(如嵌入层、视觉塔、MTP 头)`;
|
|
33
|
-
if (s.startsWith("EXL bit rates leave out the 16-bit embeddings and 6-bit head")) {
|
|
34
|
-
return "EXL 标称位数不含 16-bit 嵌入层与 6-bit 输出头,实际权重文件会比估算更大;已知真实大小时可填入「权重文件大小」。";
|
|
35
|
-
}
|
|
36
|
-
m = s.match(/^small model: embeddings are a large share, so real files run above the table \(([^)]+)\); give --file-size when known$/);
|
|
37
|
-
if (m) {
|
|
38
|
-
const ex = m[1].replace(" holds ", " 实测为 ").replace(" bits per weight", " bpw");
|
|
39
|
-
return `小模型嵌入层占比高,实际文件通常会高于表内平均位数(例如 ${ex});已知真实大小时可直接填入「权重文件大小」。`;
|
|
40
|
-
}
|
|
41
|
-
return s;
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
if (typeof document !== "undefined") (() => {
|
|
45
|
-
const calc = SizeCalc(SIZECALC_DATA);
|
|
46
|
-
const D = SIZECALC_DATA;
|
|
47
|
-
const GiB = 1073741824;
|
|
48
|
-
const $ = (id) => document.getElementById(id);
|
|
49
|
-
const esc = (s) => String(s).replace(/[&<>"]/g, (c) => ({ "&": "&", "<": "<", ">": ">", '"': """ })[c]);
|
|
50
|
-
const setClass = (el, cls, on) => { if (el?.classList) el.classList[on ? "add" : "remove"](cls); };
|
|
51
|
-
const announce = (msg) => {
|
|
52
|
-
const live = $("live-status");
|
|
53
|
-
if (!live) return;
|
|
54
|
-
live.textContent = "";
|
|
55
|
-
live.textContent = msg;
|
|
56
|
-
};
|
|
57
|
-
|
|
58
|
-
const TIER_ZH = {
|
|
59
|
-
phone: ["手机", "8–16 GB;安卓单个 App 上限 5–10 GiB"],
|
|
60
|
-
laptop: ["轻薄本 / 小 Mac", "16–36 GB 统一内存"],
|
|
61
|
-
"pc-gpu": ["家用 N 卡", "8–32 GB 显存,可借系统内存卸载"],
|
|
62
|
-
"big-unified": ["大内存一体机", "64–128 GB:Mac Max、DGX Spark、Ryzen AI Max"],
|
|
63
|
-
workstation: ["工作站", "48–96 GB 专业卡,Mac Studio Ultra 256–512 GB"],
|
|
64
|
-
"server-gpu": ["单张服务器卡", "80–192 GB HBM"],
|
|
65
|
-
node: ["8 卡服务器", "640–1536 GB HBM,张量并行"],
|
|
66
|
-
};
|
|
67
|
-
const VERDICT_ZH = { fits: "放得下", offload: "卸载到内存", no: "放不下" };
|
|
68
|
-
const SHORT = {
|
|
69
|
-
"iphone-8": "iPhone 8G", "iphone-12": "iPhone 12G", "android-12": "安卓 12G", "android-16": "安卓 16G",
|
|
70
|
-
"mac-16": "Air 16G", "mac-24": "mini 24G", "mac-36": "MBP 36G", rtx4060: "4060", rtx3060: "3060",
|
|
71
|
-
rtx4060ti: "4060Ti", rtx5070ti: "5070Ti", rtx3090: "3090", rtx4090: "4090", rtx5090: "5090",
|
|
72
|
-
"mac-64": "Mac 64G", "mac-128": "Mac 128G", "dgx-spark": "Spark", "ryzen-ai-max": "AI Max",
|
|
73
|
-
rtx6000ada: "6000Ada", rtxpro6000: "PRO6000", "mac-256": "Ultra 256G", "mac-512": "Ultra 512G",
|
|
74
|
-
a100: "A100", h100: "H100", h200: "H200", b200: "B200", mi300x: "MI300X",
|
|
75
|
-
"8xh100": "8×H100", "8xh200": "8×H200", "8xb200": "8×B200", "8xmi300x": "8×MI300X",
|
|
76
|
-
};
|
|
77
|
-
const FAMILY_ZH = {
|
|
78
|
-
float: "浮点原版", gguf: "GGUF(llama.cpp)", mlx: "MLX(Apple)", awq: "AWQ", gptq: "GPTQ",
|
|
79
|
-
fp8: "FP8", nvfp4: "NVFP4", mxfp4: "MXFP4", exl: "EXL2 / EXL3", bnb: "bitsandbytes",
|
|
80
|
-
};
|
|
81
|
-
const SUPPORT_ZH = {
|
|
82
|
-
native: ["原生", "该设备支持此格式的原生计算 kernel,可直接运行"],
|
|
83
|
-
fallback: ["回退", "可运行但走回退 / weight-only 路径(如 Ampere 卡运行 FP8 Marlin)"],
|
|
84
|
-
convert: ["需转换", "该设备不直接支持此格式,按同等体积换算为 GGUF / MLX 后估算"],
|
|
85
|
-
};
|
|
86
|
-
const BASIS_ZH = {
|
|
87
|
-
file: ["实测文件", "llama.cpp README 中 Llama-3.1-8B 整文件实测平均 bpw(含高精输出层与嵌入)"],
|
|
88
|
-
block: ["块公式", "按 ggml / 分组块结构推算,整文件通常高 0.2–0.8 bpw"],
|
|
89
|
-
derived: ["推导", "按张量量化结构加 16-bit 嵌入与输出头,针对 30B 级模型推算"],
|
|
90
|
-
exact: ["精确", "未量化浮点格式的名义精确位宽"],
|
|
91
|
-
target: ["目标值", "可变码率格式的目标平均位数,不含 16-bit 嵌入层"],
|
|
92
|
-
};
|
|
93
|
-
const FMT_NOTE_ZH = {
|
|
94
|
-
"the usual released checkpoint": "主流开源发布的原始权重格式",
|
|
95
|
-
"E4M3 + fp32 block scales, 16-bit embeddings; Ada/Hopper+": "E4M3 + fp32 分块缩放,16-bit 嵌入;需 Ada / Hopper 及以上",
|
|
96
|
-
"32 int8 + f16 scale per block": "每块 32 个 int8 + f16 缩放因子",
|
|
97
|
-
"group 64, scale + bias; embeddings quantized too": "每组 64 权重,含缩放与偏置;嵌入层也量化",
|
|
98
|
-
"the common default": "最常用的默认平衡量化",
|
|
99
|
-
"also the usual QAT release format": "也是常见的量化感知训练(QAT)发布格式",
|
|
100
|
-
"FP4 + E4M3 scale per 16, 16-bit embeddings; Blackwell": "每 16 权重配 E4M3 缩放,16-bit 嵌入;Blackwell 原生",
|
|
101
|
-
"int4 g128 is 4.16; 16-bit embeddings: 8B 5.7, 70B 4.5": "int4 (g128) 纯块 4.16 bpw;含 16-bit 嵌入:8B 约 5.7、70B 约 4.5",
|
|
102
|
-
"bitsandbytes 4-bit 4.5 (4.127 double-quant), bf16 embeddings": "bitsandbytes 4-bit 约 4.5(双重量化 4.127),bf16 嵌入",
|
|
103
|
-
"gpt-oss-120b: MXFP4 experts, Q8_0 elsewhere": "gpt-oss-120b 实测:专家层 MXFP4,其余层 Q8_0",
|
|
104
|
-
"IQ1/IQ2 keep the output at Q5_K": "IQ1 / IQ2 会将输出层保留在 Q5_K",
|
|
105
|
-
"ExLlama: embeddings stay 16-bit": "ExLlama 可变码率,嵌入层保留 16-bit",
|
|
106
|
-
};
|
|
107
|
-
const PRESET_GROUPS = [
|
|
108
|
-
{ id: "light", label: "轻量 3–8B", match: (p) => p.params < 15 },
|
|
109
|
-
{ id: "main", label: "主力 20–70B", match: (p) => p.params >= 15 && p.params < 100 },
|
|
110
|
-
{ id: "mega", label: "超大 MoE 120B+", match: (p) => p.params >= 100 },
|
|
111
|
-
];
|
|
112
|
-
const DEVICE_META = Object.fromEntries(D.devices.map((x) => [x.id, x]));
|
|
113
|
-
const CONTEXTS = [4096, 8192, 16384, 32768, 65536, 131072, 262144, 524288, 1048576];
|
|
114
|
-
|
|
115
|
-
// Public model shapes from sizecalc.EXAMPLES; the CLI fills catalog sizes from catalog.json.
|
|
116
|
-
const PRESETS = D.examples.map((x) => ({
|
|
117
|
-
id: x.id, name: x.name, params: x.params / 1e9, active: x.active ? x.active / 1e9 : null,
|
|
118
|
-
attention: x.attention, kv: x.kv_per_token / 1024, quant: x.quant,
|
|
119
|
-
file: x.file_bytes ? +(x.file_bytes / 1e9).toFixed(3) : null,
|
|
120
|
-
}));
|
|
121
|
-
|
|
122
|
-
const REFS = [
|
|
123
|
-
["llama.cpp quantize README:Llama-3.1-8B 各量化的整文件 bpw", "https://github.com/ggml-org/llama.cpp/blob/master/tools/quantize/README.md"],
|
|
124
|
-
["llama.cpp --fit / llama-fit-params:空跑真实分配,每卡留 1 GiB,MoE 专家按层溢出到 CPU", "https://github.com/ggml-org/llama.cpp/tree/master/tools/fit-params"],
|
|
125
|
-
["gpustack/gguf-parser-go:只读 GGUF 头,逐张量求和估 RAM / VRAM(MIT)", "https://github.com/gpustack/gguf-parser-go"],
|
|
126
|
-
["AlexsJones/llmfit:本机探测 + 模型库,MoE 卸载模式与 0.60 / 0.85 / 0.98 适配阈值(MIT)", "https://github.com/AlexsJones/llmfit"],
|
|
127
|
-
["fitllm-engine:按 revision 固定的真实 GGUF 字节数(MIT)", "https://github.com/click6067-ship-it/fitllm-engine"],
|
|
128
|
-
["Hugging Face accelerate estimate-memory:只算加载权重", "https://github.com/huggingface/accelerate/blob/main/src/accelerate/commands/estimate.py"],
|
|
129
|
-
["NyxKrage LLM-Model-VRAM-Calculator:GGUF / EXL2 + 上下文(bpw 表已过时)", "https://huggingface.co/spaces/NyxKrage/LLM-Model-VRAM-Calculator"],
|
|
130
|
-
["vLLM gpu_worker:启动时实测激活峰值与 CUDA graph,再分 KV 池", "https://github.com/vllm-project/vllm/blob/main/vllm/v1/worker/gpu_worker.py"],
|
|
131
|
-
["Android 17 Memory Limiter:各 RAM 档单个 App 的内存上限", "https://source.android.com/docs/core/perf/memory-limiter"],
|
|
132
|
-
];
|
|
133
|
-
|
|
134
|
-
// ── controls ──────────────────────────────────────────────────────
|
|
135
|
-
function fillControls() {
|
|
136
|
-
const sel = $("quant");
|
|
137
|
-
const byFam = {};
|
|
138
|
-
for (const f of D.formats) (byFam[f.family] = byFam[f.family] || []).push(f);
|
|
139
|
-
sel.innerHTML = Object.entries(byFam)
|
|
140
|
-
.map(([fam, list]) => `<optgroup label="${esc(FAMILY_ZH[fam] || fam)}">${list
|
|
141
|
-
.map((f) => `<option value="${esc(f.name)}">${esc(f.name)} · ${f.bits} bpw</option>`).join("")}</optgroup>`)
|
|
142
|
-
.join("") + `<optgroup label="其它"><option value="custom-exl">EXL3 / EXL2,自定义 bpw</option><option value="custom">其它,自定义 bpw</option></optgroup>`;
|
|
143
|
-
sel.value = "Q4_K_M";
|
|
144
|
-
$("presets").innerHTML = PRESET_GROUPS.map((grp) => {
|
|
145
|
-
const items = PRESETS.filter(grp.match);
|
|
146
|
-
if (!items.length) return "";
|
|
147
|
-
return `<div class="preset-group" data-group="${grp.id}">
|
|
148
|
-
<span class="preset-glabel">${esc(grp.label)}</span>
|
|
149
|
-
<div class="preset-chips">${items.map((p) => `<button type="button" data-id="${p.id}" aria-pressed="false">${esc(p.name)}</button>`).join("")}</div>
|
|
150
|
-
</div>`;
|
|
151
|
-
}).join("");
|
|
152
|
-
$("presets").addEventListener("click", (e) => {
|
|
153
|
-
const b = e.target.closest?.("button");
|
|
154
|
-
if (b) applyPreset(PRESETS.find((p) => p.id === b.dataset.id));
|
|
155
|
-
});
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
// The preset that filled the controls, and which of its overrides (file size, KV per token)
|
|
159
|
-
// still stand: changing the shape or the format drops an override the new shape would contradict.
|
|
160
|
-
let presetId = null;
|
|
161
|
-
const fromPreset = { filesize: false, kvpt: false };
|
|
162
|
-
function setPresetControls(p) {
|
|
163
|
-
presetId = p.id;
|
|
164
|
-
fromPreset.filesize = Boolean(p.file);
|
|
165
|
-
fromPreset.kvpt = true;
|
|
166
|
-
$("k-moe").checked = Boolean(p.active);
|
|
167
|
-
$("k-dense").checked = !p.active;
|
|
168
|
-
$("params").value = p.params;
|
|
169
|
-
if (p.active) $("active").value = p.active;
|
|
170
|
-
$("attention").value = p.attention;
|
|
171
|
-
$("kvpt").value = p.kv;
|
|
172
|
-
$("quant").value = p.quant;
|
|
173
|
-
$("filesize").value = p.file || "";
|
|
174
|
-
$("i-bits").checked = true;
|
|
175
|
-
$("i-params").checked = false;
|
|
176
|
-
selected = null;
|
|
177
|
-
}
|
|
178
|
-
function applyPreset(p) {
|
|
179
|
-
setPresetControls(p);
|
|
180
|
-
update();
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
const num = (id) => {
|
|
184
|
-
const v = $(id).value.trim();
|
|
185
|
-
return v === "" ? null : Number(v);
|
|
186
|
-
};
|
|
187
|
-
|
|
188
|
-
function readInputs() {
|
|
189
|
-
const moe = $("k-moe").checked;
|
|
190
|
-
const quant = $("quant").value;
|
|
191
|
-
const customBits = num("custom-bits");
|
|
192
|
-
const bits = String(customBits ?? 4);
|
|
193
|
-
const fmt = quant === "custom" ? bits : quant === "custom-exl" ? `EXL3-${bits}` : quant;
|
|
194
|
-
const params = num("params");
|
|
195
|
-
const file = num("filesize");
|
|
196
|
-
const inferParams = file != null && $("i-params").checked;
|
|
197
|
-
const inferBits = file != null && !inferParams && !fromPreset.filesize;
|
|
198
|
-
const kv = num("kvpt");
|
|
199
|
-
return {
|
|
200
|
-
moe, quant, customBits, fmt,
|
|
201
|
-
params: params != null ? Math.round(params * 1e9) : null,
|
|
202
|
-
active: moe && num("active") != null ? Math.round(num("active") * 1e9) : null,
|
|
203
|
-
fileBytes: file != null ? Math.round(file * 1e9) : null,
|
|
204
|
-
inferParams,
|
|
205
|
-
inferBits,
|
|
206
|
-
attention: $("attention").value,
|
|
207
|
-
kvPerToken: kv != null && kv > 0 ? Math.round(kv * 1024) : null,
|
|
208
|
-
context: CONTEXTS[Number($("ctx").value)],
|
|
209
|
-
slots: num("slots"),
|
|
210
|
-
kvType: $("kvtype").value,
|
|
211
|
-
hostRam: Math.max(0, num("hostram") ?? 64) * GiB,
|
|
212
|
-
};
|
|
213
|
-
}
|
|
214
|
-
|
|
215
|
-
// ── formatting ────────────────────────────────────────────────────
|
|
216
|
-
const gib = (b) => { const g = b / GiB; return g >= 100 ? g.toFixed(0) : g >= 10 ? g.toFixed(1) : g.toFixed(2); };
|
|
217
|
-
const gb = (b) => { const g = b / 1e9; return g >= 100 ? g.toFixed(0) : g >= 10 ? g.toFixed(1) : g.toFixed(2); };
|
|
218
|
-
const tok = (t) => (t >= 100 ? Math.round(t).toLocaleString() : t >= 10 ? t.toFixed(0) : t ? t.toFixed(1) : "");
|
|
219
|
-
const ctxLabel = (c) => (c >= 1048576 ? `${c / 1048576}M` : `${c / 1024}K`);
|
|
220
|
-
const sizeArg = (b) => `${+(b / 1e9).toFixed(2)}GB`;
|
|
221
|
-
const paramArg = (n) => (n >= 1e12 ? `${+(n / 1e12).toFixed(3)}T` : `${+(n / 1e9).toFixed(2)}B`);
|
|
222
|
-
|
|
223
|
-
// ── render ────────────────────────────────────────────────────────
|
|
224
|
-
let selected = null;
|
|
225
|
-
let last = null;
|
|
226
|
-
let lastInputs = null;
|
|
227
|
-
let pinned = null;
|
|
228
|
-
let devFilter = "all";
|
|
229
|
-
let devQuery = "";
|
|
230
|
-
|
|
231
|
-
function ensureSelected(r) {
|
|
232
|
-
if (!selected || !r.devices.some((d) => d.device === selected)) {
|
|
233
|
-
const t = r.tiers.find((x) => x.verdict === "fits") || r.tiers.find((x) => x.verdict === "offload");
|
|
234
|
-
selected = t ? t.device : r.devices[r.devices.length - 1].device;
|
|
235
|
-
}
|
|
236
|
-
}
|
|
237
|
-
|
|
238
|
-
function tierIndex(t) {
|
|
239
|
-
const idx = D.tiers.findIndex(([id]) => id === t);
|
|
240
|
-
return idx === -1 ? D.tiers.length : idx;
|
|
241
|
-
}
|
|
242
|
-
|
|
243
|
-
function comparisonDevice(r) {
|
|
244
|
-
if (selected) {
|
|
245
|
-
const cur = r.devices.find((d) => d.device === selected);
|
|
246
|
-
if (cur) return cur;
|
|
247
|
-
}
|
|
248
|
-
const t = r.tiers.find((x) => x.verdict === "fits") || r.tiers.find((x) => x.verdict === "offload");
|
|
249
|
-
return (t && r.devices.find((d) => d.device === t.device)) || r.devices[r.devices.length - 1] || null;
|
|
250
|
-
}
|
|
251
|
-
|
|
252
|
-
function currentLabel(r) {
|
|
253
|
-
const preset = presetId ? PRESETS.find((p) => p.id === presetId) : null;
|
|
254
|
-
const base = preset
|
|
255
|
-
? preset.name
|
|
256
|
-
: `${(r.model.params / 1e9).toFixed(1)}B${r.model.kind === "moe" ? ` (A${(r.model.active_params / 1e9).toFixed(1)}B)` : ""}`;
|
|
257
|
-
return `${base} · ${r.format.name}`;
|
|
258
|
-
}
|
|
259
|
-
|
|
260
|
-
function syncPinButton() {
|
|
261
|
-
const pinBtn = $("pin-btn");
|
|
262
|
-
if (!pinBtn) return;
|
|
263
|
-
pinBtn.textContent = pinned ? "取消对比" : "固定当前方案作对比";
|
|
264
|
-
pinBtn.setAttribute("aria-pressed", String(Boolean(pinned)));
|
|
265
|
-
}
|
|
266
|
-
|
|
267
|
-
function renderCompare(r) {
|
|
268
|
-
const bar = $("compare-bar");
|
|
269
|
-
if (!bar) return;
|
|
270
|
-
if (!pinned) {
|
|
271
|
-
bar.hidden = true;
|
|
272
|
-
bar.innerHTML = "";
|
|
273
|
-
return;
|
|
274
|
-
}
|
|
275
|
-
bar.hidden = false;
|
|
276
|
-
const curTierId = r.magnitude.fits;
|
|
277
|
-
const curTier = tierName(curTierId);
|
|
278
|
-
const df = r.file_bytes - pinned.fileBytes;
|
|
279
|
-
const dr = r.runtime.total - pinned.runTotal;
|
|
280
|
-
const fileCls = Math.abs(df) < 1e6 ? "delta-flat" : df > 0 ? "delta-up" : "delta-down";
|
|
281
|
-
const runCls = Math.abs(dr) < 1e6 ? "delta-flat" : dr > 0 ? "delta-up" : "delta-down";
|
|
282
|
-
const fmtDelta = (bytes, unit) => {
|
|
283
|
-
const div = unit === "GiB" ? GiB : 1e9;
|
|
284
|
-
if (Math.abs(bytes / div) < 0.005) return `±0 ${unit}`;
|
|
285
|
-
const absStr = unit === "GiB" ? gib(Math.abs(bytes)) : gb(Math.abs(bytes));
|
|
286
|
-
return `${bytes > 0 ? "+" : "-"}${absStr} ${unit}`;
|
|
287
|
-
};
|
|
288
|
-
const pinnedTierId = "tierId" in pinned
|
|
289
|
-
? pinned.tierId
|
|
290
|
-
: (D.tiers.find(([id]) => TIER_ZH[id][0] === pinned.tier)?.[0] ?? null);
|
|
291
|
-
let tierChip;
|
|
292
|
-
if (curTier === pinned.tier) {
|
|
293
|
-
tierChip = `<span class="delta-chip delta-flat">量级:${esc(curTier)}(不变)</span>`;
|
|
294
|
-
} else {
|
|
295
|
-
const tierCls = tierIndex(curTierId) > tierIndex(pinnedTierId) ? "delta-up" : "delta-down";
|
|
296
|
-
tierChip = `<span class="delta-chip ${tierCls}">量级:${esc(pinned.tier)} → ${esc(curTier)}</span>`;
|
|
297
|
-
}
|
|
298
|
-
const dev = (pinned.deviceId && r.devices.find((d) => d.device === pinned.deviceId)) || comparisonDevice(r);
|
|
299
|
-
const curDecode = dev?.decode_ceiling_tok_s || 0;
|
|
300
|
-
let decodeChip = "";
|
|
301
|
-
if (pinned.decode > 0 || curDecode > 0) {
|
|
302
|
-
const devNote = dev ? `(${SHORT[dev.device] || dev.name})` : "";
|
|
303
|
-
if (pinned.decode > 0 && curDecode > 0) {
|
|
304
|
-
const dd = curDecode - pinned.decode;
|
|
305
|
-
const dCls = Math.abs(dd) < 0.05 ? "delta-flat" : dd > 0 ? "delta-up better" : "delta-down worse";
|
|
306
|
-
const dText = Math.abs(dd) < 0.05 ? "±0 tok/s" : `${dd > 0 ? "+" : "-"}${tok(Math.abs(dd))} tok/s`;
|
|
307
|
-
decodeChip = `<span class="delta-chip ${dCls}">decode${esc(devNote)}:${esc(dText)}</span>`;
|
|
308
|
-
} else if (curDecode > 0) {
|
|
309
|
-
decodeChip = `<span class="delta-chip delta-up better">decode${esc(devNote)}:可运行(${tok(curDecode)} tok/s)</span>`;
|
|
310
|
-
} else {
|
|
311
|
-
decodeChip = `<span class="delta-chip delta-down worse">decode${esc(devNote)}:不可运行</span>`;
|
|
312
|
-
}
|
|
313
|
-
}
|
|
314
|
-
bar.innerHTML = `<div class="compare-base">对比基准:<b>${esc(pinned.label)}</b>(${gb(pinned.fileBytes)} GB · ${gib(pinned.runTotal)} GiB · ${esc(pinned.tier)})</div>
|
|
315
|
-
<div class="compare-deltas">
|
|
316
|
-
<span class="delta-chip ${fileCls}">权重:${esc(fmtDelta(df, "GB"))}</span>
|
|
317
|
-
<span class="delta-chip ${runCls}">运行:${esc(fmtDelta(dr, "GiB"))}</span>
|
|
318
|
-
${tierChip}
|
|
319
|
-
${decodeChip}
|
|
320
|
-
</div>
|
|
321
|
-
<button type="button" class="compare-unpin" id="compare-unpin" data-action="unpin">× 取消对比</button>`;
|
|
322
|
-
}
|
|
323
|
-
|
|
324
|
-
function parseHashMap() {
|
|
325
|
-
if (typeof location === "undefined" || !location.hash || location.hash === "#") return null;
|
|
326
|
-
const raw = location.hash.startsWith("#") ? location.hash.slice(1) : location.hash;
|
|
327
|
-
if (!raw) return null;
|
|
328
|
-
const out = {};
|
|
329
|
-
for (const part of raw.split("&")) {
|
|
330
|
-
if (!part) continue;
|
|
331
|
-
const eq = part.indexOf("=");
|
|
332
|
-
const rawKey = eq === -1 ? part : part.slice(0, eq);
|
|
333
|
-
const rawVal = eq === -1 ? "" : part.slice(eq + 1);
|
|
334
|
-
try {
|
|
335
|
-
const k = decodeURIComponent(rawKey.replace(/\+/g, " "));
|
|
336
|
-
const v = decodeURIComponent(rawVal.replace(/\+/g, " "));
|
|
337
|
-
if (k) out[k] = v;
|
|
338
|
-
} catch { /* ignore malformed percent-encoding */ }
|
|
339
|
-
}
|
|
340
|
-
return Object.keys(out).length ? out : null;
|
|
341
|
-
}
|
|
342
|
-
|
|
343
|
-
function parseCtxIndex(raw) {
|
|
344
|
-
if (raw == null || raw === "") return null;
|
|
345
|
-
const text = String(raw).trim().toLowerCase();
|
|
346
|
-
if (/^\d+$/.test(text)) {
|
|
347
|
-
const idx = Number(text);
|
|
348
|
-
if (idx >= 0 && idx < CONTEXTS.length) return idx;
|
|
349
|
-
}
|
|
350
|
-
const m = text.match(/^(\d+(?:\.\d+)?)([km])?$/);
|
|
351
|
-
if (!m) return null;
|
|
352
|
-
const mul = m[2] === "m" ? 1048576 : m[2] === "k" ? 1024 : 1;
|
|
353
|
-
const tokens = Math.round(Number(m[1]) * mul);
|
|
354
|
-
if (!Number.isFinite(tokens) || tokens <= 0) return null;
|
|
355
|
-
let best = 0;
|
|
356
|
-
let bestDiff = Infinity;
|
|
357
|
-
for (let idx = 0; idx < CONTEXTS.length; idx++) {
|
|
358
|
-
const diff = Math.abs(CONTEXTS[idx] - tokens);
|
|
359
|
-
if (diff < bestDiff) { bestDiff = diff; best = idx; }
|
|
360
|
-
}
|
|
361
|
-
return best;
|
|
362
|
-
}
|
|
363
|
-
|
|
364
|
-
function applyQuantParam(quantRaw, bitsRaw) {
|
|
365
|
-
if (quantRaw == null || quantRaw === "") return;
|
|
366
|
-
const q = String(quantRaw).trim();
|
|
367
|
-
if (q === "custom" || q === "custom-exl") {
|
|
368
|
-
$("quant").value = q;
|
|
369
|
-
const b = Number(bitsRaw);
|
|
370
|
-
const maxB = q === "custom-exl" ? 16 : 32;
|
|
371
|
-
if (bitsRaw != null && Number.isFinite(b) && b >= 1 && b <= maxB) $("custom-bits").value = String(b);
|
|
372
|
-
return;
|
|
373
|
-
}
|
|
374
|
-
const upper = q.toUpperCase();
|
|
375
|
-
const matched = D.formats.find((f) => f.name.toUpperCase() === upper);
|
|
376
|
-
if (matched) {
|
|
377
|
-
$("quant").value = matched.name;
|
|
378
|
-
return;
|
|
379
|
-
}
|
|
380
|
-
if (upper.startsWith("EXL2-") || upper.startsWith("EXL3-")) {
|
|
381
|
-
const b = Number(q.slice(5));
|
|
382
|
-
if (Number.isFinite(b) && b >= 1 && b <= 16) {
|
|
383
|
-
$("quant").value = "custom-exl";
|
|
384
|
-
$("custom-bits").value = String(b);
|
|
385
|
-
}
|
|
386
|
-
return;
|
|
387
|
-
}
|
|
388
|
-
const b = Number(q);
|
|
389
|
-
if (Number.isFinite(b) && b >= 1 && b <= 32) {
|
|
390
|
-
$("quant").value = "custom";
|
|
391
|
-
$("custom-bits").value = String(b);
|
|
392
|
-
}
|
|
393
|
-
}
|
|
394
|
-
|
|
395
|
-
function buildHash(i) {
|
|
396
|
-
const pairs = [];
|
|
397
|
-
const add = (key, val) => {
|
|
398
|
-
if (val != null && String(val) !== "") {
|
|
399
|
-
pairs.push(`${encodeURIComponent(key)}=${encodeURIComponent(String(val))}`);
|
|
400
|
-
}
|
|
401
|
-
};
|
|
402
|
-
if (presetId) add("preset", presetId);
|
|
403
|
-
add("kind", i.moe ? "moe" : "dense");
|
|
404
|
-
if (!i.inferParams) add("params", $("params").value.trim());
|
|
405
|
-
if (i.moe) add("active", $("active").value.trim());
|
|
406
|
-
add("att", i.attention);
|
|
407
|
-
add("kvpt", $("kvpt").value.trim());
|
|
408
|
-
if (!i.inferBits) {
|
|
409
|
-
add("quant", i.quant);
|
|
410
|
-
if (i.quant.startsWith("custom")) add("bits", $("custom-bits").value.trim());
|
|
411
|
-
}
|
|
412
|
-
const fileRaw = $("filesize").value.trim();
|
|
413
|
-
add("file", fileRaw);
|
|
414
|
-
if (fileRaw !== "") add("infer", i.inferParams ? "params" : "bits");
|
|
415
|
-
add("ctx", i.context);
|
|
416
|
-
add("slots", $("slots").value.trim());
|
|
417
|
-
add("kv", i.kvType);
|
|
418
|
-
add("ram", $("hostram").value.trim());
|
|
419
|
-
return "#" + pairs.join("&");
|
|
420
|
-
}
|
|
421
|
-
|
|
422
|
-
function syncHash(i) {
|
|
423
|
-
if (typeof history === "undefined" || typeof history.replaceState !== "function") return;
|
|
424
|
-
const next = buildHash(i);
|
|
425
|
-
if (typeof location === "undefined" || location.hash !== next) {
|
|
426
|
-
try { history.replaceState(null, "", next); } catch { /* ignore file:// history restrictions */ }
|
|
427
|
-
}
|
|
428
|
-
}
|
|
429
|
-
|
|
430
|
-
function shareUrl() {
|
|
431
|
-
const hash = lastInputs ? buildHash(lastInputs) : (typeof location !== "undefined" && location.hash ? location.hash : "");
|
|
432
|
-
if (typeof location !== "undefined" && location.href) {
|
|
433
|
-
return location.href.split("#")[0] + hash;
|
|
434
|
-
}
|
|
435
|
-
return hash;
|
|
436
|
-
}
|
|
437
|
-
|
|
438
|
-
function clearFileSize(focusId) {
|
|
439
|
-
$("filesize").value = "";
|
|
440
|
-
fromPreset.filesize = false;
|
|
441
|
-
presetId = null;
|
|
442
|
-
$("i-bits").checked = true;
|
|
443
|
-
$("i-params").checked = false;
|
|
444
|
-
update();
|
|
445
|
-
if (focusId) $(focusId)?.focus?.();
|
|
446
|
-
}
|
|
447
|
-
|
|
448
|
-
function syncInferenceControls(i, hasFile) {
|
|
449
|
-
$("infer-seg").hidden = !hasFile;
|
|
450
|
-
const clearBtn = $("clear-file");
|
|
451
|
-
if (clearBtn) clearBtn.hidden = !hasFile;
|
|
452
|
-
$("active-field").hidden = !$("k-moe").checked;
|
|
453
|
-
const isCustomExl = i.quant === "custom-exl";
|
|
454
|
-
$("custom-field").hidden = i.inferBits || !i.quant.startsWith("custom");
|
|
455
|
-
const customBitsEl = $("custom-bits");
|
|
456
|
-
if (customBitsEl) {
|
|
457
|
-
const maxB = isCustomExl ? "16" : "32";
|
|
458
|
-
customBitsEl.max = maxB;
|
|
459
|
-
customBitsEl.setAttribute("max", maxB);
|
|
460
|
-
}
|
|
461
|
-
const customHint = $("custom-bits-hint");
|
|
462
|
-
if (customHint) customHint.textContent = isCustomExl ? "1–16 bpw" : "1–32 bpw";
|
|
463
|
-
|
|
464
|
-
const paramsEl = $("params");
|
|
465
|
-
paramsEl.disabled = i.inferParams;
|
|
466
|
-
paramsEl.setAttribute("aria-disabled", String(i.inferParams));
|
|
467
|
-
setClass($("params-field"), "is-inferred", i.inferParams);
|
|
468
|
-
const paramsInf = $("params-inferred");
|
|
469
|
-
if (paramsInf) paramsInf.hidden = !i.inferParams;
|
|
470
|
-
if (i.inferParams && $("params-inferred-text")) $("params-inferred-text").textContent = "由文件大小反推";
|
|
471
|
-
|
|
472
|
-
const quantEl = $("quant");
|
|
473
|
-
quantEl.disabled = i.inferBits;
|
|
474
|
-
quantEl.setAttribute("aria-disabled", String(i.inferBits));
|
|
475
|
-
setClass($("quant-field"), "is-inferred", i.inferBits);
|
|
476
|
-
const quantInf = $("quant-inferred");
|
|
477
|
-
if (quantInf) quantInf.hidden = !i.inferBits;
|
|
478
|
-
if (i.inferBits && $("quant-inferred-text")) $("quant-inferred-text").textContent = "由文件大小反推";
|
|
479
|
-
}
|
|
480
|
-
|
|
481
|
-
function update() {
|
|
482
|
-
for (const b of $("presets").querySelectorAll("button")) b.setAttribute("aria-pressed", String(b.dataset.id === presetId));
|
|
483
|
-
const hasFile = num("filesize") != null;
|
|
484
|
-
const i = readInputs();
|
|
485
|
-
syncInferenceControls(i, hasFile);
|
|
486
|
-
const ctxText = `${ctxLabel(i.context)} tokens`;
|
|
487
|
-
$("ctx-val").textContent = ctxText;
|
|
488
|
-
$("ctx").setAttribute("aria-valuetext", ctxText);
|
|
489
|
-
const resultsEl = document.querySelector(".results");
|
|
490
|
-
let r;
|
|
491
|
-
try {
|
|
492
|
-
if (i.slots != null && (!Number.isFinite(i.slots) || i.slots < 1)) throw new Error("slots must be at least 1");
|
|
493
|
-
if (!i.inferBits && i.quant === "custom-exl") {
|
|
494
|
-
if (i.customBits == null || !Number.isFinite(i.customBits) || i.customBits < 1 || i.customBits > 16) {
|
|
495
|
-
throw new Error("exl bits per weight must be between 1 and 16");
|
|
496
|
-
}
|
|
497
|
-
}
|
|
498
|
-
const slots = Math.max(1, Math.round(i.slots ?? 1));
|
|
499
|
-
const { shape, notes } = calc.shape({
|
|
500
|
-
params: i.inferParams ? null : i.params,
|
|
501
|
-
active: i.active,
|
|
502
|
-
fmt: i.inferBits ? null : i.fmt,
|
|
503
|
-
fileBytes: i.fileBytes,
|
|
504
|
-
attention: i.attention,
|
|
505
|
-
kvPerToken: i.kvPerToken,
|
|
506
|
-
});
|
|
507
|
-
const p = calc.posture({ context: i.context, slots, kvType: i.kvType, hostRam: i.hostRam });
|
|
508
|
-
r = calc.report(shape, p, notes);
|
|
509
|
-
r.shape = shape;
|
|
510
|
-
r.posture = p;
|
|
511
|
-
$("err").textContent = "";
|
|
512
|
-
$("err").hidden = true;
|
|
513
|
-
$("stale-note").hidden = true;
|
|
514
|
-
resultsEl?.classList.remove("is-stale");
|
|
515
|
-
setClass($("mobile-summary"), "is-stale", false);
|
|
516
|
-
} catch (e) {
|
|
517
|
-
$("err").textContent = zhMsg(e.message);
|
|
518
|
-
$("err").hidden = false;
|
|
519
|
-
$("stale-note").hidden = false;
|
|
520
|
-
resultsEl?.classList.add("is-stale");
|
|
521
|
-
setClass($("mobile-summary"), "is-stale", true);
|
|
522
|
-
return;
|
|
523
|
-
}
|
|
524
|
-
last = r;
|
|
525
|
-
lastInputs = i;
|
|
526
|
-
ensureSelected(r);
|
|
527
|
-
if (i.inferParams && $("params-inferred-text")) {
|
|
528
|
-
$("params-inferred-text").textContent = `由文件大小反推 ≈ ${(r.model.params / 1e9).toFixed(1)}B`;
|
|
529
|
-
}
|
|
530
|
-
if (i.inferBits && $("quant-inferred-text")) {
|
|
531
|
-
const nearMatch = String(r.format.note || "").match(/^nearest listed:\s*(.+)$/);
|
|
532
|
-
$("quant-inferred-text").textContent = nearMatch
|
|
533
|
-
? `由文件大小反推 · ${r.format.bits_per_weight} bpw(近 ${nearMatch[1]})`
|
|
534
|
-
: `由文件大小反推 · ${r.format.bits_per_weight} bpw`;
|
|
535
|
-
}
|
|
536
|
-
$("kv-val").textContent = `${(r.kv_bytes_per_token / 1024).toFixed(0)} KiB/token`;
|
|
537
|
-
$("bits-val").textContent = `${r.format.bits_per_weight} bpw`;
|
|
538
|
-
renderReadouts(r, i);
|
|
539
|
-
renderRuler(r);
|
|
540
|
-
renderDevices(r);
|
|
541
|
-
renderLadder(r);
|
|
542
|
-
renderCmd(r, i);
|
|
543
|
-
syncHash(i);
|
|
544
|
-
}
|
|
545
|
-
|
|
546
|
-
function tierName(t) {
|
|
547
|
-
return t ? TIER_ZH[t][0] : "多机集群";
|
|
548
|
-
}
|
|
549
|
-
|
|
550
|
-
function renderReadouts(r, i) {
|
|
551
|
-
const m = r.magnitude;
|
|
552
|
-
$("r-tier").textContent = tierName(m.fits);
|
|
553
|
-
const pick = r.tiers.find((t) => t.tier === m.fits);
|
|
554
|
-
let extra = m.runs && m.runs !== m.fits ? `;借系统内存卸载时,${tierName(m.runs)}也能跑` : "";
|
|
555
|
-
if (m.fits && m.fits_as_is !== m.fits)
|
|
556
|
-
extra += `;这一档要先转成同样大小的 GGUF / MLX,${r.format.name} 原样最小要${m.fits_as_is ? `到${tierName(m.fits_as_is)}` : "多机"}`;
|
|
557
|
-
$("r-tier-s").textContent = m.fits ? `${TIER_ZH[m.fits][1]},最小如 ${pick.name}${extra}` : `超过 8 卡服务器${extra}`;
|
|
558
|
-
$("r-file").innerHTML = `${gb(r.file_bytes)}<small>GB</small>`;
|
|
559
|
-
$("r-file-s").textContent = `${gib(r.file_bytes)} GiB · ${r.format.name} · ${r.format.bits_per_weight} bpw · ${(r.model.params / 1e9).toFixed(1)}B 参数`;
|
|
560
|
-
const rt = r.runtime;
|
|
561
|
-
$("r-run").innerHTML = `${gib(rt.total)}<small>GiB</small>`;
|
|
562
|
-
$("r-run-s").textContent = `${r.format.default_engine}:权重 ${gib(rt.weights)} + KV ${gib(rt.kv)} + 引擎 ${gib(rt.overhead)}`;
|
|
563
|
-
const active = (r.file_bytes * r.model.active_params) / r.model.params;
|
|
564
|
-
const read = active + rt.kv / r.posture.slots;
|
|
565
|
-
$("r-read").innerHTML = `${gb(read)}<small>GB</small>`;
|
|
566
|
-
$("r-read-s").textContent = r.model.kind === "moe"
|
|
567
|
-
? `MoE 只读激活的 ${(r.model.active_params / 1e9).toFixed(1)}B;${(r.model.expert_share * 100).toFixed(0)}% 权重在路由专家里`
|
|
568
|
-
: "稠密模型每 token 读一遍全部权重";
|
|
569
|
-
const notes = r.notes.map(zhMsg);
|
|
570
|
-
if (r.kv_source !== "given") notes.push(`KV 每 token 是按参数估的(${zhMsg(r.kv_source)});知道真实值就填进去,或用 memcalc 读 config.json。`);
|
|
571
|
-
if (i.context > 131072) notes.push("上下文超过 128K:很多模型训练长度到不了这里,先查模型的 max_position_embeddings。");
|
|
572
|
-
$("notes").innerHTML = notes.map((n) => `<p>· ${esc(n)}</p>`).join("");
|
|
573
|
-
const msTier = $("ms-tier");
|
|
574
|
-
const msRun = $("ms-run");
|
|
575
|
-
const msFile = $("ms-file");
|
|
576
|
-
if (msTier) msTier.textContent = tierName(m.fits);
|
|
577
|
-
if (msRun) msRun.textContent = `运行 ${gib(rt.total)} GiB`;
|
|
578
|
-
if (msFile) msFile.textContent = `权重 ${gb(r.file_bytes)} GB`;
|
|
579
|
-
renderCompare(r);
|
|
580
|
-
}
|
|
581
|
-
|
|
582
|
-
function renderRuler(r, restoreDotIds = null) {
|
|
583
|
-
const wrap = $("ruler-wrap");
|
|
584
|
-
const W = Math.max(300, wrap.clientWidth);
|
|
585
|
-
const narrow = W < 620;
|
|
586
|
-
const gutter = narrow ? 8 : 128;
|
|
587
|
-
const rowH = narrow ? 58 : 50;
|
|
588
|
-
const top = 34;
|
|
589
|
-
const H = top + rowH * D.tiers.length + 26;
|
|
590
|
-
const need = r.runtime.total, weights = r.runtime.weights;
|
|
591
|
-
const lo = 0.5 * GiB;
|
|
592
|
-
const hi = Math.max(2048 * GiB, need * 1.3);
|
|
593
|
-
const x0 = gutter, x1 = W - 14;
|
|
594
|
-
const X = (b) => x0 + ((Math.log2(Math.max(b, lo)) - Math.log2(lo)) / (Math.log2(hi) - Math.log2(lo))) * (x1 - x0);
|
|
595
|
-
const xn = X(need), xw = X(weights);
|
|
596
|
-
const parts = [];
|
|
597
|
-
// grid
|
|
598
|
-
for (let g = 1; g * GiB <= hi; g *= 2) {
|
|
599
|
-
const x = X(g * GiB);
|
|
600
|
-
const major = [1, 4, 16, 64, 256, 1024].includes(g) || (!narrow && g >= 2048);
|
|
601
|
-
parts.push(`<line x1="${x}" x2="${x}" y1="${top - 6}" y2="${H - 22}" stroke="var(--line)" stroke-width="1"/>`);
|
|
602
|
-
if (major || !narrow) parts.push(`<text x="${x}" y="${H - 6}" text-anchor="middle">${g >= 1024 ? `${g / 1024}T` : `${g}G`}</text>`);
|
|
603
|
-
}
|
|
604
|
-
// tier baselines
|
|
605
|
-
const rows = r.devices;
|
|
606
|
-
D.tiers.forEach((_t, idx) => {
|
|
607
|
-
const y = top + idx * rowH + rowH / 2 + (narrow ? 8 : 0);
|
|
608
|
-
parts.push(`<line x1="${x0}" x2="${x1}" y1="${y}" y2="${y}" stroke="var(--line-2)" stroke-width="1"/>`);
|
|
609
|
-
});
|
|
610
|
-
// vertical reference lines drawn below tier labels, device dots & haloed labels
|
|
611
|
-
parts.push(`<line x1="${xw}" x2="${xw}" y1="${top - 4}" y2="${H - 22}" stroke="var(--muted)" stroke-width="1.5" stroke-dasharray="4 3"/>`);
|
|
612
|
-
parts.push(`<line x1="${xn}" x2="${xn}" y1="${top - 10}" y2="${H - 22}" stroke="var(--ink)" stroke-width="2"/>`);
|
|
613
|
-
// tier labels & devices of each tier, merged when their usable memory is within 4%
|
|
614
|
-
D.tiers.forEach(([tier], idx) => {
|
|
615
|
-
const y = top + idx * rowH + rowH / 2 + (narrow ? 8 : 0);
|
|
616
|
-
const [label] = TIER_ZH[tier];
|
|
617
|
-
if (narrow) parts.push(`<text class="tl halo" x="${x0}" y="${y - 24}">${esc(label)}</text>`);
|
|
618
|
-
else parts.push(`<text class="tl" x="0" y="${y + 4}">${esc(label)}</text>`);
|
|
619
|
-
const mine = rows.filter((d) => d.tier === tier).sort((a, b) => a.usable_bytes - b.usable_bytes);
|
|
620
|
-
const groups = [];
|
|
621
|
-
for (const d of mine) {
|
|
622
|
-
const g = groups[groups.length - 1];
|
|
623
|
-
if (g && d.usable_bytes / g[0].usable_bytes < 1.04) g.push(d);
|
|
624
|
-
else groups.push([d]);
|
|
625
|
-
}
|
|
626
|
-
const lastRight = [-1e9, -1e9];
|
|
627
|
-
groups.forEach((g, gi) => {
|
|
628
|
-
const best = g.find((d) => d.verdict === "fits") || g.find((d) => d.verdict === "offload") || g[0];
|
|
629
|
-
const x = X(g[0].usable_bytes);
|
|
630
|
-
const color = best.verdict === "fits" ? "var(--good)" : best.verdict === "offload" ? "var(--s-off)" : "var(--none)";
|
|
631
|
-
const text = g.map((d) => SHORT[d.device] || d.device).join("/");
|
|
632
|
-
const w = [...text].reduce((n, ch) => n + (ch.charCodeAt(0) > 0x2e80 ? 10.5 : 6.2), 0);
|
|
633
|
-
const tryPlace = (sideIdx) => {
|
|
634
|
-
let lx = x;
|
|
635
|
-
let anchor = "middle";
|
|
636
|
-
let left = lx - w / 2;
|
|
637
|
-
let right = lx + w / 2;
|
|
638
|
-
if (left < x0) { left = x0; right = x0 + w; lx = x0; anchor = "start"; }
|
|
639
|
-
else if (right > x1) { right = x1; left = x1 - w; lx = x1; anchor = "end"; }
|
|
640
|
-
// Shift away from the vertical need line when a label would cross xn
|
|
641
|
-
if (left < xn + 5 && right > xn - 5) {
|
|
642
|
-
if (x <= xn && xn - 6 - w >= x0) {
|
|
643
|
-
anchor = "end";
|
|
644
|
-
lx = xn - 6;
|
|
645
|
-
right = lx;
|
|
646
|
-
left = lx - w;
|
|
647
|
-
} else if (x > xn && xn + 6 + w <= x1) {
|
|
648
|
-
anchor = "start";
|
|
649
|
-
lx = xn + 6;
|
|
650
|
-
left = lx;
|
|
651
|
-
right = lx + w;
|
|
652
|
-
}
|
|
653
|
-
}
|
|
654
|
-
if (left > lastRight[sideIdx] + 6) return { sideIdx, lx, anchor, right };
|
|
655
|
-
return null;
|
|
656
|
-
};
|
|
657
|
-
const placed = tryPlace(gi % 2) || tryPlace(1 - (gi % 2));
|
|
658
|
-
if (placed) lastRight[placed.sideIdx] = placed.right;
|
|
659
|
-
const ly = placed ? (placed.sideIdx ? y + 17 : y - 9) : y - 9;
|
|
660
|
-
const isSelDot = g.some((d) => d.device === selected);
|
|
661
|
-
const ariaLabel = g.map((d) => {
|
|
662
|
-
const status = VERDICT_ZH[d.verdict] + (d.offload_bytes ? `(${gib(d.offload_bytes)} GiB 进内存)` : "");
|
|
663
|
-
return `${d.name},可用 ${gib(d.usable_bytes)} GiB,需要 ${gib(d.need.total)} GiB,${status}`;
|
|
664
|
-
}).join(";");
|
|
665
|
-
parts.push(`<g class="dev${isSelDot ? " is-selected" : ""}" role="button" tabindex="0" data-ids="${g.map((d) => d.device).join(",")}" aria-label="${esc(ariaLabel)}" aria-pressed="${isSelDot ? "true" : "false"}">
|
|
666
|
-
${isSelDot ? `<circle class="sel-ring" cx="${x}" cy="${y}" r="9.5"/>` : ""}
|
|
667
|
-
<circle class="dot" cx="${x}" cy="${y}" r="6" fill="${color}" stroke="var(--surface)" stroke-width="2"/>
|
|
668
|
-
${placed ? `<text class="dl halo" aria-hidden="true" x="${placed.lx}" y="${ly}" text-anchor="${placed.anchor}">${esc(text)}</text>` : ""}</g>`);
|
|
669
|
-
});
|
|
670
|
-
});
|
|
671
|
-
const anchor = xn > W - 95 ? "end" : xn < x0 + 75 ? "start" : "middle";
|
|
672
|
-
parts.push(`<text class="need halo" x="${xn}" y="${top - 16}" text-anchor="${anchor}">需要 ${gib(need)} GiB</text>`);
|
|
673
|
-
const svg = $("ruler");
|
|
674
|
-
svg.setAttribute("viewBox", `0 0 ${W} ${H}`);
|
|
675
|
-
svg.setAttribute("width", W);
|
|
676
|
-
svg.setAttribute("height", H);
|
|
677
|
-
svg.innerHTML = parts.join("");
|
|
678
|
-
if (restoreDotIds) {
|
|
679
|
-
svg.querySelector?.(`g.dev[data-ids="${restoreDotIds}"]`)?.focus?.({ preventScroll: true });
|
|
680
|
-
}
|
|
681
|
-
}
|
|
682
|
-
|
|
683
|
-
function devTip(ids, evt) {
|
|
684
|
-
const rows = ids.map((id) => last.devices.find((d) => d.device === id)).filter(Boolean);
|
|
685
|
-
if (!rows.length) return;
|
|
686
|
-
const tip = $("tip");
|
|
687
|
-
tip.innerHTML = rows.map((d, idx) => {
|
|
688
|
-
const isCur = d.device === selected;
|
|
689
|
-
return `<div class="tip-dev${idx > 0 ? " tip-sep" : ""}">
|
|
690
|
-
<div class="th">${esc(d.name)}${rows.length > 1 && isCur ? '<span class="tip-cur">当前</span>' : ""}</div>
|
|
691
|
-
<div class="tr"><span>可用</span><span>${gib(d.usable_bytes)} GiB</span></div>
|
|
692
|
-
<div class="tr"><span>需要(${esc(d.engine)})</span><span>${gib(d.need.total)} GiB</span></div>
|
|
693
|
-
<div class="tr"><span>结论</span><span>${VERDICT_ZH[d.verdict]}${d.offload_bytes ? `,${gib(d.offload_bytes)} GiB 进内存` : ""}</span></div>
|
|
694
|
-
${d.decode_ceiling_tok_s ? `<div class="tr"><span>decode 上限</span><span>${tok(d.decode_ceiling_tok_s)} tok/s</span></div>` : ""}
|
|
695
|
-
</div>`;
|
|
696
|
-
}).join("") + (rows.length > 1 ? `<div class="tip-hint">点击圆点依次切换这 ${rows.length} 台设备</div>` : "");
|
|
697
|
-
tip.hidden = false;
|
|
698
|
-
const wrap = $("ruler-wrap").getBoundingClientRect();
|
|
699
|
-
const targetNode = evt.target?.closest?.("g") || evt.target;
|
|
700
|
-
if (!targetNode || typeof targetNode.getBoundingClientRect !== "function") return;
|
|
701
|
-
const box = targetNode.getBoundingClientRect();
|
|
702
|
-
const tipW = tip.offsetWidth || 220;
|
|
703
|
-
const tipH = tip.offsetHeight || 120;
|
|
704
|
-
const dotX = box.left - wrap.left + (box.width || 0) / 2;
|
|
705
|
-
const dotY = box.top - wrap.top + (box.height || 0) / 2;
|
|
706
|
-
let left = dotX + 12;
|
|
707
|
-
if (left + tipW > wrap.width - 4) left = dotX - tipW - 12;
|
|
708
|
-
left = Math.max(4, Math.min(left, Math.max(4, wrap.width - tipW - 4)));
|
|
709
|
-
const viewH = typeof window !== "undefined" && window.innerHeight ? window.innerHeight : wrap.top + wrap.height;
|
|
710
|
-
let top = dotY + 12;
|
|
711
|
-
if (top + tipH > wrap.height - 4 || wrap.top + top + tipH > viewH - 8) {
|
|
712
|
-
top = dotY - tipH - 12;
|
|
713
|
-
}
|
|
714
|
-
top = Math.max(4, Math.min(top, Math.max(4, wrap.height - tipH - 4)));
|
|
715
|
-
tip.style.left = `${Math.round(left)}px`;
|
|
716
|
-
tip.style.top = `${Math.round(top)}px`;
|
|
717
|
-
}
|
|
718
|
-
|
|
719
|
-
function matchesDevFilter(d) {
|
|
720
|
-
if (devFilter === "runnable" && d.verdict === "no") return false;
|
|
721
|
-
const q = devQuery.trim().toLowerCase();
|
|
722
|
-
if (!q) return true;
|
|
723
|
-
const tierInfo = TIER_ZH[d.tier] || ["", ""];
|
|
724
|
-
const backend = DEVICE_META[d.device]?.backend || "";
|
|
725
|
-
const hay = `${d.name} ${d.device} ${SHORT[d.device] || ""} ${d.engine} ${backend} ${tierInfo[0]} ${tierInfo[1]}`.toLowerCase();
|
|
726
|
-
return q.split(/\s+/).every((token) => hay.includes(token));
|
|
727
|
-
}
|
|
728
|
-
|
|
729
|
-
function renderDevices(r, restoreFocusId = null) {
|
|
730
|
-
const table = $("devtable");
|
|
731
|
-
const activeEl = typeof document !== "undefined" ? document.activeElement : null;
|
|
732
|
-
const activeRow = activeEl && typeof activeEl.closest === "function" ? activeEl.closest("tr.dev") : null;
|
|
733
|
-
const inTable = activeRow && (typeof table.contains !== "function" || table.contains(activeRow));
|
|
734
|
-
const focusId = restoreFocusId || (inTable ? activeRow.dataset?.id : null);
|
|
735
|
-
ensureSelected(r);
|
|
736
|
-
const byTier = {};
|
|
737
|
-
const visibleIds = new Set();
|
|
738
|
-
let runnableCount = 0;
|
|
739
|
-
for (const d of r.devices) {
|
|
740
|
-
if (d.verdict !== "no") runnableCount++;
|
|
741
|
-
if (!matchesDevFilter(d)) continue;
|
|
742
|
-
(byTier[d.tier] = byTier[d.tier] || []).push(d);
|
|
743
|
-
visibleIds.add(d.device);
|
|
744
|
-
}
|
|
745
|
-
const supportTag = (s) => {
|
|
746
|
-
const [label, tip] = SUPPORT_ZH[s] || [s, ""];
|
|
747
|
-
return `<span class="tag ${esc(s)}" data-support="${esc(s)}"${tip ? ` title="${esc(tip)}"` : ""}>${esc(label)}</span>`;
|
|
748
|
-
};
|
|
749
|
-
const html = [];
|
|
750
|
-
for (const [tier] of D.tiers) {
|
|
751
|
-
const rows = byTier[tier] || [];
|
|
752
|
-
if (!rows.length) continue;
|
|
753
|
-
const [label, detail] = TIER_ZH[tier];
|
|
754
|
-
html.push(`<tr class="tierhead"><td colspan="7">${esc(label)}<span>${esc(detail)}</span></td></tr>`);
|
|
755
|
-
for (const d of rows) {
|
|
756
|
-
const isSel = d.device === selected;
|
|
757
|
-
const verdict = `<span class="pill ${d.verdict}">${VERDICT_ZH[d.verdict]}</span>${d.offload_bytes ? ` <span class="hint">${gib(d.offload_bytes)} GiB 进内存</span>` : ""}`;
|
|
758
|
-
html.push(`<tr class="dev${isSel ? " cur" : ""}" data-id="${d.device}" tabindex="0" aria-selected="${isSel ? "true" : "false"}">
|
|
759
|
-
<td>${esc(d.name)}</td><td>${esc(d.engine)}</td><td>${supportTag(d.format_support)}</td>
|
|
760
|
-
<td class="n">${gib(d.need.total)}</td><td class="n">${gib(d.usable_bytes)}</td><td>${verdict}</td>
|
|
761
|
-
<td class="n">${tok(d.decode_ceiling_tok_s)}</td></tr>`);
|
|
762
|
-
}
|
|
763
|
-
}
|
|
764
|
-
if (!visibleIds.size) {
|
|
765
|
-
html.push('<tr class="empty-row"><td colspan="7">没有匹配的设备 <button type="button" class="link-btn" data-action="reset-dev-filter">清除筛选</button></td></tr>');
|
|
766
|
-
}
|
|
767
|
-
table.querySelector("tbody").innerHTML = html.join("");
|
|
768
|
-
const countEl = $("dev-filter-count");
|
|
769
|
-
if (countEl) {
|
|
770
|
-
const filtered = devFilter !== "all" || devQuery.trim() !== "";
|
|
771
|
-
countEl.textContent = filtered
|
|
772
|
-
? `显示 ${visibleIds.size} / ${r.devices.length} 台`
|
|
773
|
-
: `可运行 ${runnableCount} / ${r.devices.length} 台`;
|
|
774
|
-
}
|
|
775
|
-
if (focusId && visibleIds.has(focusId)) {
|
|
776
|
-
table.querySelector?.(`tr.dev[data-id="${focusId}"]`)?.focus?.({ preventScroll: true });
|
|
777
|
-
}
|
|
778
|
-
renderBar(r.devices.find((d) => d.device === selected), r);
|
|
779
|
-
}
|
|
780
|
-
|
|
781
|
-
function renderBar(d, r) {
|
|
782
|
-
const n = d.need;
|
|
783
|
-
const onHost = d.offload_bytes || 0;
|
|
784
|
-
const hostKv = d.host_kv_bytes || 0;
|
|
785
|
-
const hostWeights = d.host_weights_bytes ?? Math.max(0, onHost - hostKv);
|
|
786
|
-
const hostRoom = d.host_room_bytes || 0;
|
|
787
|
-
const scale = Math.max(d.usable_bytes, n.total - onHost, 1);
|
|
788
|
-
const pct = (b) => `${Math.max(0, (b / scale) * 100)}%`;
|
|
789
|
-
const weightsCard = n.weights - (d.host_weights_bytes || 0);
|
|
790
|
-
const kvCard = n.kv - hostKv;
|
|
791
|
-
const segs = [
|
|
792
|
-
[weightsCard, "var(--s-w)", "权重"],
|
|
793
|
-
[kvCard, "var(--s-kv)", "KV"],
|
|
794
|
-
[n.overhead, "var(--s-ov)", "引擎"],
|
|
795
|
-
];
|
|
796
|
-
const used = weightsCard + kvCard + n.overhead;
|
|
797
|
-
const free = Math.max(0, d.usable_bytes - used);
|
|
798
|
-
const over = Math.max(0, used - d.usable_bytes);
|
|
799
|
-
const um = (d.usable_bytes / scale) * 100;
|
|
800
|
-
const markCls = um > 85 ? "end" : um < 15 ? "start" : "";
|
|
801
|
-
let hostSection = "";
|
|
802
|
-
if (onHost > 0) {
|
|
803
|
-
const hostScale = Math.max(hostRoom, onHost, 1);
|
|
804
|
-
const hpct = (b) => `${Math.max(0, (b / hostScale) * 100)}%`;
|
|
805
|
-
const hostFree = Math.max(0, hostRoom - onHost);
|
|
806
|
-
const hum = (hostRoom / hostScale) * 100;
|
|
807
|
-
const hMarkCls = hum > 85 ? "end" : hum < 15 ? "start" : "";
|
|
808
|
-
const hostSegs = [[hostWeights, "var(--s-off)", "卸载权重"]];
|
|
809
|
-
if (hostKv > 0) hostSegs.push([hostKv, "color-mix(in srgb, var(--s-off) 55%, var(--s-kv))", "卸载 KV"]);
|
|
810
|
-
const hostAria = `卸载到系统内存 ${gib(onHost)} GiB(权重 ${gib(hostWeights)}${hostKv ? `,KV ${gib(hostKv)}` : ""}),主机可用 ${gib(hostRoom)} GiB`;
|
|
811
|
-
hostSection = `
|
|
812
|
-
<div class="bar-label host-label"><span>系统内存卸载</span><span>已用 <b>${gib(onHost)}</b> / 主机可用 ${gib(hostRoom)} GiB(权重 ${gib(hostWeights)}${hostKv ? ` + KV ${gib(hostKv)}` : ""})</span></div>
|
|
813
|
-
<div class="bar host-bar" role="img" aria-label="${esc(hostAria)}">
|
|
814
|
-
${hostSegs.map(([b, c, t]) => `<div title="${t} ${gib(b)} GiB" style="width:${hpct(b)};background:${c}"></div>`).join("")}
|
|
815
|
-
${hostFree ? `<div class="free" style="width:${hpct(hostFree)}"></div>` : ""}
|
|
816
|
-
<div class="mark ${hMarkCls}" style="left:${hum}%"><span>主机可用 ${gib(hostRoom)} GiB</span></div>
|
|
817
|
-
</div>`;
|
|
818
|
-
}
|
|
819
|
-
$("dev-title").textContent = `设备明细 · ${d.name}`;
|
|
820
|
-
$("mbar").innerHTML = `
|
|
821
|
-
<div class="mh"><span><b>${esc(d.name)}</b> · ${esc(d.engine)} · ${VERDICT_ZH[d.verdict]}</span>
|
|
822
|
-
<span>${onHost
|
|
823
|
-
? `卡上 <b>${gib(used)}</b> GiB + 卸载到内存 <b>${gib(onHost)}</b> GiB / 主机可用 ${gib(hostRoom)} GiB`
|
|
824
|
-
: `卡上 / 统一内存里 <b>${gib(used)}</b> GiB,可用 ${gib(d.usable_bytes)} GiB${over ? ` <b class="oom-note">(超出 ${gib(over)} GiB)</b>` : ""}`}</span></div>
|
|
825
|
-
${onHost ? `<div class="bar-label"><span>卡上显存</span><span>已用 <b>${gib(used)}</b> / 可用 ${gib(d.usable_bytes)} GiB</span></div>` : ""}
|
|
826
|
-
<div class="bar${over ? " is-over" : ""}" role="img" aria-label="权重 ${gib(weightsCard)},KV ${gib(kvCard)},引擎 ${gib(n.overhead)} GiB,可用 ${gib(d.usable_bytes)} GiB${over ? `,超出 ${gib(over)} GiB` : ""}">
|
|
827
|
-
${segs.map(([b, c, t]) => `<div title="${t} ${gib(b)} GiB" style="width:${pct(b)};background:${c}"></div>`).join("")}
|
|
828
|
-
${free ? `<div class="free" style="width:${pct(free)}"></div>` : ""}
|
|
829
|
-
${over ? `<div class="over" title="超出可用内存 ${gib(over)} GiB" style="left:${um}%;width:${Math.max(0, 100 - um)}%"></div>` : ""}
|
|
830
|
-
<div class="mark ${markCls}" style="left:${um}%"><span>可用 ${gib(d.usable_bytes)} GiB</span></div>
|
|
831
|
-
</div>${hostSection}
|
|
832
|
-
<div class="legend"><span><i class="sq" style="background:var(--s-w)"></i>权重 ${gib(weightsCard)}</span><span><i class="sq" style="background:var(--s-kv)"></i>KV ${gib(kvCard)}(${ctxLabel(r.posture.context)} × ${r.posture.slots},${r.posture.kvType})</span><span><i class="sq" style="background:var(--s-ov)"></i>引擎 ${gib(n.overhead)}</span>${onHost ? `<span><i class="sq" style="background:var(--s-off)"></i>卸载到内存 ${gib(onHost)}(权重 ${gib(hostWeights)}${hostKv ? ` + KV ${gib(hostKv)}` : ""})</span>` : ""}${over ? `<span><i class="sq over-swatch"></i>超出 ${gib(over)} GiB</span>` : ""}${d.decode_ceiling_tok_s ? `<span>decode 上限 ≈ ${tok(d.decode_ceiling_tok_s)} tok/s</span>` : ""}</div>`;
|
|
833
|
-
}
|
|
834
|
-
|
|
835
|
-
function renderLadder(r) {
|
|
836
|
-
const max = Math.max(...r.ladder.map((l) => l.file_bytes));
|
|
837
|
-
const listed = new Set(D.formats.map((f) => f.name));
|
|
838
|
-
$("ladder").innerHTML = r.ladder.map((l) => {
|
|
839
|
-
const selectable = listed.has(l.format);
|
|
840
|
-
const attrs = selectable
|
|
841
|
-
? ` role="button" tabindex="0" data-fmt="${esc(l.format)}" aria-pressed="${l.current ? "true" : "false"}" title="切换到 ${esc(l.format)}"`
|
|
842
|
-
: "";
|
|
843
|
-
return `<div class="lr${l.current ? " on" : ""}${selectable ? " clickable" : ""}"${attrs}>
|
|
844
|
-
<span class="ln">${esc(l.format)}<small>${l.bits}</small></span>
|
|
845
|
-
<span class="lb"><div style="width:${(l.file_bytes / max) * 100}%"></div><em>${gb(l.file_bytes)} GB</em></span>
|
|
846
|
-
<span class="lt">${esc(tierName(l.fits))}${l.fits && l.fits_as_is !== l.fits ? `(需转格式;原样:${esc(tierName(l.fits_as_is))})` : ""}${l.runs && l.runs !== l.fits ? ` · 卸载:${esc(tierName(l.runs))}` : ""}</span></div>`;
|
|
847
|
-
}).join("");
|
|
848
|
-
}
|
|
849
|
-
|
|
850
|
-
function renderFormats() {
|
|
851
|
-
const basisTag = (b) => {
|
|
852
|
-
const [label, tip] = BASIS_ZH[b] || [b, ""];
|
|
853
|
-
return `<span class="tag" data-basis="${esc(b)}"${tip ? ` title="${esc(tip)}"` : ""}>${esc(label)}</span>`;
|
|
854
|
-
};
|
|
855
|
-
const fmtNote = (note) => (note ? (FMT_NOTE_ZH[note] || note) : "");
|
|
856
|
-
$("fmttable").querySelector("tbody").innerHTML = D.formats.map((f) => `<tr>
|
|
857
|
-
<td class="mono">${esc(f.name)}</td><td>${esc(FAMILY_ZH[f.family] || f.family)}</td>
|
|
858
|
-
<td class="n">${f.bits}</td><td>${basisTag(f.basis)}</td><td class="n">${(f.bits / 8).toFixed(2)} GB</td>
|
|
859
|
-
<td>${esc(D.default_engine[f.family])}</td><td class="hint">${esc(fmtNote(f.note))}</td></tr>`).join("");
|
|
860
|
-
$("refs").innerHTML = REFS.map(([t, u]) => `<li><a href="${esc(u)}" target="_blank" rel="noopener">${esc(t)}</a></li>`).join("");
|
|
861
|
-
}
|
|
862
|
-
|
|
863
|
-
function renderCmd(r, i) {
|
|
864
|
-
const a = ["localmodels sizecalc"];
|
|
865
|
-
if (!i.inferParams && i.params != null) a.push(`--params ${paramArg(i.params)}`);
|
|
866
|
-
if (i.active != null) a.push(`--active ${paramArg(i.active)}`);
|
|
867
|
-
if (!i.inferBits) a.push(`--quant ${i.fmt}`);
|
|
868
|
-
if (i.fileBytes != null) a.push(`--file-size ${sizeArg(i.fileBytes)}`);
|
|
869
|
-
if (i.attention !== "full") a.push(`--attention ${i.attention}`);
|
|
870
|
-
if (i.kvPerToken != null) a.push(`--kv-per-token ${+(i.kvPerToken / 1024).toFixed(1)}KiB`);
|
|
871
|
-
if (i.context !== D.constants.default_context) a.push(`--context ${ctxLabel(i.context).toLowerCase()}`);
|
|
872
|
-
if (i.slots != null && Math.round(i.slots) > 1) a.push(`--slots ${Math.round(i.slots)}`);
|
|
873
|
-
if (i.kvType !== "f16") a.push(`--kv ${i.kvType}`);
|
|
874
|
-
if (i.hostRam !== D.constants.default_host_ram) a.push(`--host-ram ${i.hostRam / GiB}GiB`);
|
|
875
|
-
$("cmd").textContent = a.join(" ");
|
|
876
|
-
}
|
|
877
|
-
|
|
878
|
-
// ── clipboard & theme helpers ─────────────────────────────────────
|
|
879
|
-
async function copyText(text, fallbackEl = null) {
|
|
880
|
-
if (typeof navigator !== "undefined" && navigator.clipboard && typeof navigator.clipboard.writeText === "function") {
|
|
881
|
-
try {
|
|
882
|
-
await navigator.clipboard.writeText(text);
|
|
883
|
-
return "copied";
|
|
884
|
-
} catch { /* fall through to execCommand fallback */ }
|
|
885
|
-
}
|
|
886
|
-
if (typeof document !== "undefined" && typeof document.createElement === "function" && document.body && typeof document.body.appendChild === "function") {
|
|
887
|
-
const ta = document.createElement("textarea");
|
|
888
|
-
ta.value = text;
|
|
889
|
-
ta.setAttribute?.("readonly", "");
|
|
890
|
-
if (ta.style) {
|
|
891
|
-
ta.style.position = "fixed";
|
|
892
|
-
ta.style.top = "-9999px";
|
|
893
|
-
ta.style.left = "-9999px";
|
|
894
|
-
ta.style.opacity = "0";
|
|
895
|
-
}
|
|
896
|
-
document.body.appendChild(ta);
|
|
897
|
-
try {
|
|
898
|
-
ta.focus?.();
|
|
899
|
-
ta.select?.();
|
|
900
|
-
ta.setSelectionRange?.(0, text.length);
|
|
901
|
-
if (typeof document.execCommand === "function" && document.execCommand("copy")) {
|
|
902
|
-
return "copied";
|
|
903
|
-
}
|
|
904
|
-
} catch { /* fall through to selection fallback */ }
|
|
905
|
-
finally {
|
|
906
|
-
ta.remove?.();
|
|
907
|
-
}
|
|
908
|
-
}
|
|
909
|
-
if (fallbackEl && typeof window !== "undefined" && typeof window.getSelection === "function" && typeof document.createRange === "function") {
|
|
910
|
-
try {
|
|
911
|
-
const range = document.createRange();
|
|
912
|
-
range.selectNodeContents(fallbackEl);
|
|
913
|
-
const sel = window.getSelection();
|
|
914
|
-
sel?.removeAllRanges?.();
|
|
915
|
-
sel?.addRange?.(range);
|
|
916
|
-
return "selected";
|
|
917
|
-
} catch { /* ignore */ }
|
|
918
|
-
}
|
|
919
|
-
return "failed";
|
|
920
|
-
}
|
|
921
|
-
|
|
922
|
-
function bindCopyButton(btn, getText, defaultLabel, opts = {}) {
|
|
923
|
-
if (!btn) return;
|
|
924
|
-
let resetTimer = null;
|
|
925
|
-
btn.addEventListener("click", async () => {
|
|
926
|
-
if (typeof clearTimeout === "function" && resetTimer != null) {
|
|
927
|
-
clearTimeout(resetTimer);
|
|
928
|
-
resetTimer = null;
|
|
929
|
-
}
|
|
930
|
-
const res = await copyText(getText(), opts.fallbackEl || null);
|
|
931
|
-
if (res === "copied") {
|
|
932
|
-
btn.textContent = opts.okLabel || "已复制";
|
|
933
|
-
btn.classList.add("done");
|
|
934
|
-
announce(opts.okAnnounce || "已复制到剪贴板");
|
|
935
|
-
} else if (res === "selected") {
|
|
936
|
-
btn.textContent = "已选中,请 Ctrl+C";
|
|
937
|
-
btn.classList.remove("done");
|
|
938
|
-
announce("未能自动复制,已选中文本,请按 Ctrl+C 复制");
|
|
939
|
-
} else {
|
|
940
|
-
btn.textContent = opts.failLabel || "复制失败";
|
|
941
|
-
btn.classList.remove("done");
|
|
942
|
-
announce(opts.failAnnounce || "复制失败");
|
|
943
|
-
}
|
|
944
|
-
if (typeof setTimeout === "function") {
|
|
945
|
-
resetTimer = setTimeout(() => {
|
|
946
|
-
btn.textContent = defaultLabel;
|
|
947
|
-
btn.classList.remove("done");
|
|
948
|
-
resetTimer = null;
|
|
949
|
-
}, 1600);
|
|
950
|
-
}
|
|
951
|
-
});
|
|
952
|
-
}
|
|
953
|
-
|
|
954
|
-
const THEME_KEY = "localmodels.theme";
|
|
955
|
-
const THEME_LEGACY_KEYS = ["lm-sizecalc-theme", "lm-theme"];
|
|
956
|
-
const THEME_ORDER = ["auto", "light", "dark"];
|
|
957
|
-
const THEME_LABEL = { auto: "外观:跟随系统", light: "外观:浅色", dark: "外观:深色" };
|
|
958
|
-
const THEME_NEXT = { auto: "浅色", light: "深色", dark: "跟随系统" };
|
|
959
|
-
|
|
960
|
-
function readSavedTheme() {
|
|
961
|
-
try {
|
|
962
|
-
if (typeof localStorage !== "undefined" && typeof localStorage.getItem === "function") {
|
|
963
|
-
for (const key of [THEME_KEY, ...THEME_LEGACY_KEYS]) {
|
|
964
|
-
const saved = localStorage.getItem(key);
|
|
965
|
-
if (THEME_ORDER.includes(saved)) return saved;
|
|
966
|
-
}
|
|
967
|
-
}
|
|
968
|
-
} catch { /* ignore storage errors on file:// or private browsing */ }
|
|
969
|
-
return "auto";
|
|
970
|
-
}
|
|
971
|
-
|
|
972
|
-
function saveTheme(mode) {
|
|
973
|
-
try {
|
|
974
|
-
if (typeof localStorage !== "undefined" && typeof localStorage.setItem === "function") {
|
|
975
|
-
localStorage.setItem(THEME_KEY, mode);
|
|
976
|
-
for (const key of THEME_LEGACY_KEYS) localStorage.setItem(key, mode);
|
|
977
|
-
}
|
|
978
|
-
} catch { /* ignore */ }
|
|
979
|
-
}
|
|
980
|
-
|
|
981
|
-
function applyTheme(mode) {
|
|
982
|
-
const m = THEME_ORDER.includes(mode) ? mode : "auto";
|
|
983
|
-
if (document.documentElement?.dataset) {
|
|
984
|
-
if (m === "auto") delete document.documentElement.dataset.theme;
|
|
985
|
-
else document.documentElement.dataset.theme = m;
|
|
986
|
-
}
|
|
987
|
-
const btn = $("theme");
|
|
988
|
-
if (!btn) return;
|
|
989
|
-
btn.textContent = THEME_LABEL[m];
|
|
990
|
-
const tip = `当前${THEME_LABEL[m]},点击切换为${THEME_NEXT[m]}`;
|
|
991
|
-
btn.title = tip;
|
|
992
|
-
btn.setAttribute("aria-label", tip);
|
|
993
|
-
}
|
|
994
|
-
|
|
995
|
-
function selectLadderFormat(fmt, restoreFocus = false) {
|
|
996
|
-
if (!fmt || !D.formats.some((f) => f.name === fmt)) return;
|
|
997
|
-
const inferring = num("filesize") != null && $("i-params").checked;
|
|
998
|
-
presetId = null;
|
|
999
|
-
if (!inferring && num("filesize") != null) {
|
|
1000
|
-
$("filesize").value = "";
|
|
1001
|
-
fromPreset.filesize = false;
|
|
1002
|
-
} else if (inferring) {
|
|
1003
|
-
fromPreset.filesize = false;
|
|
1004
|
-
}
|
|
1005
|
-
$("quant").value = fmt;
|
|
1006
|
-
update();
|
|
1007
|
-
if (restoreFocus) {
|
|
1008
|
-
$("ladder").querySelector?.(`.lr[data-fmt="${fmt}"]`)?.focus?.({ preventScroll: true });
|
|
1009
|
-
}
|
|
1010
|
-
}
|
|
1011
|
-
|
|
1012
|
-
// ── wiring ────────────────────────────────────────────────────────
|
|
1013
|
-
fillControls();
|
|
1014
|
-
renderFormats();
|
|
1015
|
-
for (const el of document.querySelectorAll(".controls input, .controls select")) {
|
|
1016
|
-
el.addEventListener(el.tagName === "SELECT" ? "change" : "input", () => {
|
|
1017
|
-
const id = el.id;
|
|
1018
|
-
const posture = ["ctx", "slots", "kvtype", "hostram"].includes(id);
|
|
1019
|
-
if (!posture) presetId = null;
|
|
1020
|
-
// Parameters are inferred from the file when its size is given and "infer parameters" is on.
|
|
1021
|
-
const inferring = num("filesize") != null && $("i-params").checked;
|
|
1022
|
-
const isInferRadio = id === "i-bits" || id === "i-params" || el.name === "infer";
|
|
1023
|
-
const formatMoves = id === "quant" || id === "custom-bits";
|
|
1024
|
-
const paramsMove = ["params", "active", "k-dense", "k-moe"].includes(id) ||
|
|
1025
|
-
isInferRadio || (inferring && (formatMoves || id === "filesize"));
|
|
1026
|
-
// A preset's file belongs to its parameters and format, unless it is the input the
|
|
1027
|
-
// parameters are inferred from; its KV per token belongs to its layer layout.
|
|
1028
|
-
if (id === "filesize" || id === "i-bits" || (inferring && formatMoves)) fromPreset.filesize = false;
|
|
1029
|
-
else if (fromPreset.filesize && !inferring && !isInferRadio && (paramsMove || formatMoves)) {
|
|
1030
|
-
$("filesize").value = "";
|
|
1031
|
-
fromPreset.filesize = false;
|
|
1032
|
-
}
|
|
1033
|
-
if (id === "kvpt") fromPreset.kvpt = false;
|
|
1034
|
-
else if (fromPreset.kvpt && (paramsMove || id === "attention")) {
|
|
1035
|
-
$("kvpt").value = "";
|
|
1036
|
-
fromPreset.kvpt = false;
|
|
1037
|
-
}
|
|
1038
|
-
update();
|
|
1039
|
-
});
|
|
1040
|
-
}
|
|
1041
|
-
function syncDevFilterButtons() {
|
|
1042
|
-
$("dev-filter-all")?.setAttribute("aria-pressed", String(devFilter === "all"));
|
|
1043
|
-
$("dev-filter-runnable")?.setAttribute("aria-pressed", String(devFilter === "runnable"));
|
|
1044
|
-
}
|
|
1045
|
-
function setDevFilter(mode) {
|
|
1046
|
-
if ((mode !== "all" && mode !== "runnable") || devFilter === mode) return;
|
|
1047
|
-
devFilter = mode;
|
|
1048
|
-
syncDevFilterButtons();
|
|
1049
|
-
if (last) renderDevices(last);
|
|
1050
|
-
}
|
|
1051
|
-
function resetDevFilters() {
|
|
1052
|
-
devFilter = "all";
|
|
1053
|
-
devQuery = "";
|
|
1054
|
-
const searchEl = $("dev-search");
|
|
1055
|
-
if (searchEl) searchEl.value = "";
|
|
1056
|
-
const clearSearch = $("dev-search-clear");
|
|
1057
|
-
if (clearSearch) clearSearch.hidden = true;
|
|
1058
|
-
syncDevFilterButtons();
|
|
1059
|
-
if (last) renderDevices(last);
|
|
1060
|
-
}
|
|
1061
|
-
function clearPin() {
|
|
1062
|
-
if (!pinned) return;
|
|
1063
|
-
pinned = null;
|
|
1064
|
-
syncPinButton();
|
|
1065
|
-
if (last) renderCompare(last);
|
|
1066
|
-
announce("已取消对比");
|
|
1067
|
-
}
|
|
1068
|
-
function pickRulerDot(ids, { restoreFocus = false, refreshTip = false } = {}) {
|
|
1069
|
-
if (!ids.length || !last) return;
|
|
1070
|
-
const idx = ids.indexOf(selected);
|
|
1071
|
-
selected = idx >= 0 ? ids[(idx + 1) % ids.length] : ids[0];
|
|
1072
|
-
const rawIds = ids.join(",");
|
|
1073
|
-
renderRuler(last, restoreFocus ? rawIds : null);
|
|
1074
|
-
renderDevices(last);
|
|
1075
|
-
if (refreshTip && !$("tip").hidden) {
|
|
1076
|
-
const freshG = $("ruler").querySelector?.(`g.dev[data-ids="${rawIds}"]`);
|
|
1077
|
-
if (freshG && typeof freshG.getBoundingClientRect === "function") devTip(ids, { target: freshG });
|
|
1078
|
-
}
|
|
1079
|
-
}
|
|
1080
|
-
|
|
1081
|
-
$("clear-file")?.addEventListener("click", () => clearFileSize("filesize"));
|
|
1082
|
-
$("clear-file-params")?.addEventListener("click", () => clearFileSize("params"));
|
|
1083
|
-
$("clear-file-quant")?.addEventListener("click", () => clearFileSize("quant"));
|
|
1084
|
-
$("dev-filter-all")?.addEventListener("click", () => setDevFilter("all"));
|
|
1085
|
-
$("dev-filter-runnable")?.addEventListener("click", () => setDevFilter("runnable"));
|
|
1086
|
-
$("dev-filter-bar")?.addEventListener("click", (e) => {
|
|
1087
|
-
const btn = e.target?.closest?.("button[data-filter]");
|
|
1088
|
-
if (btn) setDevFilter(btn.dataset.filter);
|
|
1089
|
-
});
|
|
1090
|
-
$("dev-search")?.addEventListener("input", () => {
|
|
1091
|
-
devQuery = $("dev-search").value || "";
|
|
1092
|
-
const clearSearch = $("dev-search-clear");
|
|
1093
|
-
if (clearSearch) clearSearch.hidden = !devQuery;
|
|
1094
|
-
if (last) renderDevices(last);
|
|
1095
|
-
});
|
|
1096
|
-
$("dev-search")?.addEventListener("keydown", (e) => {
|
|
1097
|
-
if (e.key === "Escape" && devQuery) {
|
|
1098
|
-
e.preventDefault?.();
|
|
1099
|
-
devQuery = "";
|
|
1100
|
-
$("dev-search").value = "";
|
|
1101
|
-
const clearSearch = $("dev-search-clear");
|
|
1102
|
-
if (clearSearch) clearSearch.hidden = true;
|
|
1103
|
-
if (last) renderDevices(last);
|
|
1104
|
-
}
|
|
1105
|
-
});
|
|
1106
|
-
$("dev-search-clear")?.addEventListener("click", () => {
|
|
1107
|
-
devQuery = "";
|
|
1108
|
-
const searchEl = $("dev-search");
|
|
1109
|
-
if (searchEl) searchEl.value = "";
|
|
1110
|
-
$("dev-search-clear").hidden = true;
|
|
1111
|
-
if (last) renderDevices(last);
|
|
1112
|
-
searchEl?.focus?.();
|
|
1113
|
-
});
|
|
1114
|
-
$("compare-bar")?.addEventListener("click", (e) => {
|
|
1115
|
-
if (e.target?.closest?.("[data-action='unpin']")) clearPin();
|
|
1116
|
-
});
|
|
1117
|
-
$("ms-jump")?.addEventListener("click", () => {
|
|
1118
|
-
const resultsEl = document.querySelector(".results");
|
|
1119
|
-
let reduce = false;
|
|
1120
|
-
try {
|
|
1121
|
-
reduce = typeof matchMedia === "function" && Boolean(matchMedia("(prefers-reduced-motion: reduce)").matches);
|
|
1122
|
-
} catch { /* ignore */ }
|
|
1123
|
-
resultsEl?.scrollIntoView?.({ behavior: reduce ? "auto" : "smooth", block: "start" });
|
|
1124
|
-
});
|
|
1125
|
-
$("devtable").addEventListener("click", (e) => {
|
|
1126
|
-
if (e.target?.closest?.("[data-action='reset-dev-filter']")) { resetDevFilters(); return; }
|
|
1127
|
-
const tr = e.target?.closest?.("tr.dev");
|
|
1128
|
-
if (tr) { selected = tr.dataset.id; if (last) { renderRuler(last); renderDevices(last); } }
|
|
1129
|
-
});
|
|
1130
|
-
$("devtable").addEventListener("keydown", (e) => {
|
|
1131
|
-
const tr = e.target?.closest?.("tr.dev");
|
|
1132
|
-
if (tr && (e.key === "Enter" || e.key === " ")) {
|
|
1133
|
-
e.preventDefault?.();
|
|
1134
|
-
selected = tr.dataset.id;
|
|
1135
|
-
if (last) { renderRuler(last); renderDevices(last, tr.dataset.id); }
|
|
1136
|
-
}
|
|
1137
|
-
});
|
|
1138
|
-
$("ladder").addEventListener("click", (e) => {
|
|
1139
|
-
const row = e.target.closest?.(".lr[data-fmt]");
|
|
1140
|
-
if (row) selectLadderFormat(row.dataset.fmt, false);
|
|
1141
|
-
});
|
|
1142
|
-
$("ladder").addEventListener("keydown", (e) => {
|
|
1143
|
-
const row = e.target.closest?.(".lr[data-fmt]");
|
|
1144
|
-
if (row && (e.key === "Enter" || e.key === " ")) { e.preventDefault?.(); selectLadderFormat(row.dataset.fmt, true); }
|
|
1145
|
-
});
|
|
1146
|
-
const ruler = $("ruler");
|
|
1147
|
-
const showTip = (e) => { const g = e.target?.closest?.("g.dev"); if (g) devTip(g.dataset.ids.split(","), e); };
|
|
1148
|
-
ruler.addEventListener("mouseover", showTip);
|
|
1149
|
-
ruler.addEventListener("focusin", showTip);
|
|
1150
|
-
ruler.addEventListener("mouseout", () => { $("tip").hidden = true; });
|
|
1151
|
-
ruler.addEventListener("focusout", () => { $("tip").hidden = true; });
|
|
1152
|
-
ruler.addEventListener("click", (e) => {
|
|
1153
|
-
const g = e.target?.closest?.("g.dev");
|
|
1154
|
-
if (g) pickRulerDot(g.dataset.ids.split(","), { refreshTip: true });
|
|
1155
|
-
});
|
|
1156
|
-
ruler.addEventListener("keydown", (e) => {
|
|
1157
|
-
const g = e.target?.closest?.("g.dev");
|
|
1158
|
-
if (g && (e.key === "Enter" || e.key === " ")) {
|
|
1159
|
-
e.preventDefault?.();
|
|
1160
|
-
const ids = g.dataset.ids.split(",");
|
|
1161
|
-
pickRulerDot(ids, { restoreFocus: true, refreshTip: true });
|
|
1162
|
-
if (ids.length === 1) {
|
|
1163
|
-
$("devtable").querySelector?.(`tr[data-id="${selected}"]`)?.scrollIntoView?.({ block: "nearest" });
|
|
1164
|
-
}
|
|
1165
|
-
}
|
|
1166
|
-
});
|
|
1167
|
-
bindCopyButton($("copy"), () => $("cmd").textContent, "复制", {
|
|
1168
|
-
fallbackEl: $("cmd"),
|
|
1169
|
-
okLabel: "已复制",
|
|
1170
|
-
okAnnounce: "命令已复制到剪贴板",
|
|
1171
|
-
failAnnounce: "复制命令失败",
|
|
1172
|
-
});
|
|
1173
|
-
bindCopyButton($("share-btn"), shareUrl, "复制链接", {
|
|
1174
|
-
okLabel: "已复制链接",
|
|
1175
|
-
okAnnounce: "当前方案链接已复制到剪贴板",
|
|
1176
|
-
failLabel: "请复制地址栏",
|
|
1177
|
-
failAnnounce: "未能自动复制链接,请直接复制浏览器地址栏",
|
|
1178
|
-
});
|
|
1179
|
-
let themeMode = readSavedTheme();
|
|
1180
|
-
applyTheme(themeMode);
|
|
1181
|
-
$("theme").addEventListener("click", () => {
|
|
1182
|
-
themeMode = THEME_ORDER[(THEME_ORDER.indexOf(themeMode) + 1) % THEME_ORDER.length];
|
|
1183
|
-
applyTheme(themeMode);
|
|
1184
|
-
saveTheme(themeMode);
|
|
1185
|
-
});
|
|
1186
|
-
$("pin-btn")?.addEventListener("click", () => {
|
|
1187
|
-
if (pinned) {
|
|
1188
|
-
clearPin();
|
|
1189
|
-
return;
|
|
1190
|
-
}
|
|
1191
|
-
if (last) {
|
|
1192
|
-
const dev = comparisonDevice(last);
|
|
1193
|
-
pinned = {
|
|
1194
|
-
label: currentLabel(last),
|
|
1195
|
-
fileBytes: last.file_bytes,
|
|
1196
|
-
runTotal: last.runtime.total,
|
|
1197
|
-
tier: tierName(last.magnitude.fits),
|
|
1198
|
-
tierId: last.magnitude.fits,
|
|
1199
|
-
deviceId: dev?.device || null,
|
|
1200
|
-
deviceName: dev?.name || "",
|
|
1201
|
-
decode: dev?.decode_ceiling_tok_s || 0,
|
|
1202
|
-
};
|
|
1203
|
-
}
|
|
1204
|
-
syncPinButton();
|
|
1205
|
-
if (last) renderCompare(last);
|
|
1206
|
-
});
|
|
1207
|
-
let raf = 0;
|
|
1208
|
-
addEventListener("resize", () => { cancelAnimationFrame(raf); raf = requestAnimationFrame(() => last && renderRuler(last)); });
|
|
1209
|
-
|
|
1210
|
-
function initFromHash() {
|
|
1211
|
-
const fallback = PRESETS.find((p) => p.id === "qwen38-27b");
|
|
1212
|
-
const map = parseHashMap();
|
|
1213
|
-
const preset = map?.preset ? PRESETS.find((p) => p.id === map.preset) : null;
|
|
1214
|
-
if (!map || (!preset && map.params == null && map.file == null)) {
|
|
1215
|
-
applyPreset(fallback);
|
|
1216
|
-
return;
|
|
1217
|
-
}
|
|
1218
|
-
if (preset) {
|
|
1219
|
-
setPresetControls(preset);
|
|
1220
|
-
} else {
|
|
1221
|
-
presetId = null;
|
|
1222
|
-
fromPreset.filesize = false;
|
|
1223
|
-
fromPreset.kvpt = false;
|
|
1224
|
-
$("k-dense").checked = true;
|
|
1225
|
-
$("k-moe").checked = false;
|
|
1226
|
-
$("filesize").value = "";
|
|
1227
|
-
$("kvpt").value = "";
|
|
1228
|
-
$("i-bits").checked = true;
|
|
1229
|
-
$("i-params").checked = false;
|
|
1230
|
-
selected = null;
|
|
1231
|
-
}
|
|
1232
|
-
const shapeMatchesPreset = !preset || (
|
|
1233
|
-
(map.kind == null || map.kind === (preset.active ? "moe" : "dense"))
|
|
1234
|
-
&& (map.params == null || Number(map.params) === preset.params)
|
|
1235
|
-
&& (map.active == null || Number(map.active) === preset.active)
|
|
1236
|
-
&& (map.att == null || map.att === preset.attention)
|
|
1237
|
-
&& (map.quant == null || map.quant === preset.quant)
|
|
1238
|
-
);
|
|
1239
|
-
if (!shapeMatchesPreset) {
|
|
1240
|
-
presetId = null;
|
|
1241
|
-
if (map.file == null && map.infer !== "params") {
|
|
1242
|
-
$("filesize").value = "";
|
|
1243
|
-
fromPreset.filesize = false;
|
|
1244
|
-
}
|
|
1245
|
-
if (map.kvpt == null) {
|
|
1246
|
-
$("kvpt").value = "";
|
|
1247
|
-
fromPreset.kvpt = false;
|
|
1248
|
-
}
|
|
1249
|
-
}
|
|
1250
|
-
if (map.kind === "moe") { $("k-moe").checked = true; $("k-dense").checked = false; }
|
|
1251
|
-
else if (map.kind === "dense") { $("k-dense").checked = true; $("k-moe").checked = false; }
|
|
1252
|
-
if (map.params != null) {
|
|
1253
|
-
const pVal = Number(map.params);
|
|
1254
|
-
if (Number.isFinite(pVal) && pVal > 0) $("params").value = map.params;
|
|
1255
|
-
}
|
|
1256
|
-
if (map.active != null) {
|
|
1257
|
-
const aVal = Number(map.active);
|
|
1258
|
-
if (Number.isFinite(aVal) && aVal > 0) $("active").value = map.active;
|
|
1259
|
-
}
|
|
1260
|
-
if (map.att && ["full", "swa", "hybrid", "mla"].includes(map.att)) $("attention").value = map.att;
|
|
1261
|
-
if (map.kvpt != null) {
|
|
1262
|
-
if (map.kvpt === "") { $("kvpt").value = ""; fromPreset.kvpt = false; }
|
|
1263
|
-
else {
|
|
1264
|
-
const kVal = Number(map.kvpt);
|
|
1265
|
-
if (Number.isFinite(kVal) && kVal >= 0) {
|
|
1266
|
-
$("kvpt").value = map.kvpt;
|
|
1267
|
-
if (!preset || kVal !== preset.kv) fromPreset.kvpt = false;
|
|
1268
|
-
}
|
|
1269
|
-
}
|
|
1270
|
-
}
|
|
1271
|
-
applyQuantParam(map.quant, map.bits);
|
|
1272
|
-
if (map.file != null) {
|
|
1273
|
-
if (map.file === "") { $("filesize").value = ""; fromPreset.filesize = false; }
|
|
1274
|
-
else {
|
|
1275
|
-
const fVal = Number(map.file);
|
|
1276
|
-
if (Number.isFinite(fVal) && fVal > 0) {
|
|
1277
|
-
$("filesize").value = map.file;
|
|
1278
|
-
if (!preset || fVal !== preset.file) {
|
|
1279
|
-
fromPreset.filesize = false;
|
|
1280
|
-
presetId = null;
|
|
1281
|
-
}
|
|
1282
|
-
}
|
|
1283
|
-
}
|
|
1284
|
-
}
|
|
1285
|
-
if (map.infer === "params") { $("i-params").checked = true; $("i-bits").checked = false; presetId = null; }
|
|
1286
|
-
else if (map.infer === "bits") { $("i-bits").checked = true; $("i-params").checked = false; }
|
|
1287
|
-
const ctxIdx = parseCtxIndex(map.ctx);
|
|
1288
|
-
if (ctxIdx != null) $("ctx").value = String(ctxIdx);
|
|
1289
|
-
if (map.slots != null) {
|
|
1290
|
-
const sVal = Number(map.slots);
|
|
1291
|
-
if (Number.isFinite(sVal) && sVal >= 1) $("slots").value = String(Math.round(sVal));
|
|
1292
|
-
}
|
|
1293
|
-
if (map.kv && ["f16", "fp8", "q8_0", "q4_0"].includes(map.kv)) $("kvtype").value = map.kv;
|
|
1294
|
-
if (map.ram != null) {
|
|
1295
|
-
const rVal = Number(map.ram);
|
|
1296
|
-
if (Number.isFinite(rVal) && rVal >= 0) $("hostram").value = map.ram;
|
|
1297
|
-
}
|
|
1298
|
-
last = null;
|
|
1299
|
-
update();
|
|
1300
|
-
if (!last) applyPreset(fallback);
|
|
1301
|
-
}
|
|
1302
|
-
syncPinButton();
|
|
1303
|
-
initFromHash();
|
|
1304
|
-
addEventListener("hashchange", initFromHash);
|
|
1305
|
-
})();
|
|
1306
|
-
if (typeof module !== "undefined") module.exports = { zhMsg };
|