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 pull request #862 from thread3d/fix/scan-budget-in-place-rewrite

Nandakishore3abe8c06a4a
diff --cc laya/agent.py
index e3cd5687,0a335cc9..e997de0a
--- a/laya/agent.py
+++ b/laya/agent.py
@@@ -1560,9 -1561,18 +1561,18 @@@ class Agent(HookRegistry)
internal = {qid: self._to_internal(questions[qid]) for qid in ids}
budget, step, _ = window_budget(self.tok, [internal[qid] for qid in ids], max_len,
head_max_len, window=window, stride=stride)
+ # Snapshot the questions the scan was just sized against, BEFORE any start hook can
+ # rewrite them, and compare against this instead of `questions` itself. `==` over the
+ # mapping cannot see an in-place rewrite: a hook that adds options to
+ # `ctx.questions[q]["criteria"]` -- the `widen_for_high_cardinality` pattern in
+ # `docs/hooks/patterns.md`, and the case this guard exists for -- mutates the same nested
+ # dict the caller's mapping holds, so both sides change together and compare equal. A deep
+ # copy is independent, so `_check_scan_budget` sees the difference; a shallow one would
+ # share the nested dicts and miss it exactly as before.
+ asked = copy.deepcopy(questions)
- state_ids = self.tok(serialize_state(state).replace(self.tok.mask_token, " "),
- add_special_tokens=False)["input_ids"]
+ state_ids = encode_text(self.tok, serialize_state(state).replace(self.tok.mask_token, " "),
+ add_special_tokens=False)["input_ids"]
# Fits in one window: identical to a plain call, no windowing overhead. `windows` is still
# written, so the key is total over the three paths this method can take and a caller can
# ask "how much of the document did the model read?" without handling a KeyError on the