@simplexai/localmodels-linux-arm64 0.1.0-dev.103 → 0.1.0-dev.105
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 +159 -158
- package/modules/localmodels/__init__.py +1 -1
- package/modules/localmodels/__main__.py +204 -86
- package/modules/localmodels/apple_sensors.py +23 -0
- package/modules/localmodels/approval.py +25 -2
- package/modules/localmodels/catalog.json +584 -158
- package/modules/localmodels/catalog.py +18 -3
- package/modules/localmodels/catalog_recipes.py +64 -6
- package/modules/localmodels/cli_help.py +10 -0
- package/modules/localmodels/cli_parser.py +313 -230
- package/modules/localmodels/component.py +21 -3
- package/modules/localmodels/console.py +1 -1
- package/modules/localmodels/context_policy.py +6 -5
- package/modules/localmodels/custom_probe.py +4 -2
- 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/deploy.py +11 -1
- 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 +61 -24
- 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/host_sensors.py +25 -2
- package/modules/localmodels/hosts.py +38 -21
- package/modules/localmodels/kokoro-tts-0.6.1.txt +1 -1
- package/modules/localmodels/library_cli.py +34 -16
- package/modules/localmodels/library_custom.py +9 -1
- package/modules/localmodels/library_direct.py +41 -1
- package/modules/localmodels/library_elastic.py +135 -6
- package/modules/localmodels/library_jobs.py +23 -4
- package/modules/localmodels/library_kept.py +9 -1
- package/modules/localmodels/library_model.py +174 -2
- package/modules/localmodels/library_order.py +175 -69
- package/modules/localmodels/library_poly.py +150 -21
- package/modules/localmodels/library_presentation.py +485 -0
- package/modules/localmodels/library_pricing.py +15 -4
- package/modules/localmodels/library_serve.py +342 -70
- package/modules/localmodels/library_smoke.py +63 -5
- package/modules/localmodels/library_state.py +48 -10
- package/modules/localmodels/library_status.py +37 -17
- package/modules/localmodels/llm_rank.py +22 -11
- package/modules/localmodels/metal.py +1 -2
- package/modules/localmodels/plan_envelope.py +40 -13
- 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/probe.py +34 -7
- package/modules/localmodels/py.typed +0 -0
- package/modules/localmodels/quant_formats.py +10 -3
- package/modules/localmodels/recommend_cli.py +1 -1
- package/modules/localmodels/records.py +19 -2
- package/modules/localmodels/remote_ops_launchd.py +8 -1
- package/modules/localmodels/remote_ops_verify.py +91 -24
- package/modules/localmodels/runtime_index.py +303 -0
- 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 +94 -73
- 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 +30 -16
- package/modules/localmodels/speech_jobs.py +42 -17
- package/modules/localmodels/speech_serve.py +9 -2
- package/modules/localmodels/speech_server.py +185 -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 +276 -145
- package/modules/localmodels/stack_auto.py +91 -6
- package/modules/localmodels/stack_aux_gpu.py +1 -1
- package/modules/localmodels/stack_cleanup.py +21 -18
- package/modules/localmodels/stack_cli.py +120 -115
- package/modules/localmodels/stack_compose.py +16 -5
- package/modules/localmodels/stack_debug.py +15 -6
- package/modules/localmodels/stack_decision.py +4 -4
- package/modules/localmodels/stack_doctor.py +2 -2
- package/modules/localmodels/stack_down.py +2 -0
- package/modules/localmodels/stack_events.py +1 -1
- package/modules/localmodels/stack_gpu_memory.py +1 -1
- package/modules/localmodels/stack_hardware.py +17 -15
- package/modules/localmodels/stack_mcp.py +1 -2
- package/modules/localmodels/stack_mlx.py +8 -1
- package/modules/localmodels/stack_picks.py +20 -21
- package/modules/localmodels/stack_plan.py +12 -11
- package/modules/localmodels/stack_ports.py +31 -4
- package/modules/localmodels/stack_review.py +28 -7
- package/modules/localmodels/stack_rollback.py +1 -1
- package/modules/localmodels/stack_run.py +1 -1
- package/modules/localmodels/stack_suite.py +72 -21
- package/modules/localmodels/stack_up.py +2 -0
- package/modules/localmodels/stack_view.py +180 -35
- package/modules/localmodels/stack_view_agent.py +1 -1
- package/modules/localmodels/stack_view_demo.py +2 -0
- package/modules/localmodels/stack_view_gpu.py +36 -2
- package/modules/localmodels/stack_view_schema.py +26 -3
- package/modules/localmodels/stack_view_serve.py +0 -2
- package/modules/localmodels/stack_view_slots.py +3 -1
- package/modules/localmodels/stack_view_telemetry.py +90 -4
- package/modules/localmodels/stack_view_tick.py +246 -40
- package/modules/localmodels/stack_view_words.py +9 -2
- package/modules/localmodels/stack_warm.py +2 -2
- package/modules/localmodels/stack_whatif.py +524 -41
- package/modules/localmodels/stack_whatif_html.py +900 -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 +265 -6
- package/modules/localmodels/telemetry_math.py +458 -18
- package/modules/localmodels/transport.py +8 -1
- package/modules/localmodels/tts_admission.py +2 -17
- package/modules/localmodels/tts_catalog.py +29 -1
- package/modules/localmodels/tts_cli.py +45 -22
- package/modules/localmodels/tts_http.py +10 -4
- package/modules/localmodels/tts_jobs.py +49 -19
- package/modules/localmodels/tts_serve.py +9 -2
- package/modules/localmodels/tts_server.py +1 -1
- package/modules/localmodels/tts_sidecar.py +69 -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 +297 -0
- package/modules/localmodels/win_probe.py +89 -16
- package/modules/localmodels/windows_job.py +179 -11
- package/modules/simplex_localmodels-0.1.0.dev105.dist-info/METADATA +14 -0
- package/modules/{simplex_localmodels-0.1.0.dev103.dist-info → simplex_localmodels-0.1.0.dev105.dist-info}/RECORD +151 -145
- package/modules/simplex_localmodels-0.1.0.dev105.dist-info/licenses/LICENSE +201 -0
- package/modules/simplex_localmodels-0.1.0.dev105.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.dev105.dist-info}/WHEEL +0 -0
- /package/modules/{simplex_localmodels-0.1.0.dev103.dist-info → simplex_localmodels-0.1.0.dev105.dist-info}/entry_points.txt +0 -0
- /package/modules/{simplex_localmodels-0.1.0.dev103.dist-info → simplex_localmodels-0.1.0.dev105.dist-info}/licenses/localmodels/HERMES-LICENSE +0 -0
|
@@ -0,0 +1,297 @@
|
|
|
1
|
+
/* Pure lookup & resolution engine for `localmodels stack what-if --html`.
|
|
2
|
+
* Zero hardcoded model IDs or hardware thresholds: every decision comes directly
|
|
3
|
+
* from `WHATIF_DATA` generated by Python `stack_whatif_html.page_data()`.
|
|
4
|
+
*/
|
|
5
|
+
(function (root) {
|
|
6
|
+
"use strict";
|
|
7
|
+
|
|
8
|
+
const GIB = 1073741824;
|
|
9
|
+
|
|
10
|
+
function formatWindow(tokens) {
|
|
11
|
+
if (!tokens || tokens <= 0) return "—";
|
|
12
|
+
if (tokens % 1024 === 0) return String(tokens / 1024) + "K";
|
|
13
|
+
return String(Math.round(tokens / 1000)) + "K";
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
function formatGiB(bytes, digits) {
|
|
17
|
+
if (bytes === null || bytes === undefined) return "—";
|
|
18
|
+
const d = digits === undefined ? 1 : digits;
|
|
19
|
+
return (bytes / GIB).toFixed(d) + " GiB";
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
function formatNum(n) {
|
|
23
|
+
return Number(n).toFixed(2).replace(/\.?0+$/, "");
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
function lookupBand(bands, value) {
|
|
27
|
+
if (!bands || !bands.length) return null;
|
|
28
|
+
const target = Number(value) + 1e-6;
|
|
29
|
+
let chosen = 0;
|
|
30
|
+
for (let i = bands.length - 1; i >= 0; i--) {
|
|
31
|
+
if (bands[i][0] <= target) {
|
|
32
|
+
chosen = i;
|
|
33
|
+
break;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
return { edge: bands[chosen][0], value: bands[chosen][1], index: chosen };
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
function strataPossible(policy, platform, cuda, vramUsed) {
|
|
40
|
+
if (cuda !== "13.0") return false;
|
|
41
|
+
if (platform === "linux" && vramUsed >= policy.idle_used_gib) return false;
|
|
42
|
+
if (platform === "win32" && vramUsed > policy.wddm_baseline_cap_gib) return false;
|
|
43
|
+
return true;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
function cloneResult(raw, stripPassedOver) {
|
|
47
|
+
const out = Object.assign({}, raw);
|
|
48
|
+
let reasons = Array.isArray(raw.reasons) ? raw.reasons.slice() : [];
|
|
49
|
+
if (stripPassedOver) {
|
|
50
|
+
reasons = reasons.filter(function (line) {
|
|
51
|
+
return !String(line).startsWith("LLM: auto passed over");
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
out.reasons = reasons;
|
|
55
|
+
return out;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
function resolveNvidia(data, state) {
|
|
59
|
+
const policy = data.policy;
|
|
60
|
+
const platform = state.platform === "linux" ? "linux" : "win32";
|
|
61
|
+
const vram = Number(state.vram);
|
|
62
|
+
const ram = Number(state.ram);
|
|
63
|
+
const ramAvail = Math.max(0, Math.min(Number(state.ram_avail), ram));
|
|
64
|
+
const vramUsed = Math.max(0, Math.min(Number(state.vram_used || 0), vram - 1));
|
|
65
|
+
const cuda = String(state.cuda || "13.0");
|
|
66
|
+
const prefer = String(state.prefer || "smartest");
|
|
67
|
+
const decision = String(state.decision || "none");
|
|
68
|
+
|
|
69
|
+
const effPrefer = prefer;
|
|
70
|
+
let effCuda = cuda;
|
|
71
|
+
const stripPassedOver = false;
|
|
72
|
+
if (!strataPossible(policy, platform, cuda, vramUsed) && cuda === "13.0") {
|
|
73
|
+
effCuda = "12.8";
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
const effStrata = strataPossible(policy, platform, effCuda, vramUsed);
|
|
77
|
+
const buckets = (data.nvidia_ram_buckets || {})[String(vram)] || {};
|
|
78
|
+
const ramKey = effStrata ? String(buckets[String(ram)] || ram) : "*";
|
|
79
|
+
const key = [platform, vram, ramKey, effCuda, vramUsed, effPrefer, decision].join("|");
|
|
80
|
+
const curve = data.nvidia[key] || [];
|
|
81
|
+
const hit = lookupBand(curve, ramAvail);
|
|
82
|
+
const result = hit ? cloneResult(data.results[hit.value], stripPassedOver) : null;
|
|
83
|
+
|
|
84
|
+
const libStrata = strataPossible(policy, platform, cuda, vramUsed);
|
|
85
|
+
const libCuda = !libStrata && cuda === "13.0" ? "12.8" : cuda;
|
|
86
|
+
const libRamKey = libStrata ? String(buckets[String(ram)] || ram) : "*";
|
|
87
|
+
const libKey = [platform, vram, libRamKey, libCuda, vramUsed].join("|");
|
|
88
|
+
const libCurve = (data.library && data.library.nvidia && data.library.nvidia[libKey]) || [];
|
|
89
|
+
const libHit = lookupBand(libCurve, ramAvail);
|
|
90
|
+
|
|
91
|
+
return {
|
|
92
|
+
mode: "nvidia",
|
|
93
|
+
result: result,
|
|
94
|
+
library: libHit ? libHit.value : null,
|
|
95
|
+
curve: curve,
|
|
96
|
+
curveKey: key,
|
|
97
|
+
effectiveAvail: ramAvail,
|
|
98
|
+
rawAvail: ramAvail,
|
|
99
|
+
ramTotal: ram,
|
|
100
|
+
vramTotal: vram,
|
|
101
|
+
vramUsed: vramUsed,
|
|
102
|
+
vramFree: Math.max(0, vram - vramUsed),
|
|
103
|
+
strataAllowed: strataPossible(policy, platform, cuda, vramUsed),
|
|
104
|
+
stripPassedOver: stripPassedOver,
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
function resolveMac(data, state) {
|
|
109
|
+
const policy = data.policy;
|
|
110
|
+
const total = Number(state.mac_total);
|
|
111
|
+
const tier = data.mac.tiers[String(total)] || {
|
|
112
|
+
working_set_gib: total * 0.75,
|
|
113
|
+
reserve_gib: 3,
|
|
114
|
+
ceiling_gib: total - 3,
|
|
115
|
+
};
|
|
116
|
+
const rawAvail = Math.max(0, Math.min(Number(state.mac_avail), total));
|
|
117
|
+
const pressure = Number(state.pressure || 1);
|
|
118
|
+
const prefer = String(state.prefer || "smartest");
|
|
119
|
+
const decision = String(state.decision || "none");
|
|
120
|
+
|
|
121
|
+
if (pressure === 4) {
|
|
122
|
+
return {
|
|
123
|
+
mode: "mac",
|
|
124
|
+
result: cloneResult(data.results[data.mac.critical_result], false),
|
|
125
|
+
library: null,
|
|
126
|
+
curve: [],
|
|
127
|
+
effectiveAvail: 0,
|
|
128
|
+
rawAvail: rawAvail,
|
|
129
|
+
pressureKept: rawAvail,
|
|
130
|
+
tier: tier,
|
|
131
|
+
total: total,
|
|
132
|
+
pressure: pressure,
|
|
133
|
+
};
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
const kept = pressure === 2 ? rawAvail * policy.warn_keep_fraction : 0;
|
|
137
|
+
const effAvail = Math.max(0, rawAvail - kept);
|
|
138
|
+
const effPrefer = prefer === "concurrent" ? "smartest" : prefer;
|
|
139
|
+
const key = [total, effPrefer, decision].join("|");
|
|
140
|
+
const curve = data.mac.curves[key] || [];
|
|
141
|
+
const hit = lookupBand(curve, effAvail);
|
|
142
|
+
const result = hit ? cloneResult(data.results[hit.value], false) : null;
|
|
143
|
+
if (result && pressure === 2) {
|
|
144
|
+
const pct = Math.round(policy.warn_keep_fraction * 100);
|
|
145
|
+
result.reasons.unshift(
|
|
146
|
+
"macOS memory pressure is at warning; " +
|
|
147
|
+
kept.toFixed(1) +
|
|
148
|
+
" GB (" +
|
|
149
|
+
pct +
|
|
150
|
+
"% of the memory available) is kept back so loading the stack does not push it to critical"
|
|
151
|
+
);
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
const libCurve = (data.library && data.library.mac && data.library.mac[String(total)]) || [];
|
|
155
|
+
const libHit = lookupBand(libCurve, effAvail);
|
|
156
|
+
|
|
157
|
+
return {
|
|
158
|
+
mode: "mac",
|
|
159
|
+
result: result,
|
|
160
|
+
library: libHit ? libHit.value : null,
|
|
161
|
+
curve: curve,
|
|
162
|
+
curveKey: key,
|
|
163
|
+
effectiveAvail: effAvail,
|
|
164
|
+
rawAvail: rawAvail,
|
|
165
|
+
pressureKept: kept,
|
|
166
|
+
tier: tier,
|
|
167
|
+
total: total,
|
|
168
|
+
pressure: pressure,
|
|
169
|
+
};
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
function resolveOtherUnified(data, state) {
|
|
173
|
+
const vendor = String(state.other_vendor || "cuda-uma");
|
|
174
|
+
const total = Number(state.other_total || 64);
|
|
175
|
+
const prefer = String(state.prefer || "smartest");
|
|
176
|
+
const key = [vendor, total, prefer].join("|");
|
|
177
|
+
const entry = data.other_unified[key];
|
|
178
|
+
return {
|
|
179
|
+
mode: "other_unified",
|
|
180
|
+
result: entry ? cloneResult(data.results[entry.result], false) : null,
|
|
181
|
+
library: entry ? entry.library : null,
|
|
182
|
+
curve: [],
|
|
183
|
+
vendor: vendor,
|
|
184
|
+
total: total,
|
|
185
|
+
};
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
function buildCommand(state) {
|
|
189
|
+
const parts = ["python3 -m localmodels stack plan --llm auto"];
|
|
190
|
+
if (state.prefer && state.prefer !== "smartest") {
|
|
191
|
+
parts.push("--prefer " + state.prefer);
|
|
192
|
+
}
|
|
193
|
+
if (state.decision && state.decision !== "none") {
|
|
194
|
+
parts.push("--decision " + state.decision);
|
|
195
|
+
}
|
|
196
|
+
if (state.mode === "mac") {
|
|
197
|
+
parts.push("--unified-memory " + state.mac_total + "GiB");
|
|
198
|
+
}
|
|
199
|
+
return parts.join(" ");
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
function buildWhatifCommand(state) {
|
|
203
|
+
const parts = ["python3 -m localmodels stack what-if"];
|
|
204
|
+
if (state.mode === "mac") {
|
|
205
|
+
parts.push("--unified-memory " + state.mac_total + "GiB");
|
|
206
|
+
parts.push("--ram-available " + formatNum(state.mac_avail) + "GiB");
|
|
207
|
+
if (Number(state.pressure) !== 1) {
|
|
208
|
+
parts.push("--pressure " + state.pressure);
|
|
209
|
+
}
|
|
210
|
+
} else if (state.mode === "nvidia") {
|
|
211
|
+
parts.push("--platform " + (state.platform === "linux" ? "linux" : "windows"));
|
|
212
|
+
parts.push("--vram " + state.vram + "GiB");
|
|
213
|
+
parts.push("--ram " + state.ram + "GiB");
|
|
214
|
+
parts.push("--ram-available " + formatNum(state.ram_avail) + "GiB");
|
|
215
|
+
if (state.cuda && state.cuda !== "13.0") {
|
|
216
|
+
parts.push("--cuda " + state.cuda);
|
|
217
|
+
}
|
|
218
|
+
if (Number(state.vram_used) > 0) {
|
|
219
|
+
parts.push("--vram-used " + state.vram_used + "GiB");
|
|
220
|
+
}
|
|
221
|
+
} else {
|
|
222
|
+
return "python3 -m localmodels library status";
|
|
223
|
+
}
|
|
224
|
+
if (state.prefer && state.prefer !== "smartest") {
|
|
225
|
+
parts.push("--prefer " + state.prefer);
|
|
226
|
+
}
|
|
227
|
+
if (state.decision && state.decision !== "none") {
|
|
228
|
+
parts.push("--decision " + state.decision);
|
|
229
|
+
}
|
|
230
|
+
return parts.join(" ");
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
function resolve(data, state) {
|
|
234
|
+
let out;
|
|
235
|
+
if (state.mode === "mac") {
|
|
236
|
+
out = resolveMac(data, state);
|
|
237
|
+
} else if (state.mode === "other_unified") {
|
|
238
|
+
out = resolveOtherUnified(data, state);
|
|
239
|
+
} else {
|
|
240
|
+
out = resolveNvidia(data, state);
|
|
241
|
+
}
|
|
242
|
+
out.command = buildCommand(state);
|
|
243
|
+
out.whatifCommand = buildWhatifCommand(state);
|
|
244
|
+
return out;
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
function extractRulerBands(data, curve, maxGib) {
|
|
248
|
+
if (!curve || !curve.length) return [];
|
|
249
|
+
const clipped = [];
|
|
250
|
+
for (let i = 0; i < curve.length; i++) {
|
|
251
|
+
const low = Number(curve[i][0]);
|
|
252
|
+
if (low > maxGib + 1e-6) break;
|
|
253
|
+
const nextLow = i + 1 < curve.length ? Math.min(maxGib, Number(curve[i + 1][0])) : maxGib;
|
|
254
|
+
const res = data.results[curve[i][1]];
|
|
255
|
+
if (clipped.length) {
|
|
256
|
+
const prev = clipped[clipped.length - 1];
|
|
257
|
+
const same =
|
|
258
|
+
prev.result.ok === res.ok &&
|
|
259
|
+
prev.result.id === res.id &&
|
|
260
|
+
prev.result.quant === res.quant &&
|
|
261
|
+
prev.result.engine === res.engine &&
|
|
262
|
+
prev.result.window === res.window &&
|
|
263
|
+
prev.result.slots === res.slots &&
|
|
264
|
+
prev.result.decision_id === res.decision_id &&
|
|
265
|
+
JSON.stringify(prev.result.kv_types) === JSON.stringify(res.kv_types);
|
|
266
|
+
if (same) {
|
|
267
|
+
prev.max = nextLow;
|
|
268
|
+
continue;
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
clipped.push({ min: low, max: nextLow, result: res });
|
|
272
|
+
}
|
|
273
|
+
return clipped.reverse();
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
const api = {
|
|
277
|
+
GIB: GIB,
|
|
278
|
+
formatWindow: formatWindow,
|
|
279
|
+
formatGiB: formatGiB,
|
|
280
|
+
formatNum: formatNum,
|
|
281
|
+
lookupBand: lookupBand,
|
|
282
|
+
strataPossible: strataPossible,
|
|
283
|
+
resolveNvidia: resolveNvidia,
|
|
284
|
+
resolveMac: resolveMac,
|
|
285
|
+
resolveOtherUnified: resolveOtherUnified,
|
|
286
|
+
resolve: resolve,
|
|
287
|
+
buildCommand: buildCommand,
|
|
288
|
+
buildWhatifCommand: buildWhatifCommand,
|
|
289
|
+
extractRulerBands: extractRulerBands,
|
|
290
|
+
};
|
|
291
|
+
|
|
292
|
+
if (typeof module !== "undefined" && module.exports) {
|
|
293
|
+
module.exports = api;
|
|
294
|
+
} else {
|
|
295
|
+
root.WHATIF_SIM = api;
|
|
296
|
+
}
|
|
297
|
+
})(typeof globalThis !== "undefined" ? globalThis : window);
|
|
@@ -47,11 +47,14 @@ _GPU_PROC_MEM_PS = (
|
|
|
47
47
|
"$local = if ($null -ne $lp -and $null -ne $lp.Value) { [int64]$lp.Value } else { $null }; "
|
|
48
48
|
"$dp = $_.PSObject.Properties['DedicatedUsage']; "
|
|
49
49
|
"$ded = if ($null -ne $dp -and $null -ne $dp.Value) { [int64]$dp.Value } else { $null }; "
|
|
50
|
+
"$sp = $_.PSObject.Properties['SharedUsage']; "
|
|
51
|
+
"$shared = if ($null -ne $sp -and $null -ne $sp.Value) { [int64]$sp.Value } else { $null }; "
|
|
50
52
|
"$usage = if ($null -ne $local) { $local } else { $ded }; "
|
|
51
|
-
"if ($null -ne $usage -and $usage -gt 0 -and $
|
|
53
|
+
"if ((($null -ne $usage -and $usage -gt 0) -or ($null -ne $shared -and $shared -gt 0)) "
|
|
54
|
+
"-and $_.Name -match 'pid_(\\d+)_') { "
|
|
52
55
|
"$p = [int]$Matches[1]; "
|
|
53
56
|
"if ($procs.ContainsKey($p)) { "
|
|
54
|
-
"[PSCustomObject]@{ pid = $p; name = $procs[$p]; local_bytes = $local; dedicated_bytes = $ded } "
|
|
57
|
+
"[PSCustomObject]@{ pid = $p; name = $procs[$p]; local_bytes = $local; dedicated_bytes = $ded; shared_bytes = $shared } "
|
|
55
58
|
"} } }); "
|
|
56
59
|
"$rows | ConvertTo-Json -Compress"
|
|
57
60
|
)
|
|
@@ -128,6 +131,21 @@ def _row_bytes(row: Mapping[str, Any]) -> int | None:
|
|
|
128
131
|
return raw if isinstance(raw, int) and not isinstance(raw, bool) else None
|
|
129
132
|
|
|
130
133
|
|
|
134
|
+
def _parse_cim_rows(raw_json: str) -> list[dict[str, Any]]:
|
|
135
|
+
text = raw_json.strip()
|
|
136
|
+
if not text:
|
|
137
|
+
return []
|
|
138
|
+
try:
|
|
139
|
+
parsed = json.loads(text)
|
|
140
|
+
except ValueError:
|
|
141
|
+
return []
|
|
142
|
+
if isinstance(parsed, dict):
|
|
143
|
+
return [parsed]
|
|
144
|
+
if isinstance(parsed, list):
|
|
145
|
+
return [row for row in parsed if isinstance(row, dict)]
|
|
146
|
+
return []
|
|
147
|
+
|
|
148
|
+
|
|
131
149
|
def parse_gpu_process_memory(
|
|
132
150
|
raw_json: str,
|
|
133
151
|
*,
|
|
@@ -136,19 +154,12 @@ def parse_gpu_process_memory(
|
|
|
136
154
|
limit: int = _MAX_GPU_APPS,
|
|
137
155
|
) -> list[GpuAppMemory]:
|
|
138
156
|
"""Aggregate locale-independent Windows CIM GPUProcessMemory rows by process name."""
|
|
139
|
-
|
|
140
|
-
if not
|
|
157
|
+
rows = _parse_cim_rows(raw_json)
|
|
158
|
+
if not rows:
|
|
141
159
|
return []
|
|
142
|
-
try:
|
|
143
|
-
parsed = json.loads(text)
|
|
144
|
-
except ValueError:
|
|
145
|
-
return []
|
|
146
|
-
rows = [parsed] if isinstance(parsed, dict) else parsed if isinstance(parsed, list) else []
|
|
147
160
|
skip_pids = exclude_pids or set()
|
|
148
161
|
grouped: dict[str, tuple[str, int, set[int]]] = {}
|
|
149
162
|
for row in rows:
|
|
150
|
-
if not isinstance(row, dict):
|
|
151
|
-
continue
|
|
152
163
|
raw_name = row.get("name")
|
|
153
164
|
raw_pid = row.get("pid")
|
|
154
165
|
raw_bytes = _row_bytes(row)
|
|
@@ -182,8 +193,42 @@ def parse_gpu_process_memory(
|
|
|
182
193
|
]
|
|
183
194
|
|
|
184
195
|
|
|
185
|
-
def
|
|
186
|
-
|
|
196
|
+
def parse_wddm_shared_spill_bytes(
|
|
197
|
+
raw_json: str,
|
|
198
|
+
*,
|
|
199
|
+
include_pids: set[int] | None = None,
|
|
200
|
+
exclude_pids: set[int] | None = None,
|
|
201
|
+
) -> int | None:
|
|
202
|
+
"""Sum WDDM ``SharedUsage`` (``shared_bytes``) across Windows CIM ``GPUProcessMemory`` rows.
|
|
203
|
+
|
|
204
|
+
Returns ``None`` when the payload carries no valid ``shared_bytes`` / ``SharedUsage`` fields.
|
|
205
|
+
"""
|
|
206
|
+
rows = _parse_cim_rows(raw_json)
|
|
207
|
+
if not rows:
|
|
208
|
+
return None
|
|
209
|
+
skip_pids = exclude_pids or set()
|
|
210
|
+
total = 0
|
|
211
|
+
seen_any = False
|
|
212
|
+
for row in rows:
|
|
213
|
+
raw_pid = row.get("pid")
|
|
214
|
+
pid = raw_pid if isinstance(raw_pid, int) and not isinstance(raw_pid, bool) else None
|
|
215
|
+
if pid is not None:
|
|
216
|
+
if pid in skip_pids:
|
|
217
|
+
continue
|
|
218
|
+
if include_pids is not None and pid not in include_pids:
|
|
219
|
+
continue
|
|
220
|
+
elif include_pids is not None:
|
|
221
|
+
continue
|
|
222
|
+
raw_shared = row.get("shared_bytes")
|
|
223
|
+
if raw_shared is None and "SharedUsage" in row:
|
|
224
|
+
raw_shared = row.get("SharedUsage")
|
|
225
|
+
if isinstance(raw_shared, int) and not isinstance(raw_shared, bool) and raw_shared >= 0:
|
|
226
|
+
total += raw_shared
|
|
227
|
+
seen_any = True
|
|
228
|
+
return total if seen_any else None
|
|
229
|
+
|
|
230
|
+
|
|
231
|
+
def _query_gpu_process_memory_raw(timeout: float = 4.0) -> str | None:
|
|
187
232
|
flags = int(getattr(subprocess, "CREATE_NO_WINDOW", 0))
|
|
188
233
|
try:
|
|
189
234
|
proc = subprocess.run(
|
|
@@ -198,7 +243,35 @@ def gpu_process_memory(timeout: float = 4.0) -> list[GpuAppMemory]:
|
|
|
198
243
|
creationflags=flags,
|
|
199
244
|
)
|
|
200
245
|
except (OSError, subprocess.TimeoutExpired):
|
|
201
|
-
return
|
|
246
|
+
return None
|
|
202
247
|
if proc.returncode != 0 or not proc.stdout.strip():
|
|
203
|
-
return
|
|
204
|
-
return
|
|
248
|
+
return None
|
|
249
|
+
return proc.stdout
|
|
250
|
+
|
|
251
|
+
|
|
252
|
+
def gpu_memory_snapshot(timeout: float = 4.0) -> tuple[list[GpuAppMemory], int | None]:
|
|
253
|
+
"""Single CIM query returning ``(closeable_local_vram_apps, wddm_shared_spill_bytes)``."""
|
|
254
|
+
raw = _query_gpu_process_memory_raw(timeout=timeout)
|
|
255
|
+
if raw is None:
|
|
256
|
+
return [], None
|
|
257
|
+
own_pid = {os.getpid()}
|
|
258
|
+
return (
|
|
259
|
+
parse_gpu_process_memory(raw, exclude_pids=own_pid),
|
|
260
|
+
parse_wddm_shared_spill_bytes(raw, exclude_pids=own_pid),
|
|
261
|
+
)
|
|
262
|
+
|
|
263
|
+
|
|
264
|
+
def gpu_process_memory(timeout: float = 4.0) -> list[GpuAppMemory]:
|
|
265
|
+
"""Top closeable Windows desktop processes holding local GPU VRAM via CIM."""
|
|
266
|
+
apps, _ = gpu_memory_snapshot(timeout=timeout)
|
|
267
|
+
return apps
|
|
268
|
+
|
|
269
|
+
|
|
270
|
+
def wddm_shared_spill_bytes(
|
|
271
|
+
timeout: float = 4.0, *, include_pids: set[int] | None = None
|
|
272
|
+
) -> int | None:
|
|
273
|
+
"""Total WDDM shared GPU memory bytes (implicit VRAM->RAM spill) from CIM ``SharedUsage``."""
|
|
274
|
+
raw = _query_gpu_process_memory_raw(timeout=timeout)
|
|
275
|
+
if raw is None:
|
|
276
|
+
return None
|
|
277
|
+
return parse_wddm_shared_spill_bytes(raw, include_pids=include_pids, exclude_pids={os.getpid()})
|
|
@@ -1,28 +1,144 @@
|
|
|
1
|
-
"""Windows:
|
|
1
|
+
"""Windows: Job Object lifetime, CPU affinity, and shared core-reservation policy.
|
|
2
|
+
|
|
3
|
+
Pure CPU-split helpers (``reserved_speech_cores``, ``poly_cpu_threads``,
|
|
4
|
+
``split_affinity_masks``, ``parse_affinity_override``) run on every platform so planning and
|
|
5
|
+
tests share one rule with the Windows runtime.
|
|
6
|
+
"""
|
|
2
7
|
|
|
3
8
|
from __future__ import annotations
|
|
4
9
|
|
|
5
10
|
import ctypes
|
|
11
|
+
import os
|
|
6
12
|
import sys
|
|
13
|
+
from collections.abc import Mapping
|
|
7
14
|
from typing import Any
|
|
8
15
|
|
|
16
|
+
_AFFINITY = 0x0010 # JOB_OBJECT_LIMIT_AFFINITY
|
|
9
17
|
_KILL_ON_JOB_CLOSE = 0x2000 # JOB_OBJECT_LIMIT_KILL_ON_JOB_CLOSE
|
|
10
18
|
# JOB_OBJECT_LIMIT_BREAKAWAY_OK: a service the helper starts with CREATE_BREAKAWAY_FROM_JOB
|
|
11
19
|
# (process_identity.spawn_detached) leaves the job and outlives the CLI; without it the model
|
|
12
|
-
# server stayed in the job and died with the load command (
|
|
20
|
+
# server stayed in the job and died with the load command (Windows job verification).
|
|
13
21
|
_BREAKAWAY_OK = 0x0800
|
|
14
22
|
_EXTENDED_LIMITS = 9 # JobObjectExtendedLimitInformation
|
|
15
23
|
_JOBS: list[Any] = [] # this process's job handles: closed by Windows when it ends, however
|
|
16
24
|
|
|
25
|
+
SPEECH_AFFINITY_ENV = "LOCALMODELS_SPEECH_CPU_AFFINITY"
|
|
26
|
+
POLY_AFFINITY_ENV = "LOCALMODELS_POLY_CPU_AFFINITY"
|
|
27
|
+
_DISABLE_VALUES = frozenset(("0", "off", "false", "none"))
|
|
17
28
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
29
|
+
|
|
30
|
+
def reserved_speech_cores(logical_cores: int) -> int:
|
|
31
|
+
"""Logical cores kept back from PolyStrata for speech and desktop responsiveness."""
|
|
32
|
+
if logical_cores >= 12:
|
|
33
|
+
return 4
|
|
34
|
+
if logical_cores >= 6:
|
|
35
|
+
return 2
|
|
36
|
+
return 0
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
def poly_cpu_threads(logical_cores: int) -> int:
|
|
40
|
+
"""Default ``--threads`` for PolyStrata CPU expert compute, leaving headroom for speech."""
|
|
41
|
+
cores = max(1, logical_cores)
|
|
42
|
+
reserve = reserved_speech_cores(cores)
|
|
43
|
+
if reserve > 0:
|
|
44
|
+
return max(1, cores - reserve)
|
|
45
|
+
return max(1, cores - 1)
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
def split_affinity_masks(
|
|
49
|
+
available_mask: int,
|
|
50
|
+
*,
|
|
51
|
+
min_speech_cores: int = 1,
|
|
52
|
+
) -> tuple[int, int] | None:
|
|
53
|
+
"""Split ``available_mask`` into disjoint ``(poly_mask, speech_mask)`` bitmasks.
|
|
54
|
+
|
|
55
|
+
Reserves the highest-index logical CPUs for speech (keeping CPU 0 and Intel P-cores with
|
|
56
|
+
PolyStrata while guaranteeing a PolyStrata-free slice for speech). Returns ``None`` when
|
|
57
|
+
too few CPUs are available to reserve at least ``min_speech_cores``.
|
|
58
|
+
"""
|
|
59
|
+
if available_mask <= 0:
|
|
60
|
+
return None
|
|
61
|
+
cpus = [bit for bit in range(available_mask.bit_length()) if available_mask & (1 << bit)]
|
|
62
|
+
reserve = reserved_speech_cores(len(cpus))
|
|
63
|
+
if reserve <= 0 or reserve < min_speech_cores or len(cpus) <= reserve:
|
|
64
|
+
return None
|
|
65
|
+
speech_mask = sum(1 << bit for bit in cpus[-reserve:])
|
|
66
|
+
poly_mask = available_mask & ~speech_mask
|
|
67
|
+
if poly_mask <= 0 or speech_mask <= 0:
|
|
68
|
+
return None
|
|
69
|
+
return poly_mask, speech_mask
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
def parse_affinity_override(raw: str | None, available_mask: int) -> int | None:
|
|
73
|
+
"""Parse an explicit CPU affinity env override (``off`` -> 0, int/hex -> clamped mask).
|
|
74
|
+
|
|
75
|
+
Returns ``None`` when unset/blank so the caller applies its default policy.
|
|
76
|
+
"""
|
|
77
|
+
if raw is None:
|
|
78
|
+
return None
|
|
79
|
+
cleaned = raw.strip().lower()
|
|
80
|
+
if not cleaned:
|
|
81
|
+
return None
|
|
82
|
+
if cleaned in _DISABLE_VALUES:
|
|
83
|
+
return 0
|
|
84
|
+
try:
|
|
85
|
+
parsed = int(cleaned, 0)
|
|
86
|
+
except ValueError:
|
|
87
|
+
return 0
|
|
88
|
+
if parsed <= 0 or available_mask <= 0:
|
|
89
|
+
return 0
|
|
90
|
+
return parsed & available_mask
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
def process_affinity_mask(handle: int | None = None) -> int | None:
|
|
94
|
+
"""Windows: active processor-group affinity mask for ``handle`` (default: current process)."""
|
|
24
95
|
if sys.platform != "win32":
|
|
25
|
-
return
|
|
96
|
+
return None
|
|
97
|
+
from ctypes import wintypes
|
|
98
|
+
|
|
99
|
+
kernel = ctypes.WinDLL("kernel32", use_last_error=True)
|
|
100
|
+
h = wintypes.HANDLE
|
|
101
|
+
kernel.GetCurrentProcess.argtypes, kernel.GetCurrentProcess.restype = (), h
|
|
102
|
+
kernel.GetProcessAffinityMask.argtypes = (
|
|
103
|
+
h,
|
|
104
|
+
ctypes.POINTER(ctypes.c_size_t),
|
|
105
|
+
ctypes.POINTER(ctypes.c_size_t),
|
|
106
|
+
)
|
|
107
|
+
kernel.GetProcessAffinityMask.restype = wintypes.BOOL
|
|
108
|
+
target = kernel.GetCurrentProcess() if handle is None else handle
|
|
109
|
+
proc_mask = ctypes.c_size_t(0)
|
|
110
|
+
sys_mask = ctypes.c_size_t(0)
|
|
111
|
+
if not kernel.GetProcessAffinityMask(target, ctypes.byref(proc_mask), ctypes.byref(sys_mask)):
|
|
112
|
+
return None
|
|
113
|
+
mask = int(proc_mask.value)
|
|
114
|
+
return mask if mask > 0 else None
|
|
115
|
+
|
|
116
|
+
|
|
117
|
+
def speech_affinity_mask(
|
|
118
|
+
*,
|
|
119
|
+
env: Mapping[str, str] | None = None,
|
|
120
|
+
available_mask: int | None = None,
|
|
121
|
+
) -> int | None:
|
|
122
|
+
"""Exclusive 4-core CPU affinity mask for a Windows CPU speech worker, or ``None``.
|
|
123
|
+
|
|
124
|
+
Only pins speech when at least 4 cores are reserved (12+ logical CPUs) so speech's 4
|
|
125
|
+
threads are never cramped onto 2 cores. On 6-11 logical CPUs, PolyStrata is still excluded
|
|
126
|
+
from the top 2 cores while speech runs unpinned at ``ABOVE_NORMAL_PRIORITY_CLASS``.
|
|
127
|
+
"""
|
|
128
|
+
mask = process_affinity_mask() if available_mask is None else available_mask
|
|
129
|
+
if mask is None or mask <= 0:
|
|
130
|
+
return None
|
|
131
|
+
source = os.environ if env is None else env
|
|
132
|
+
override = parse_affinity_override(source.get(SPEECH_AFFINITY_ENV), mask)
|
|
133
|
+
if override is not None:
|
|
134
|
+
return override if override > 0 else None
|
|
135
|
+
split = split_affinity_masks(mask, min_speech_cores=4)
|
|
136
|
+
return split[1] if split is not None else None
|
|
137
|
+
|
|
138
|
+
|
|
139
|
+
def _windows_job_structures() -> tuple[Any, Any]:
|
|
140
|
+
if sys.platform != "win32":
|
|
141
|
+
raise RuntimeError("Windows Job Object structures require win32")
|
|
26
142
|
from ctypes import wintypes
|
|
27
143
|
|
|
28
144
|
c = ctypes.c_uint64
|
|
@@ -42,6 +158,14 @@ def end_with_this_process(handle: int) -> bool:
|
|
|
42
158
|
("peak_job", ctypes.c_size_t),
|
|
43
159
|
] # fmt: skip
|
|
44
160
|
|
|
161
|
+
return Basic, Extended
|
|
162
|
+
|
|
163
|
+
|
|
164
|
+
def _configure_kernel32() -> Any:
|
|
165
|
+
if sys.platform != "win32":
|
|
166
|
+
raise RuntimeError("kernel32 Job Object API requires win32")
|
|
167
|
+
from ctypes import wintypes
|
|
168
|
+
|
|
45
169
|
kernel = ctypes.WinDLL("kernel32", use_last_error=True)
|
|
46
170
|
h = wintypes.HANDLE
|
|
47
171
|
kernel.CreateJobObjectW.argtypes, kernel.CreateJobObjectW.restype = (
|
|
@@ -54,12 +178,27 @@ def end_with_this_process(handle: int) -> bool:
|
|
|
54
178
|
(h, h),
|
|
55
179
|
wintypes.BOOL,
|
|
56
180
|
)
|
|
181
|
+
kernel.SetProcessAffinityMask.argtypes, kernel.SetProcessAffinityMask.restype = (
|
|
182
|
+
(h, ctypes.c_size_t),
|
|
183
|
+
wintypes.BOOL,
|
|
184
|
+
)
|
|
57
185
|
kernel.CloseHandle.argtypes, kernel.CloseHandle.restype = (h,), wintypes.BOOL
|
|
186
|
+
return kernel
|
|
187
|
+
|
|
188
|
+
|
|
189
|
+
def _assign_job(handle: int, flags: int, affinity_mask: int | None = None) -> bool:
|
|
190
|
+
if sys.platform != "win32":
|
|
191
|
+
return False
|
|
192
|
+
_, extended_cls = _windows_job_structures()
|
|
193
|
+
kernel = _configure_kernel32()
|
|
58
194
|
job = kernel.CreateJobObjectW(None, None)
|
|
59
195
|
if not job:
|
|
60
196
|
return False
|
|
61
|
-
info =
|
|
62
|
-
info.basic.flags =
|
|
197
|
+
info = extended_cls()
|
|
198
|
+
info.basic.flags = flags
|
|
199
|
+
if affinity_mask is not None and affinity_mask > 0:
|
|
200
|
+
info.basic.flags |= _AFFINITY
|
|
201
|
+
info.basic.affinity = affinity_mask
|
|
63
202
|
if kernel.SetInformationJobObject(
|
|
64
203
|
job, _EXTENDED_LIMITS, ctypes.byref(info), ctypes.sizeof(info)
|
|
65
204
|
) and kernel.AssignProcessToJobObject(job, handle):
|
|
@@ -67,3 +206,32 @@ def end_with_this_process(handle: int) -> bool:
|
|
|
67
206
|
return True
|
|
68
207
|
kernel.CloseHandle(job)
|
|
69
208
|
return False
|
|
209
|
+
|
|
210
|
+
|
|
211
|
+
def end_with_this_process(handle: int, *, affinity_mask: int | None = None) -> bool:
|
|
212
|
+
"""Windows: put the process ``handle`` names in a job that this process alone holds open,
|
|
213
|
+
with kill-on-close: when this process ends, however (TerminateProcess included), Windows
|
|
214
|
+
ends that process and its children. A helper otherwise outlives a killed CLI and keeps the
|
|
215
|
+
file it writes open, so cleaning up after the CLI fails with WinError 32.
|
|
216
|
+
|
|
217
|
+
When ``affinity_mask`` is positive, also sets ``JOB_OBJECT_LIMIT_AFFINITY`` on the job,
|
|
218
|
+
falling back to kill-on-close alone if the host job hierarchy rejects the affinity limit.
|
|
219
|
+
False when the job cannot be made or assigned (the helper then ends as before)."""
|
|
220
|
+
if sys.platform != "win32":
|
|
221
|
+
return False
|
|
222
|
+
base_flags = _KILL_ON_JOB_CLOSE | _BREAKAWAY_OK
|
|
223
|
+
if affinity_mask is not None and affinity_mask > 0:
|
|
224
|
+
if _assign_job(handle, base_flags, affinity_mask):
|
|
225
|
+
return True
|
|
226
|
+
return _assign_job(handle, base_flags)
|
|
227
|
+
|
|
228
|
+
|
|
229
|
+
def restrict_process_tree_affinity(handle: int, affinity_mask: int) -> bool:
|
|
230
|
+
"""Windows: bound ``handle`` and every child it spawns to ``affinity_mask`` via a Job Object
|
|
231
|
+
without kill-on-close, falling back to ``SetProcessAffinityMask`` when nested jobs fail."""
|
|
232
|
+
if sys.platform != "win32" or affinity_mask <= 0:
|
|
233
|
+
return False
|
|
234
|
+
if _assign_job(handle, 0, affinity_mask):
|
|
235
|
+
return True
|
|
236
|
+
kernel = _configure_kernel32()
|
|
237
|
+
return bool(kernel.SetProcessAffinityMask(handle, affinity_mask))
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: simplex-localmodels
|
|
3
|
+
Version: 0.1.0.dev105
|
|
4
|
+
Summary: Detect hardware, recommend and install a verified local model stack
|
|
5
|
+
License-Expression: Apache-2.0
|
|
6
|
+
License-File: LICENSE
|
|
7
|
+
License-File: NOTICE
|
|
8
|
+
License-File: localmodels/HERMES-LICENSE
|
|
9
|
+
Classifier: License :: OSI Approved :: Apache Software License
|
|
10
|
+
Classifier: Programming Language :: Python :: 3 :: Only
|
|
11
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
12
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
13
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
14
|
+
Requires-Python: >=3.10
|