Fix review issues #11-#16: StreamK fixpipe 单次计账 / K=1 AIV单缓冲方案 / MergeBatch b0 L0A/L0B 上限+路由可行回退 / advice-StreamK / 输入校验 / .gitignore+死代码清理
This commit is contained in:
@@ -78,11 +78,9 @@ class BranchRouter:
|
||||
mb = self.merge_batch.analyze(case)
|
||||
ib = self.iter_batch.analyze(case)
|
||||
|
||||
candidates = []
|
||||
if mb.capable:
|
||||
candidates.append((self.merge_batch.name, mb))
|
||||
if ib.capable:
|
||||
candidates.append((self.iter_batch.name, ib))
|
||||
# 候选表: [(分支名, BranchResult)], 顺序 = 仲裁优先级
|
||||
cand_map = {self.merge_batch.name: mb, self.iter_batch.name: ib}
|
||||
capable = {n: r.capable for n, r in cand_map.items()}
|
||||
|
||||
arbitration = ""
|
||||
if mb.capable and ib.capable:
|
||||
@@ -100,8 +98,8 @@ class BranchRouter:
|
||||
)
|
||||
if win != lat_win:
|
||||
win = lat_win # 时延模型为最终裁决
|
||||
elif candidates:
|
||||
win = candidates[0][0]
|
||||
elif any(capable.values()):
|
||||
win = next(n for n, v in capable.items() if v)
|
||||
arbitration = f"仅 {win} 条件满足"
|
||||
else:
|
||||
# 切B分支都不满足, 尝试 StreamK 再回落 ASW
|
||||
@@ -115,11 +113,37 @@ class BranchRouter:
|
||||
f"IterBatch未过: {ib.failed_conditions()}; "
|
||||
f"MergeBatch未过: {mb.failed_conditions()}")
|
||||
|
||||
chosen = mb if win == self.merge_batch.name else ib
|
||||
# 可行性保障 (issue#13): 仲裁胜出方案必须通过约束自检, 否则按
|
||||
# (另一切B候选 -> StreamK -> ASW_Basic) 顺序回退到首个可行方案.
|
||||
from .constraints import check_plan_constraints
|
||||
|
||||
def _feasible(n):
|
||||
r = cand_map[n]
|
||||
return r.plan is not None and not check_plan_constraints(case, r.plan, self.spec)
|
||||
|
||||
if _feasible(win):
|
||||
chosen = cand_map[win]
|
||||
else:
|
||||
loser = self.merge_batch.name if win == self.iter_batch.name else self.iter_batch.name
|
||||
fallback_note = (f"; 但 {win} 方案自检违规: "
|
||||
f"{'; '.join(check_plan_constraints(case, cand_map[win].plan, self.spec))}")
|
||||
if capable.get(loser) and _feasible(loser):
|
||||
chosen, win = cand_map[loser], loser
|
||||
fallback_note += f", 回退可行候选 {loser}"
|
||||
else:
|
||||
sk = self.stream_k.analyze(case)
|
||||
if sk.capable and sk.plan is not None and \
|
||||
not check_plan_constraints(case, sk.plan, self.spec):
|
||||
return self._wrap_checked(case, sk, arbitration + fallback_note + ", 落 StreamK")
|
||||
asw = self.asw_basic.analyze(case)
|
||||
if asw.plan is not None and not check_plan_constraints(case, asw.plan, self.spec):
|
||||
return self._wrap_checked(case, asw, arbitration + fallback_note + ", 回落 ASW_Basic")
|
||||
chosen, win = cand_map[win], win # 无可行方案: 保留原裁决, 由自检标注
|
||||
arbitration += fallback_note
|
||||
|
||||
result = BranchResult(capable=True, plan=chosen.plan, timing=chosen.timing)
|
||||
return self._wrap_checked(case, result, arbitration,
|
||||
candidates={n: r.capable for n, r in
|
||||
[(self.merge_batch.name, mb), (self.iter_batch.name, ib)]})
|
||||
candidates=capable)
|
||||
|
||||
# ------------------------------------------------------------------
|
||||
def _wrap_checked(self, case: BmmCase, result: BranchResult, note: str,
|
||||
@@ -155,15 +179,3 @@ class BranchRouter:
|
||||
return {"branch": branch, "plan": plan, "timing": None,
|
||||
"arbitration": "[无方案] " + note, "candidates": {},
|
||||
"self_check_violations": []}
|
||||
|
||||
# ------------------------------------------------------------------
|
||||
@staticmethod
|
||||
def _wrap(result: BranchResult, note: str) -> dict:
|
||||
return {
|
||||
"branch": result.plan.branch if result.plan else "未知",
|
||||
"plan": result.plan,
|
||||
"timing": result.timing,
|
||||
"arbitration": note + (f" | {result.note}" if result.note else ""),
|
||||
"candidates": {},
|
||||
"self_check_violations": [],
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user