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.

Merge main into this branch and resolve conflicts

Nandakishor204b2959ab6b
diff --cc laya/onnx_agent.py
index 3f31e6df,d784c956..0f4a19f5
--- a/laya/onnx_agent.py
+++ b/laya/onnx_agent.py
@@@ -46,7 -51,7 +51,8 @@@ class ONNXAgent(HookRegistry)
on_predict_end=None,
hooks_raise: bool = True,
hooks_concurrent: bool = True,
+ hooks_timeout: Optional[float] = None,
+ lang_temperatures: Optional[Dict[str, Dict[str, Any]]] = None,
):
"""Load a Laya agent backed by ONNX Runtime.
@@@ -67,10 -72,7 +73,11 @@@
on_predict_end (PredictHookArg): An opt-in end hook, run after inference.
hooks_raise: When False, a failing hook warns and inference continues.
hooks_concurrent: When False, hooks are serialised with a lock.
+ hooks_timeout: Bounds each hook call in seconds; None means no limit.
+ lang_temperatures: Optional per-language temperature overrides, keyed by language
+ code, each `{"temperature": [3 floats], "temperature_by_options": {}}`.
+ Applied when a `lang=` is passed to `system_one`/`predict`, mirroring
+ the PyTorch `Agent`; a cross-backend swap otherwise loses calibration.
"""
self.hooks = normalise_hooks(hooks, on_predict_start, on_predict_end)
self.hooks_raise = bool(hooks_raise)
@@@ -216,18 -206,15 +224,20 @@@
return q
def system_one(self, state: Union[str, dict, list], questions: Dict[str, Dict[str, Any]],
+ lang: Optional[str] = None,
hooks=None, on_predict_start=None, on_predict_end=None,
hooks_raise: Optional[bool] = None,
+ hooks_timeout: Optional[float] = None,
max_len: Optional[int] = None,
head_max_len: Optional[int] = None) -> Dict[str, Any]:
- """Evaluate typed questions, running any opt-in hooks around the inference."""
+ """Evaluate typed questions, running any opt-in hooks around the inference.
+
+ `lang` selects a per-language temperature override (see `lang_temperatures`), matching the
+ PyTorch `Agent.system_one` signature so either backend is a drop-in for the other.
+ """
active = compose_hooks(self.hooks, hooks, on_predict_start, on_predict_end)
raise_errors = self.hooks_raise if hooks_raise is None else bool(hooks_raise)
+ timeout = self.hooks_timeout if hooks_timeout is None else validate_timeout(hooks_timeout)
ctx = PredictContext(states=[state], questions=questions, model=self.model_id, agent=self,
max_len=max_len, head_max_len=head_max_len)
try: