diag: ml/eval/diag_cl.py 闭环失败定位 + fix(dagger): collect.py kin.gaps 分块 1024 点、cap=gap_min+1(原 4096 点 cap 40 吃满显存/内存)
This commit is contained in:
+11
-1
@@ -16,6 +16,8 @@ from ml.data import load_tasks
|
||||
from ml.model.policy import build
|
||||
from ml.sim.closed_loop import rollout, goal_err, tasks_to_tensors, DT
|
||||
|
||||
GAP_CHUNK = 1024 # 每次 kin.gaps 的查询点数上限
|
||||
|
||||
|
||||
def main():
|
||||
ap = argparse.ArgumentParser()
|
||||
@@ -41,8 +43,14 @@ def main():
|
||||
tr = per['traj'].to(a.device) # [B,T,6]
|
||||
B, Tn, _ = tr.shape
|
||||
_, T, R, _, _ = tasks_to_tensors(tb, a.device)
|
||||
# 2026-10-19 修(用户实测):原来一次喂 64 题 × 64 步 = 4096 点、cap=40 mm 给 kin.gaps,40 mm 内幸存的胶囊对太多,
|
||||
# 峰值把显存 / 内存吃满。这里只需判断"≤0(碰撞)"和"> gap_min(起点地板)",cap 取 gap_min+1 即可,
|
||||
# 且按 GAP_CHUNK 个点分块,用完即释放。
|
||||
cap = gap_min + 1.0
|
||||
flat = tr.reshape(-1, 6)
|
||||
with torch.no_grad():
|
||||
g = torch.cat([kin.gaps(tr[:, s:s + 64].reshape(-1, 6), 40.0)['gm'].min(-1).values.view(B, -1) for s in range(0, Tn, 64)], 1)
|
||||
g = torch.cat([kin.gaps(flat[s:s + GAP_CHUNK], cap)['gm'].min(-1).values for s in range(0, flat.shape[0], GAP_CHUNK)]).view(B, Tn)
|
||||
del flat
|
||||
for b, t in enumerate(tb):
|
||||
hit = (g[b] <= 0).nonzero()
|
||||
c = int(hit[0]) if hit.numel() else Tn
|
||||
@@ -58,6 +66,8 @@ def main():
|
||||
if e.item() < 5 and (not t.get('R') or oe.item() < 5): stat['rej_near'] += 1; continue
|
||||
out.append({'q0': [round(v, 3) for v in q[0].tolist()], 'T': t['T'], 'R': t.get('R'), 'cat': t.get('cat', 'A'),
|
||||
'src': {'tid': t['tid'], 'k': k, 'col': bool(hit.numel())}})
|
||||
del tr, g, per
|
||||
if a.device.startswith('cuda'): torch.cuda.empty_cache()
|
||||
print(f'[dagger] {min(i + a.bs, len(tasks))}/{len(tasks)} 题,起点 {len(out)}', flush=True)
|
||||
stat['states'] = len(out)
|
||||
rng.shuffle(out)
|
||||
|
||||
Reference in New Issue
Block a user