dsh-qqbot-muu 0.1.20 → 0.1.21
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/CHANGELOG.md +168 -154
- package/client/qqbot-settings.js +13401 -13380
- package/dist/config.js +573 -581
- package/dist/features/contextless-store.js +247 -247
- package/dist/features/four-source.js +338 -336
- package/dist/features/group-join-request.js +289 -287
- package/dist/features/local-models.js +1494 -1467
- package/dist/features/style-layer.js +501 -498
- package/dist/features/thinking-log.js +71 -69
- package/dist/gateway/bootstrap.js +1704 -1652
- package/dist/model/settings-reader.js +193 -102
- package/dist/shared/paths.js +128 -0
- package/dist/shared/settings-io.js +79 -83
- package/dshqqbot/.qqbot-extensions/inbound/00-vision.mjs +111 -0
- package/dshqqbot/.qqbot-extensions/inbound/aa-memory-recall.mjs +802 -794
- package/dshqqbot/.qqbot-extensions/inbound/az-feedback.mjs +113 -115
- package/dshqqbot/.qqbot-extensions/inbound/local-answer.mjs +689 -568
- package/dshqqbot/.qqbot-extensions/lib/local-llm.mjs +455 -444
- package/dshqqbot/.qqbot-extensions/lib/memory-agent.mjs +930 -928
- package/dshqqbot/.qqbot-extensions/lib/memory-core.mjs +537 -537
- package/dshqqbot/.qqbot-extensions/lib/memory-db.mjs +2476 -2245
- package/dshqqbot/.qqbot-extensions/lib/memory-hippo.mjs +18 -0
- package/dshqqbot/.qqbot-extensions/lib/memory.mjs +191 -186
- package/dshqqbot/.qqbot-extensions/lib/scope-util.mjs +84 -0
- package/dshqqbot/.qqbot-extensions/outbound/aa-sanitize.mjs +158 -154
- package/dshqqbot/.qqbot-extensions/outbound/memory-agent.mjs +121 -130
- package/dshqqbot/.qqbot-extensions/outbound/turn-memory.mjs +92 -101
- package/dshqqbot/.qqbot-extensions/tools/memory.mjs +178 -120
- package/dshqqbot/.qqbot-extensions/vendor/abogus/test-abogus.mjs +128 -126
- package/package.json +119 -118
- package/scripts/__pycache__/fan-mode.cpython-311.pyc +0 -0
- package/scripts/__pycache__/memory-audit.cpython-311.pyc +0 -0
- package/scripts/__pycache__/qq-ip-sync.cpython-311.pyc +0 -0
- package/scripts/__pycache__/qq-whitelist.cpython-311.pyc +0 -0
- package/scripts/ai-toolkit.py +607 -478
- package/scripts/chat-archive/__pycache__/build-sft-v4.cpython-311.pyc +0 -0
- package/scripts/chat-archive/__pycache__/build-sft.cpython-311.pyc +0 -0
- package/scripts/chat-archive/build-sft-v4.py +566 -0
- package/scripts/chat-archive/build-sft.py +390 -0
- package/scripts/chat-archive/eval-sft.py +155 -0
- package/scripts/chat-archive/extract-memory.py +143 -0
- package/scripts/chat-archive/inventory.py +182 -0
- package/scripts/chat-archive/merge-sft.py +114 -0
- package/scripts/chat-archive/qce-pull.py +217 -0
- package/scripts/chat-archive/qqheader.py +110 -0
- package/scripts/chat-archive/qqkey2.py +113 -0
- package/scripts/chat-archive/qqprobe.py +153 -0
- package/scripts/chat-archive/screen-collect.py +163 -0
- package/scripts/chat-archive/sqlcipher_probe.py +444 -0
- package/scripts/episode.py +529 -0
- package/scripts/fan-curve.py +218 -0
- package/scripts/fan-guard.cmd +8 -0
- package/scripts/fan-mode.py +380 -263
- package/scripts/gen-image.py +420 -413
- package/scripts/gen-video.py +186 -178
- package/scripts/hw-profile.py +175 -0
- package/scripts/media-enhance.py +402 -0
- package/scripts/memory-audit.py +581 -0
- package/scripts/migrate-scope.mjs +140 -139
- package/scripts/qq-connect-login.py +133 -0
- package/scripts/qq-ip-sync-hidden.vbs +5 -0
- package/scripts/qq-ip-sync.py +300 -0
- package/scripts/qq-whitelist.py +71 -0
- package/scripts/release-all.mjs +636 -509
- package/scripts/release-check.mjs +244 -226
- package/scripts/secure-room/index.html +334 -0
- package/scripts/secure-room/server.py +582 -0
- package/scripts/stickers/auto-tag.mjs +161 -0
- package/scripts/train/__pycache__/train-lora.cpython-311.pyc +0 -0
- package/scripts/train/gguf-quantize.py +92 -0
- package/scripts/train/gguf-to-hf.py +112 -0
- package/scripts/train/merge-lora.py +51 -0
- package/scripts/train/probe-mirrors.sh +12 -0
- package/scripts/train/probe-mirrors2.sh +20 -0
- package/scripts/train/setup-wsl.sh +23 -0
- package/scripts/train/setup-wsl2.sh +25 -0
- package/scripts/train/setup-wsl3.sh +22 -0
- package/scripts/train/setup-wsl4.sh +22 -0
- package/scripts/train/train-lora.py +319 -0
- package/dist/_backup_ctx_20261125_183653/dist/config.d.ts +0 -473
- package/dist/_backup_ctx_20261125_183653/dist/config.js +0 -450
- package/dist/_backup_ctx_20261125_183653/dist/features/contextless-trim.js +0 -304
- package/dist/_backup_ctx_20261125_183653/dist/session/session-manager.js +0 -1588
- package/dist/_backup_ctx_20261125_183653/dist/transport/inbound.js +0 -1567
- package/dist/_backup_ctx_20261125_183653/dist/transport/outbound.js +0 -647
- package/scripts/__pycache__/ai-mode.cpython-311.pyc +0 -0
- package/scripts/__pycache__/ai-toolkit.cpython-311.pyc +0 -0
- package/scripts/__pycache__/comfy_gen.cpython-311.pyc +0 -0
- package/scripts/__pycache__/gen-image.cpython-311.pyc +0 -0
- package/scripts/__pycache__/gen-video.cpython-311.pyc +0 -0
- package/scripts/__pycache__/model-registry.cpython-311.pyc +0 -0
- package/scripts/__pycache__/purge-standby.cpython-311.pyc +0 -0
package/scripts/fan-mode.py
CHANGED
|
@@ -1,263 +1,380 @@
|
|
|
1
|
-
# -*- coding: utf-8 -*-
|
|
2
|
-
"""fan-mode.py ——
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
python scripts/fan-mode.py --
|
|
17
|
-
python scripts/fan-mode.py --
|
|
18
|
-
python scripts/fan-mode.py --apply
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
import
|
|
25
|
-
import
|
|
26
|
-
import
|
|
27
|
-
import
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
return
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
def
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
return
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
return
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
"""fan-mode.py —— FanControl 三档风扇 + 温度看门狗(日常 / 中间 / 训练)
|
|
3
|
+
|
|
4
|
+
为什么重写(2026-12-04):
|
|
5
|
+
原来只有 daily / task 两档,且切换全靠别的脚本手动调用 —— 没有任何进程在看温度,
|
|
6
|
+
所以 GPU 跑到 88C 风扇还停在固定值上,"超过 80 度就切散热"从来没真正发生过。
|
|
7
|
+
现在:三档固定占空比(不建曲线、不靠温度源判断,切过去就是死值),
|
|
8
|
+
外加一个 --watch 看门狗:GPU/CPU 过 80C 进训练档,降回 74C 以下退日常档,中间走中间档。
|
|
9
|
+
|
|
10
|
+
档位数值(主人 2026-12-04 给定,别再自己发挥):
|
|
11
|
+
日常 daily : GPU 22 CPU 30 进风 23 出风 23
|
|
12
|
+
中间 medium: GPU 61 CPU 50 进风 29 出风 29
|
|
13
|
+
训练 train : GPU 70 CPU 66 进风 35 出风 35
|
|
14
|
+
|
|
15
|
+
用法:
|
|
16
|
+
python scripts/fan-mode.py --status # 看当前温度/风扇/档位
|
|
17
|
+
python scripts/fan-mode.py --apply train # 切训练档
|
|
18
|
+
python scripts/fan-mode.py --apply medium
|
|
19
|
+
python scripts/fan-mode.py --apply daily
|
|
20
|
+
python scripts/fan-mode.py --task # 兼容旧调用,等价于 --apply train
|
|
21
|
+
python scripts/fan-mode.py --daily # 兼容旧调用
|
|
22
|
+
python scripts/fan-mode.py --watch # 常驻看门狗(>80C 自动进训练档)
|
|
23
|
+
"""
|
|
24
|
+
import argparse
|
|
25
|
+
import ctypes
|
|
26
|
+
import json
|
|
27
|
+
import os
|
|
28
|
+
import subprocess
|
|
29
|
+
import sys
|
|
30
|
+
import time
|
|
31
|
+
from datetime import datetime
|
|
32
|
+
|
|
33
|
+
ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
|
34
|
+
FC_EXE = r"C:\Program Files (x86)\FanControl\FanControl.exe"
|
|
35
|
+
FC_USER_CFG = r"C:\Program Files (x86)\FanControl\Configurations\userConfig.json"
|
|
36
|
+
CFG_DIR = os.path.join(ROOT, "config", "fan")
|
|
37
|
+
STATE_FILE = os.path.join(CFG_DIR, "state.json")
|
|
38
|
+
LOG_FILE = os.path.join(ROOT, "logs", "fan.log")
|
|
39
|
+
CREATE_NO_WINDOW = 0x08000000
|
|
40
|
+
|
|
41
|
+
# 档位定义:key -> (cpu, in, out, gpu)
|
|
42
|
+
PROFILES = {
|
|
43
|
+
"daily": {"cpu": 30, "in": 23, "out": 23, "gpu": 22},
|
|
44
|
+
"medium": {"cpu": 50, "in": 29, "out": 29, "gpu": 61},
|
|
45
|
+
"train": {"cpu": 66, "in": 35, "out": 35, "gpu": 70},
|
|
46
|
+
}
|
|
47
|
+
ALIAS = {"task": "train"} # 旧名字
|
|
48
|
+
# 看门狗阈值(带迟滞,避免在阈值上反复横跳)
|
|
49
|
+
T_HOT = 80 # >= 80C 进训练档
|
|
50
|
+
T_WARM = 74 # 74~80C 中间档
|
|
51
|
+
T_COOL = 64 # <= 64C 才回日常档。61% 风扇的平衡点就在 68~70C,阈值贴着平衡点会
|
|
52
|
+
# 每两分钟切一次(实测 10:30/10:32 连切),留到 64C 才不会来回叫
|
|
53
|
+
POLL_SEC = 15
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
def log(msg):
|
|
57
|
+
line = "%s %s" % (datetime.now().strftime("%Y-%m-%d %H:%M:%S"), msg)
|
|
58
|
+
print(line, flush=True)
|
|
59
|
+
try:
|
|
60
|
+
os.makedirs(os.path.dirname(LOG_FILE), exist_ok=True)
|
|
61
|
+
with open(LOG_FILE, "a", encoding="utf-8") as f:
|
|
62
|
+
f.write(line + "\n")
|
|
63
|
+
except OSError:
|
|
64
|
+
pass
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
def smi(*fields):
|
|
68
|
+
try:
|
|
69
|
+
out = subprocess.run(
|
|
70
|
+
["nvidia-smi", "--query-gpu=" + ",".join(fields), "--format=csv,noheader,nounits"],
|
|
71
|
+
capture_output=True, text=True, timeout=15, creationflags=CREATE_NO_WINDOW)
|
|
72
|
+
rows = (out.stdout or "").strip().splitlines()
|
|
73
|
+
return [x.strip() for x in rows[0].split(",")] if rows else None
|
|
74
|
+
except Exception:
|
|
75
|
+
return None
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
def gpu_temp():
|
|
79
|
+
row = smi("temperature.gpu")
|
|
80
|
+
try:
|
|
81
|
+
return int(float(row[0]))
|
|
82
|
+
except Exception:
|
|
83
|
+
return None
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
def gpu_fan():
|
|
87
|
+
row = smi("fan.speed")
|
|
88
|
+
try:
|
|
89
|
+
return int(float(row[0]))
|
|
90
|
+
except Exception:
|
|
91
|
+
return None
|
|
92
|
+
|
|
93
|
+
|
|
94
|
+
def cpu_temp():
|
|
95
|
+
"""CPU 温度:走 ACPI 热区。很多台式板子不暴露,读不到就返回 None(不阻塞判断)。"""
|
|
96
|
+
try:
|
|
97
|
+
out = subprocess.run(
|
|
98
|
+
["powershell", "-NoProfile", "-Command",
|
|
99
|
+
"(Get-CimInstance -Namespace root/wmi -ClassName MSAcpi_ThermalZoneTemperature "
|
|
100
|
+
"-ErrorAction Stop | Select-Object -First 1).CurrentTemperature"],
|
|
101
|
+
capture_output=True, text=True, timeout=10, creationflags=CREATE_NO_WINDOW,
|
|
102
|
+
encoding="gbk", errors="ignore")
|
|
103
|
+
raw = (out.stdout or "").strip()
|
|
104
|
+
if not raw:
|
|
105
|
+
return None
|
|
106
|
+
return int(round(int(float(raw)) / 10.0 - 273.15))
|
|
107
|
+
except Exception:
|
|
108
|
+
return None
|
|
109
|
+
|
|
110
|
+
|
|
111
|
+
def _card_key(ident, nick):
|
|
112
|
+
hay_id = (ident or "").lower()
|
|
113
|
+
hay_nick = (nick or "").lower()
|
|
114
|
+
# 显卡卡的 Identifier 实际是 'NVApiWrapper/0-TU102-A/control/0'
|
|
115
|
+
# (旧代码写成 nvaapiwrapper,多了一个 a,所以三条配置里的 GPU 值从来没被改到)
|
|
116
|
+
if "nvapiwrapper" in hay_id or hay_id.startswith("nvapi"):
|
|
117
|
+
return "gpu"
|
|
118
|
+
if "cpu fan" in hay_nick:
|
|
119
|
+
return "cpu"
|
|
120
|
+
if "进风" in hay_nick:
|
|
121
|
+
return "in"
|
|
122
|
+
if "出风" in hay_nick:
|
|
123
|
+
return "out"
|
|
124
|
+
return None
|
|
125
|
+
|
|
126
|
+
|
|
127
|
+
def read_source_config():
|
|
128
|
+
with open(FC_USER_CFG, "r", encoding="utf-8-sig") as f:
|
|
129
|
+
return json.load(f)
|
|
130
|
+
|
|
131
|
+
|
|
132
|
+
def build(force=False):
|
|
133
|
+
"""按三档目标值生成 daily/medium/train 三份模板;值不对就重建(不自作主张改数值)。"""
|
|
134
|
+
os.makedirs(CFG_DIR, exist_ok=True)
|
|
135
|
+
paths = {k: os.path.join(CFG_DIR, k + ".json") for k in PROFILES}
|
|
136
|
+
if not force and all(os.path.exists(p) for p in paths.values()):
|
|
137
|
+
# 模板被 FanControl 回写坏过(实测 medium 变成 35),所以存在也要核对数值
|
|
138
|
+
if all(_template_ok(p, PROFILES[k]) for k, p in paths.items()):
|
|
139
|
+
return paths
|
|
140
|
+
cfg = read_source_config()
|
|
141
|
+
for name, targets in PROFILES.items():
|
|
142
|
+
data = json.loads(json.dumps(cfg))
|
|
143
|
+
for card in data["FanControl"]["Controls"]:
|
|
144
|
+
key = _card_key(card.get("Identifier"), card.get("NickName"))
|
|
145
|
+
if not key:
|
|
146
|
+
continue
|
|
147
|
+
card["Enable"] = True
|
|
148
|
+
card["ManualControl"] = True # 固定值,不用曲线
|
|
149
|
+
card["ManualControlValue"] = int(targets[key])
|
|
150
|
+
tmp = paths[name] + ".tmp"
|
|
151
|
+
with open(tmp, "w", encoding="utf-8") as f:
|
|
152
|
+
json.dump(data, f, ensure_ascii=False, indent=2)
|
|
153
|
+
os.replace(tmp, paths[name])
|
|
154
|
+
log("已生成三档配置: " + ", ".join("%s(GPU %d%%)" % (k, v["gpu"]) for k, v in PROFILES.items()))
|
|
155
|
+
return paths
|
|
156
|
+
|
|
157
|
+
|
|
158
|
+
def _template_ok(path, targets):
|
|
159
|
+
try:
|
|
160
|
+
with open(path, "r", encoding="utf-8") as f:
|
|
161
|
+
data = json.load(f)
|
|
162
|
+
for card in data["FanControl"]["Controls"]:
|
|
163
|
+
key = _card_key(card.get("Identifier"), card.get("NickName"))
|
|
164
|
+
if key and int(card.get("ManualControlValue", -1)) != int(targets[key]):
|
|
165
|
+
return False
|
|
166
|
+
return True
|
|
167
|
+
except Exception:
|
|
168
|
+
return False
|
|
169
|
+
|
|
170
|
+
|
|
171
|
+
def fancontrol_running():
|
|
172
|
+
try:
|
|
173
|
+
out = subprocess.run(["tasklist", "/FI", "IMAGENAME eq FanControl.exe", "/NH"],
|
|
174
|
+
capture_output=True, text=True, timeout=15,
|
|
175
|
+
encoding="gbk", errors="ignore",
|
|
176
|
+
creationflags=CREATE_NO_WINDOW)
|
|
177
|
+
return "FanControl.exe" in (out.stdout or "")
|
|
178
|
+
except Exception:
|
|
179
|
+
return False
|
|
180
|
+
|
|
181
|
+
|
|
182
|
+
def write_state(profile, ok, note=""):
|
|
183
|
+
os.makedirs(CFG_DIR, exist_ok=True)
|
|
184
|
+
data = {"profile": profile if ok else "unknown", "ok": bool(ok),
|
|
185
|
+
"gpu_temp": gpu_temp(), "gpu_fan": gpu_fan(), "note": note,
|
|
186
|
+
"at": datetime.now().strftime("%Y-%m-%d %H:%M:%S")}
|
|
187
|
+
tmp = STATE_FILE + ".tmp"
|
|
188
|
+
with open(tmp, "w", encoding="utf-8") as f:
|
|
189
|
+
json.dump(data, f, ensure_ascii=False, indent=2)
|
|
190
|
+
os.replace(tmp, STATE_FILE)
|
|
191
|
+
return data
|
|
192
|
+
|
|
193
|
+
|
|
194
|
+
def current_profile():
|
|
195
|
+
try:
|
|
196
|
+
with open(STATE_FILE, "r", encoding="utf-8") as f:
|
|
197
|
+
return (json.load(f) or {}).get("profile")
|
|
198
|
+
except Exception:
|
|
199
|
+
return None
|
|
200
|
+
|
|
201
|
+
|
|
202
|
+
def is_admin():
|
|
203
|
+
"""FanControl.exe -c 只有管理员才真正生效:非管理员调用会「成功返回、风扇不动」。"""
|
|
204
|
+
try:
|
|
205
|
+
return bool(ctypes.windll.shell32.IsUserAnAdmin())
|
|
206
|
+
except Exception:
|
|
207
|
+
return False
|
|
208
|
+
|
|
209
|
+
|
|
210
|
+
def relaunch_as_admin():
|
|
211
|
+
"""把自己以管理员身份重开一次(UAC 弹窗)。换档/看门狗必须走这条路,否则等于没切。"""
|
|
212
|
+
params = " ".join('"%s"' % a for a in sys.argv[1:])
|
|
213
|
+
try:
|
|
214
|
+
rc = ctypes.windll.shell32.ShellExecuteW(None, "runas", sys.executable, params, None, 1)
|
|
215
|
+
return rc > 32
|
|
216
|
+
except Exception as e:
|
|
217
|
+
log("申请管理员权限失败: %s" % e)
|
|
218
|
+
return False
|
|
219
|
+
|
|
220
|
+
|
|
221
|
+
def apply(profile, wait=20):
|
|
222
|
+
name = ALIAS.get(profile, profile)
|
|
223
|
+
if name not in PROFILES:
|
|
224
|
+
log("未知档位: %s" % profile)
|
|
225
|
+
return 2
|
|
226
|
+
if not is_admin():
|
|
227
|
+
# 非管理员调 FanControl -c 会「返回成功但风扇不动」,那正是之前 88C 的原因
|
|
228
|
+
log("切 %s 档被拒绝:当前不是管理员,FanControl 接收配置但不执行" % name)
|
|
229
|
+
return 5
|
|
230
|
+
if not os.path.exists(FC_EXE):
|
|
231
|
+
log("找不到 FanControl.exe: %s" % FC_EXE)
|
|
232
|
+
return 3
|
|
233
|
+
cfg = build(force=False)[name] # 三档模板(只读,不给 FanControl 加载)
|
|
234
|
+
active = os.path.join(CFG_DIR, "active.json")
|
|
235
|
+
want = PROFILES[name]["gpu"]
|
|
236
|
+
# ★ 只改文件再 -c 重新加载并不可靠:实测同一进程里 reload 之后风扇还是按旧曲线跑
|
|
237
|
+
# (61% 目标实际只到 35~42%)。所以换档 = 先把 FanControl 停掉、再按新配置冷启动,
|
|
238
|
+
# 这样它一定是「启动即加载」,三档占空比才会真的落到风扇上。
|
|
239
|
+
try:
|
|
240
|
+
subprocess.run(["taskkill", "/IM", "FanControl.exe", "/F"], capture_output=True,
|
|
241
|
+
timeout=20, creationflags=CREATE_NO_WINDOW)
|
|
242
|
+
time.sleep(1.5)
|
|
243
|
+
except Exception:
|
|
244
|
+
pass
|
|
245
|
+
# 必须在停掉之后写 active.json:FanControl 退出时会把实时值回写它加载的那个文件
|
|
246
|
+
try:
|
|
247
|
+
with open(cfg, "r", encoding="utf-8") as f:
|
|
248
|
+
data = json.load(f)
|
|
249
|
+
with open(active, "w", encoding="utf-8") as f:
|
|
250
|
+
json.dump(data, f, ensure_ascii=False, indent=2)
|
|
251
|
+
except Exception as e:
|
|
252
|
+
log("写 active.json 失败: %s" % e)
|
|
253
|
+
return 3
|
|
254
|
+
try:
|
|
255
|
+
subprocess.Popen([FC_EXE, "-c", active, "-m"], creationflags=CREATE_NO_WINDOW)
|
|
256
|
+
except Exception as e:
|
|
257
|
+
log("拉起 FanControl 失败: %s" % e)
|
|
258
|
+
return 3
|
|
259
|
+
|
|
260
|
+
t0, cur = time.time(), gpu_fan()
|
|
261
|
+
while time.time() - t0 < wait:
|
|
262
|
+
time.sleep(2)
|
|
263
|
+
cur = gpu_fan()
|
|
264
|
+
if cur is None or abs(cur - want) <= 5:
|
|
265
|
+
break
|
|
266
|
+
ok = True if cur is None else (abs(cur - want) <= 8)
|
|
267
|
+
write_state(name, ok, "gpu_fan=%s want=%s" % (cur, want))
|
|
268
|
+
log("切到 %s 档 -> GPU 风扇 %s%%(目标 %s%%)%s" % (name, cur, want, "" if ok else " ⚠ 未达预期"))
|
|
269
|
+
return 0 if ok else 4
|
|
270
|
+
|
|
271
|
+
|
|
272
|
+
def pick_profile(temp, cur=None):
|
|
273
|
+
"""带迟滞的三档判定:只在「确实该换」时才换,避免在阈值上每 15 秒来回跳。
|
|
274
|
+
|
|
275
|
+
>=80C → train(不管现在哪档)
|
|
276
|
+
74~80C → 现在已经在 train 就保持(让它再压下去),否则 medium
|
|
277
|
+
70~74C → 死区,保持不动
|
|
278
|
+
<=70C → daily
|
|
279
|
+
"""
|
|
280
|
+
if temp is None:
|
|
281
|
+
return None
|
|
282
|
+
if temp >= T_HOT:
|
|
283
|
+
return "train"
|
|
284
|
+
if temp <= T_COOL:
|
|
285
|
+
return "daily"
|
|
286
|
+
if temp >= T_WARM:
|
|
287
|
+
return "train" if cur == "train" else "medium"
|
|
288
|
+
return None # 70~74 死区
|
|
289
|
+
|
|
290
|
+
|
|
291
|
+
def fan_ok(profile, tol=10):
|
|
292
|
+
"""实际风扇是否真的到了该档的目标值(state.json 写的是「意图」,不是事实)。"""
|
|
293
|
+
f = gpu_fan()
|
|
294
|
+
if f is None:
|
|
295
|
+
return True
|
|
296
|
+
return abs(f - PROFILES[profile]["gpu"]) <= tol
|
|
297
|
+
|
|
298
|
+
|
|
299
|
+
def watch():
|
|
300
|
+
log("看门狗启动:>=%dC 训练档 / %d~%dC 中间档 / <=%dC 日常档,每 %ds 轮询"
|
|
301
|
+
% (T_HOT, T_WARM, T_HOT, T_COOL, POLL_SEC))
|
|
302
|
+
last_retry = 0.0
|
|
303
|
+
while True:
|
|
304
|
+
try:
|
|
305
|
+
tg, tc = gpu_temp(), cpu_temp()
|
|
306
|
+
hot = max([x for x in (tg, tc) if x is not None] or [None])
|
|
307
|
+
cur = current_profile()
|
|
308
|
+
want = pick_profile(hot, cur)
|
|
309
|
+
need = bool(want) and want != cur
|
|
310
|
+
# 配置写进去了但风扇没跟上(FanControl 自己回写配置就是这种坑)→ 60 秒重试一次
|
|
311
|
+
if want and not need and not fan_ok(want) and time.time() - last_retry > 60:
|
|
312
|
+
log("风扇没跟上:当前 %s%% / %s 档目标 %d%% → 重新下发"
|
|
313
|
+
% (gpu_fan(), want, PROFILES[want]["gpu"]))
|
|
314
|
+
last_retry = time.time()
|
|
315
|
+
need = True
|
|
316
|
+
if need:
|
|
317
|
+
log("温度 GPU=%s CPU=%s -> 切 %s 档" % (tg, tc, want))
|
|
318
|
+
apply(want)
|
|
319
|
+
time.sleep(POLL_SEC)
|
|
320
|
+
except KeyboardInterrupt:
|
|
321
|
+
log("看门狗退出")
|
|
322
|
+
return 0
|
|
323
|
+
except Exception as e:
|
|
324
|
+
log("看门狗异常(继续跑): %s" % e)
|
|
325
|
+
time.sleep(POLL_SEC)
|
|
326
|
+
|
|
327
|
+
|
|
328
|
+
def status():
|
|
329
|
+
row = smi("name", "temperature.gpu", "fan.speed", "power.draw", "power.limit", "memory.used")
|
|
330
|
+
if row:
|
|
331
|
+
print("gpu : %s" % row[0])
|
|
332
|
+
print("temp : %s C fan: %s%% power: %s / %s W" % tuple(row[1:5]))
|
|
333
|
+
print("vram : %s MiB" % row[5])
|
|
334
|
+
else:
|
|
335
|
+
print("nvidia-smi 不可用")
|
|
336
|
+
print("cpu : %s C" % cpu_temp())
|
|
337
|
+
print("fanctl: %s" % ("running" if fancontrol_running() else "NOT running"))
|
|
338
|
+
print("mode : %s" % (current_profile() or "未知(还没切过档)"))
|
|
339
|
+
for name in PROFILES:
|
|
340
|
+
p = os.path.join(CFG_DIR, name + ".json")
|
|
341
|
+
print("%-6s: %s (GPU %d%%)" % (name, "ok" if os.path.exists(p) else "缺失", PROFILES[name]["gpu"]))
|
|
342
|
+
return 0
|
|
343
|
+
|
|
344
|
+
|
|
345
|
+
def main():
|
|
346
|
+
ap = argparse.ArgumentParser()
|
|
347
|
+
ap.add_argument("--status", action="store_true")
|
|
348
|
+
ap.add_argument("--make", action="store_true")
|
|
349
|
+
ap.add_argument("--force", action="store_true")
|
|
350
|
+
ap.add_argument("--watch", action="store_true")
|
|
351
|
+
ap.add_argument("--task", action="store_true")
|
|
352
|
+
ap.add_argument("--daily", action="store_true")
|
|
353
|
+
ap.add_argument("--apply", choices=list(PROFILES) + ["task"])
|
|
354
|
+
a = ap.parse_args()
|
|
355
|
+
|
|
356
|
+
if a.status:
|
|
357
|
+
return status()
|
|
358
|
+
if a.make:
|
|
359
|
+
build(force=a.force)
|
|
360
|
+
return status()
|
|
361
|
+
# 换档 / 看门狗:非管理员先自我提权重开,否则切了等于没切
|
|
362
|
+
if (a.watch or a.apply or a.task or a.daily) and not is_admin():
|
|
363
|
+
log("非管理员启动,正在申请管理员权限重开(UAC 请点「是」)")
|
|
364
|
+
if relaunch_as_admin():
|
|
365
|
+
return 0
|
|
366
|
+
log("没有拿到管理员权限 —— 风扇不会真的动")
|
|
367
|
+
return 5
|
|
368
|
+
if a.watch:
|
|
369
|
+
return watch()
|
|
370
|
+
if a.apply:
|
|
371
|
+
return apply(a.apply)
|
|
372
|
+
if a.task:
|
|
373
|
+
return apply("train")
|
|
374
|
+
if a.daily:
|
|
375
|
+
return apply("daily")
|
|
376
|
+
return status()
|
|
377
|
+
|
|
378
|
+
|
|
379
|
+
if __name__ == "__main__":
|
|
380
|
+
sys.exit(main())
|