Skip to content

armgit / laya

Public Imported from GitHub
0

Non-autoregressive System 1 decision engine. Typed choice, score and yes/no decisions over any text in a single forward pass, in 100+ languages, with a router that picks the right checkpoint per request.

fix(router): preserve hooks_timeout positional prefix on predict_batch (#909)

Swatantra Yadavb0be37986b51
diff --git a/docs/hooks/api.md b/docs/hooks/api.md
index f7284a06..0c1bceaf 100644
--- a/docs/hooks/api.md
+++ b/docs/hooks/api.md
@@ -296,8 +296,8 @@ router.predict(state, questions, model=None, task=None, lang=None, lang_guess=No
hooks=None, on_predict_start=None, on_predict_end=None, hooks_raise=None,
hooks_timeout=None, max_len=None, head_max_len=None)
-router.predict_batch(requests, batch_size=None, min_confidence=None, sort_by_length=False,
- hooks_timeout=None, hooks=None, on_predict_start=None, on_predict_end=None,
+router.predict_batch(requests, batch_size=None, hooks_timeout=None, min_confidence=None,
+ sort_by_length=False, hooks=None, on_predict_start=None, on_predict_end=None,
hooks_raise=None)
router.system_one(...) # alias of predict
diff --git a/laya/mcp/remote.py b/laya/mcp/remote.py
index ec5e1c2d..c5f7efc9 100644
--- a/laya/mcp/remote.py
+++ b/laya/mcp/remote.py
@@ -195,10 +195,10 @@ class RemoteRouter(Router):
self,
requests: Sequence[Dict[str, Any]],
batch_size: Optional[int] = None,
+ hooks_timeout: Optional[float] = None,
min_confidence: Optional[float] = None,
sort_by_length: bool = False,
*,
- hooks_timeout: Optional[float] = None,
hooks=None,
on_predict_start=None,
on_predict_end=None,
diff --git a/laya/router.py b/laya/router.py
index b51ea42f..1e57b1d2 100644
--- a/laya/router.py
+++ b/laya/router.py
@@ -1227,10 +1227,10 @@ class Router(HookRegistry):
self,
requests: Sequence[Dict[str, Any]],
batch_size: Optional[int] = None,
+ hooks_timeout: Optional[float] = None,
min_confidence: Optional[float] = None,
sort_by_length: bool = False,
*,
- hooks_timeout: Optional[float] = None,
hooks=None,
on_predict_start=None,
on_predict_end=None,
@@ -1267,12 +1267,12 @@ class Router(HookRegistry):
``lang_guess`` routing overrides and ``max_len`` / ``head_max_len`` token-budget
overrides.
batch_size: Optional maximum number of states per Agent forward-pass batch.
+ hooks_timeout: Override the Router's ``hooks_timeout`` for this call.
min_confidence: Optional float or per-bucket mapping for confidence gating.
sort_by_length: Forwarded to every ``Agent.predict_batch`` call, so each question
group pads to a shorter maximum; see ``Agent.predict_batch``. Results retain the
input order either way. Silently dropped for an attached agent whose
``predict_batch`` predates the knob (#294).
- hooks_timeout: Override the Router's ``hooks_timeout`` for this call.
hooks (HookArg): Per-call hook or sequence of hooks for this call.
on_predict_start (PredictHookArg): Plain callable or sequence of callables for start events.
on_predict_end (PredictHookArg): Plain callable or sequence of callables for end events.
diff --git a/tests/test_hooks.py b/tests/test_hooks.py
index 817a738c..49edfe24 100644
--- a/tests/test_hooks.py
+++ b/tests/test_hooks.py
@@ -1682,15 +1682,19 @@ check("router_batch/route_batch positional hooks_timeout", len(pos_decisions), 1
kw_decisions = r_pos.route_batch([req("pos1")], 1.0, hooks=[RouteTrace()])
check("router_batch/route_batch keyword-only hooks", len(kw_decisions), 1)
-# predict_batch keeps hooks_timeout keyword-only
-pos_results = r_pos.predict_batch([req("pos2")], 8, hooks_timeout=1.0, hooks=[PerCallTrace()])
-check("router_batch/predict_batch keyword-only controls", len(pos_results), 1)
+# predict_batch preserves hooks_timeout positional prefix from main
+pos_results = r_pos.predict_batch([req("pos2")], 8, 1.0, hooks=[PerCallTrace()])
+check("router_batch/predict_batch positional hooks_timeout", len(pos_results), 1)
+
+# predict_batch takes per-call hooks as keyword-only
+kw_results = r_pos.predict_batch([req("pos2")], 8, hooks=[PerCallTrace()])
+check("router_batch/predict_batch keyword-only hooks", len(kw_results), 1)
# keyword-only enforcement: passing hook controls positionally raises TypeError
check_raises("router_batch/route_batch rejects positional hooks", TypeError,
lambda: r_pos.route_batch([req("pos1")], 1.0, [RouteTrace()]))
-check_raises("router_batch/predict_batch rejects positional hooks_timeout past sort_by_length", TypeError,
- lambda: r_pos.predict_batch([req("pos2")], 8, None, False, 1.0))
+check_raises("router_batch/predict_batch rejects positional hooks", TypeError,
+ lambda: r_pos.predict_batch([req("pos2")], 8, 1.0, None, False, [PerCallTrace()]))
# --------------------------------------------------------------- report
diff --git a/tests/test_hooks_api.py b/tests/test_hooks_api.py
index b90a2e91..8d97c165 100644
--- a/tests/test_hooks_api.py
+++ b/tests/test_hooks_api.py
@@ -190,11 +190,11 @@ check("Router.route_batch/positional prefix",
check("Router.predict_batch/positional prefix",
[p.name for p in sig(Router.predict_batch).values()
if p.kind != inspect.Parameter.KEYWORD_ONLY and p.name != "self"],
- ["requests", "batch_size", "min_confidence", "sort_by_length"])
+ ["requests", "batch_size", "hooks_timeout", "min_confidence", "sort_by_length"])
for param in ("hooks", "hooks_raise"):
check("Router.route_batch/%s is keyword-only" % param,
sig(Router.route_batch)[param].kind, inspect.Parameter.KEYWORD_ONLY)
-for param in ("hooks_timeout", "hooks", "on_predict_start", "on_predict_end", "hooks_raise"):
+for param in ("hooks", "on_predict_start", "on_predict_end", "hooks_raise"):
check("Router.predict_batch/%s is keyword-only" % param,
sig(Router.predict_batch)[param].kind, inspect.Parameter.KEYWORD_ONLY)