perf+exp: 轮次34——复用cum_xf进库(22项指标逐位不变)、批量认证压最坏尾部(80→37ms)、FP16/BF16实测无收益

- 撤回一条自己的假收益:先前"合并几何查询→24.5ms"不成立。①第一版把 xf= 传给含5行的 gaps,
  只有第0行走完宽相位,认证点全部退回截顶40.0(少干活);②真实顺序 特征→推理→候选→认证,
  认证点依赖网络输出,故"特征间隙与认证点合并一次调用"实现上做不到
- 可实现并已落地:gm_groups(..., xf=) 复用 features 已算的 cum_xf,B=1 交错实测 P50 −3.4ms;
  256题重跑 22 项指标与轮次33 base 逐项相同
- 新增 --cert_batch(默认0不变):K条候选并成1次 gaps 调用。合成夹具(B=2)断言选择/轨迹/证书逐位一致,
  变异检查(换回错误索引)2项测试立即失败;256题重跑同样 22 项指标逐位相同
  实测交换:典型 33.5→37.6ms,最坏(前面候选被拒)80.2→37.1ms,P99 64.7→48.3ms
- FP16/BF16 实测不比 FP32 快(推理 7.68→8.31→8.58ms),整周期不变而 P99 更差,动作偏差 0.005°/0.038°
  → 小批量下不是算力受限,半精度不划算,推理保持 FP32
- 仍不达 20ms:下一刀是流水线复用(下次规划的特征间隙=本次已认证的末点),可整块省掉特征 ~13ms
- 测试 32→34 项
This commit is contained in:
cbb
2026-10-20 20:53:43 +08:00
parent 48cc566c3f
commit 34019c1a34
10 changed files with 1545 additions and 21 deletions
+31 -16
View File
@@ -163,7 +163,7 @@ def rollout(model, kin, tasks, device, K=8, safety=False, seed=0, max_sec=None,
qp0=None, steps=1, z_scale=1.0, select='consist', oracle=None, replan='r3', sub_rule='cross',
fb_gain=0.0, fb_scale=0.0, fb_near=0.2, fb_fallback=0.0, safety_partial=0, commit_n=3, collect=None,
fb_exec=0.0, exec_safety=0, fb_ki=0.0, fb_decay=0.9, fb_imax=0.5, fb_every=1, safety_try=0, sel_w=0.1, dls_safety=0, fb_clear=0.0, fb_cmin=0.3, sub_refresh=0, fb_block_gain=1.0,
inc_cap=0, gap_margin=0.0, progress=None):
inc_cap=0, gap_margin=0.0, cert_batch=0, progress=None):
"""use_sub=False:不用子目标(sf=0);sub_override=(subs [B,M,6] 绝对关节角, n [B] 个数 或 need [B] bool):冷启动时用给定途经点代替子目标头;
qp0 [B,6]:起点的上一帧(默认 = q0,即静止起步)。steps:MeanFlow 采样段数;z_scale:噪声缩放;
select:consist(部署口径:冷启动价值前瞻、之后与上一条已提交计划的一致性)/ value(每次都价值前瞻)/ first(不选,取第 0 条)。
@@ -329,22 +329,37 @@ def rollout(model, kin, tasks, device, K=8, safety=False, seed=0, max_sec=None,
maxlen = torch.zeros(B, dtype=torch.long, device=device)
chosen = torch.zeros(B, commit_n, 6, device=device); chosen_k = pick.clone()
ntry = min(K_eff, safety_try) if safety_try > 0 else K_eff
for kk in range(ntry):
ck = inc[ar, order[:, kk], r:r + commit_n]
pts, mids = execution_points(kin, qe, ck)
allq = torch.cat([pts, mids], 1).reshape(-1, 6)
gaps6 = kin.gaps(allq, gcap)['gm'].min(-1).values.view(B, 2 * commit_n)
ok6 = gaps6 > gap_margin
okstep = ok6[:, :commit_n] & ok6[:, commit_n:]
plen = torch.cumprod(okstep.long(), 1).sum(1)
take = plen > maxlen
chosen = torch.where(take[:, None, None], ck, chosen); chosen_k = torch.where(take, order[:, kk], chosen_k)
if cert_batch: # 一次 gaps 覆盖全部候选:典型路径略贵,但把「前面候选被拒→串行调用 K 次」的最坏情况封成 1 次
cks = inc[ar[:, None], order[:, :ntry], r:r + commit_n].reshape(B * ntry, commit_n, 6)
pts, mids = execution_points(kin, qe.repeat_interleave(ntry, 0), cks)
gaps6 = kin.gaps(torch.cat([pts, mids], 1).reshape(-1, 6), gcap)['gm'].min(-1).values.view(B, ntry, 2 * commit_n)
plen = torch.cumprod(((gaps6 > gap_margin)[:, :, :commit_n] &
(gaps6 > gap_margin)[:, :, commit_n:]).long(), -1).sum(-1)
maxlen = plen.max(-1).values
best = plen.argmax(-1) # 与串行同口径:严格更大者胜 ⇒ 首个最大值
chosen = cks.view(B, ntry, commit_n, 6)[ar, best]
chosen_k = order[ar, best]
if return_traj:
cert_pts = torch.where(take[:, None, None], pts, cert_pts)
cert_mids = torch.where(take[:, None, None], mids, cert_mids)
cert_gaps = torch.where(take[:, None], gaps6, cert_gaps)
maxlen = torch.maximum(maxlen, plen)
if B == 1 and int(maxlen[0]) >= commit_n: break # 实时单题:首个全安全候选即停(安全层 16 点→2-4 点)
cert_pts = pts.view(B, ntry, commit_n, 6)[ar, best]
cert_mids = mids.view(B, ntry, commit_n, 6)[ar, best]
cert_gaps = gaps6[ar, best]
else:
for kk in range(ntry):
ck = inc[ar, order[:, kk], r:r + commit_n]
pts, mids = execution_points(kin, qe, ck)
allq = torch.cat([pts, mids], 1).reshape(-1, 6)
gaps6 = kin.gaps(allq, gcap)['gm'].min(-1).values.view(B, 2 * commit_n)
ok6 = gaps6 > gap_margin
okstep = ok6[:, :commit_n] & ok6[:, commit_n:]
plen = torch.cumprod(okstep.long(), 1).sum(1)
take = plen > maxlen
chosen = torch.where(take[:, None, None], ck, chosen); chosen_k = torch.where(take, order[:, kk], chosen_k)
if return_traj:
cert_pts = torch.where(take[:, None, None], pts, cert_pts)
cert_mids = torch.where(take[:, None, None], mids, cert_mids)
cert_gaps = torch.where(take[:, None], gaps6, cert_gaps)
maxlen = torch.maximum(maxlen, plen)
if B == 1 and int(maxlen[0]) >= commit_n: break # 实时单题:首个全安全候选即停(安全层 16 点→2-4 点)
msk = (torch.arange(commit_n, device=device)[None] < maxlen[:, None])
commit = torch.where(msk[..., None], chosen, torch.zeros_like(chosen))
if return_traj: certified = msk.clone()