v2.8.3 新增测试间隔时间:每次采样之间让大模型接口空闲休息,默认5秒可配置(0关闭),等待期间支持停止
This commit is contained in:
@@ -32,6 +32,15 @@ class TestRunner(threading.Thread):
|
||||
def log(self, level, msg):
|
||||
db.add_log(self.test_id, level, msg)
|
||||
|
||||
def _sleep_interval(self, secs):
|
||||
"""测试间隔等待:期间可被用户停止,返回 False 表示已被取消"""
|
||||
deadline = time.time() + secs
|
||||
while time.time() < deadline:
|
||||
if self.should_stop():
|
||||
return False
|
||||
time.sleep(0.2)
|
||||
return not self.should_stop()
|
||||
|
||||
# ───────────────────────── 主流程 ─────────────────────────
|
||||
|
||||
def run(self):
|
||||
@@ -61,6 +70,11 @@ class TestRunner(threading.Thread):
|
||||
max_tokens = max(1, int(gen.get("max_tokens", 128))) # 解码输出长度
|
||||
avoid_cache = bool(gen.get("avoid_cache"))
|
||||
warmup = bool(gen.get("warmup", True)) # 测试前空转预热
|
||||
# 测试间隔(秒):每次采样之间让接口空闲休息,默认 5 秒,0 表示不等待
|
||||
try:
|
||||
interval = 5 if gen.get("interval") in (None, "") else max(0, float(gen.get("interval")))
|
||||
except (TypeError, ValueError):
|
||||
interval = 5
|
||||
|
||||
# 并发数列表(默认单流 [1];支持 2/4 及自定义,如 [1,2,4,8])
|
||||
raw_concs = gen.get("concurrency_levels") or []
|
||||
@@ -73,10 +87,10 @@ class TestRunner(threading.Thread):
|
||||
if name:
|
||||
self.log("INFO", "测试名称(主题): %s" % name)
|
||||
self.log("INFO", "提供商: %s | 模型: %s" % (lp.PROVIDER_LABELS.get(provider, provider), model))
|
||||
self.log("INFO", "上下文长度: %s tokens | 生成长度: %d tokens | 并发数: %s | 每个组合采样: %d 次 | 预热: %s | 避免缓存: %s"
|
||||
self.log("INFO", "上下文长度: %s tokens | 生成长度: %d tokens | 并发数: %s | 每个组合采样: %d 次 | 预热: %s | 避免缓存: %s | 测试间隔: %g 秒"
|
||||
% (" / ".join(str(x) for x in lengths), max_tokens,
|
||||
" / ".join(str(x) for x in concurrency_levels), n,
|
||||
"开" if warmup else "关", "开" if avoid_cache else "关"))
|
||||
"开" if warmup else "关", "开" if avoid_cache else "关", interval))
|
||||
to = self.gen.get("read_timeout") or "默认(1800)"
|
||||
self.log("INFO", "请求超时: 连接 %s s | 等待首字/预处理 %s s(接口慢可在左侧调大)"
|
||||
% (self.gen.get("connect_timeout") or 60, to))
|
||||
@@ -86,6 +100,7 @@ class TestRunner(threading.Thread):
|
||||
self.log("INFO", "校准完成: %.3f tok/字符(%.2f 字符/token)" % (ratio, 1.0 / ratio))
|
||||
|
||||
run_seq = 0
|
||||
sample_done = 0 # 已完成的采样数,用于控制测试间隔(首个采样不等待)
|
||||
last_conc = None # 只在实际切换并发档时打印一次表头,避免同一并发数重复刷屏
|
||||
for L in lengths:
|
||||
if self.should_stop():
|
||||
@@ -103,7 +118,12 @@ class TestRunner(threading.Thread):
|
||||
for i in range(1, n + 1):
|
||||
if self.should_stop():
|
||||
raise StopRequested()
|
||||
if sample_done > 0 and interval > 0:
|
||||
self.log("INFO", "⏳ 接口空闲休息 %g 秒后继续下一采样..." % interval)
|
||||
if not self._sleep_interval(interval):
|
||||
raise StopRequested()
|
||||
run_seq += 1
|
||||
sample_done += 1
|
||||
self.log("INFO", "── [%d tok · 并发%d] 采样 %d/%d 开始 ──" % (L, C, i, n))
|
||||
try:
|
||||
m = self._run_sample(C, base_prompt, max_tokens, avoid_cache)
|
||||
|
||||
Reference in New Issue
Block a user