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.
Python calibrationclassificationdecision-modelhuggingfacejevmodernbertmultilingualnlppythonpytorchroutingtyped-decisionszero-shot
fix(serve): keep LAYA_TOURNAMENT_GROUP within the one-pass cap
kmitul472f0986b365
diff --git a/docs/http-api.md b/docs/http-api.mdindex 18a8a88e..fefed7b2 100644--- a/docs/http-api.md+++ b/docs/http-api.md@@ -43,7 +43,7 @@ Everything is environment variables, so one image serves a laptop dev run and a| `LAYA_MAX_CONCURRENT` | requests admitted past auth at once; excess gets `503` | `16` || `LAYA_MAX_BATCH_TOKENS` | tokens one `/v1/systemone/batch` FORWARD PASS may collate (`states` x questions x row width); a larger batch is split into several passes, not refused | `131072` || `LAYA_JEV_STRICT` | serve the strict Jev wire contract: no root `routing`, no per-answer `action` / `answer_confidence`, no `confidence` on noul answers, and `usage` reduced to `input_tokens` + `output_tokens`. For clients that validate the response against the Jev contract with no extra fields | `0` |-| `LAYA_TOURNAMENT_GROUP` | answer a `choice` with more options than this by elimination, in groups of this size, on `/v1/systemone`, and raise its option cap from 100 to 255. See [Large choices](#large-choices-laya_tournament_group). Unset, or outside 2 to 255, is off | `0` |+| `LAYA_TOURNAMENT_GROUP` | answer a `choice` with more options than this by elimination, in groups of this size, on `/v1/systemone`, and raise its option cap from 100 to 255. See [Large choices](#large-choices-laya_tournament_group). Unset, or outside 2 to 100, is off | `0` |For a deployment published under a prefix such as `/laya`, set `LAYA_ROOT_PATH=/laya`.FastAPI uses it when generating OpenAPI and Swagger UI URLs. Configure the reverse proxy to@@ -294,7 +294,11 @@ the request is refused. Jev accepts up to 255. With `LAYA_TOURNAMENT_GROUP=16`,answers a choice with more than 16 options the way `laya.predict_tournament` does: the options arecut into groups of at most 16, each group is answered in one shared call, and the group winners goto a final call. Its option cap becomes 255. A choice of 16 or fewer, and every other question,-takes the usual path unchanged.+takes the usual path unchanged. The group size is limited to 2 to 100, the one-pass cap, so every+choice the raised cap newly admits is always narrowed rather than read in one pass it cannot fit.+A larger group is not a better one: each group is still read in one pass, and one pass loses+accuracy as its options grow (the measurement below), so keep the group small; 16 is what was+measured.The answer keeps the Jev shape, so the official SDK parses it:diff --git a/laya/serve.py b/laya/serve.pyindex 549689a8..be868373 100644--- a/laya/serve.py+++ b/laya/serve.py@@ -379,8 +379,10 @@ def _resolve_tournament_group() -> int:"""Group size for choices answered by elimination, from LAYA_TOURNAMENT_GROUP; 0 is off (#302).A choice with more options than this goes through `predict_tournament` in groups of this size.- Anything unset, unparseable, below 2 or above MAX_TOURNAMENT_CHOICE_OPTIONS leaves it off, so- the one-pass path is the default: no choice the cap admits has more options than such a group.+ Anything unset, unparseable, below 2 or above MAX_CHOICE_OPTIONS leaves it off, so the one-pass+ path is the default. The upper bound is what keeps the raised cap honest: every choice it newly+ admits has more than MAX_CHOICE_OPTIONS options, so it is always over the group and always+ narrowed, never handed to a one-pass read that cannot fit it."""raw = os.environ.get("LAYA_TOURNAMENT_GROUP")if not raw:@@ -389,7 +391,7 @@ def _resolve_tournament_group() -> int:n = int(raw)except ValueError:return 0- return n if 2 <= n <= MAX_TOURNAMENT_CHOICE_OPTIONS else 0+ return n if 2 <= n <= MAX_CHOICE_OPTIONS else 0def _resolve_idle_unload_seconds() -> float:diff --git a/nix/laya-serve.nix b/nix/laya-serve.nixindex 1efc4ad8..dc4f7900 100644--- a/nix/laya-serve.nix+++ b/nix/laya-serve.nix@@ -252,7 +252,7 @@ in};tournamentGroup = lib.mkOption {- type = lib.types.nullOr (lib.types.ints.between 2 255);+ type = lib.types.nullOr (lib.types.ints.between 2 100);default = null;example = 16;description = ''diff --git a/tests/test_serve.py b/tests/test_serve.pyindex 4b2aec90..e76d1f0f 100644--- a/tests/test_serve.py+++ b/tests/test_serve.py@@ -374,6 +374,26 @@ def test_tournament_answers_a_large_choice_in_the_jev_shape(monkeypatch):assert body["usage"]["input_tokens"] == 90[email protected]("group, n", [("100", 101), ("100", 150), ("100", 255), ("16", 101), ("2", 255)])+def test_every_choice_over_the_one_pass_cap_is_narrowed(monkeypatch, group, n):+ """A choice only the raised cap admits never reaches the one-pass path, at any valid group."""+ client, fake = _tournament_client(monkeypatch, group)+ r = client.post("/v1/systemone", json=_large_req(n))+ assert r.status_code == 200+ sizes = [len(q["criteria"]) for q in fake.calls[0].values()]+ assert len(sizes) == -(-n // int(group)) and sum(sizes) == n and max(sizes) <= int(group)+ assert len(r.json()["answers"]["queue"]["probabilities"]) == n+++def test_a_group_over_the_one_pass_cap_leaves_the_flag_off(monkeypatch):+ """`LAYA_TOURNAMENT_GROUP=200` with 150 options: off, so the clear cap refusal, not a budget one."""+ client, fake = _tournament_client(monkeypatch, "200")+ r = client.post("/v1/systemone", json=_large_req(150))+ assert r.status_code == 413+ assert "150 > 100" in r.json()["detail"]+ assert fake.calls == []++def test_tournament_accepts_up_to_255_options(monkeypatch):client, _ = _tournament_client(monkeypatch, "16")assert client.post("/v1/systemone", json=_large_req(255)).status_code == 200@@ -414,8 +434,8 @@ def test_batch_keeps_the_one_pass_cap_with_a_tournament_group(monkeypatch):@pytest.mark.parametrize("raw, want", [(None, 0), ("", 0), ("abc", 0), ("0", 0), ("1", 0), ("-4", 0),- ("2", 2), ("16", 16), ("255", 255),- ("256", 0)])+ ("2", 2), ("16", 16), ("100", 100),+ ("101", 0), ("200", 0), ("255", 0)])def test_tournament_group_resolution(monkeypatch, raw, want):if raw is None:monkeypatch.delenv("LAYA_TOURNAMENT_GROUP", raising=False)