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
docs(router): say what the digest merge does NOT cover, and pin three untested guards
Adeshina Lasisi489fb8e18317
diff --git a/laya/router.py b/laya/router.pyindex 418f3724..48440676 100644--- a/laya/router.py+++ b/laya/router.py@@ -401,9 +401,12 @@ class Router(HookRegistry):passes on: `Router(revision=" ")` used to reach `resolve_revision`, where a truthy but blankstring suppressed the `LAYA_REVISION` fallback and left huggingface_hub's default, and is nowdropped before it gets there, so a Router configured with whitespace behaves like one- configured with nothing and `$LAYA_REVISION` applies. It is the one place a weaker source ends- up ahead of an explicit argument, and it is what "this configuration line was never filled in"- has to mean if `revision` and a `revisions` entry are to be read the same way.+ configured with nothing and `$LAYA_REVISION` applies. That is what "this configuration line was+ never filled in" has to mean if `revision` and a `revisions` entry are to be read the same way.++ It is one of two places a weaker source ends up ahead of an explicit argument. The other is a+ per-checkpoint digest entry from `LAYA_SHA256_DIGESTS`, which wins over an `expected_sha256`+ passed through `agent_kwargs`; see the class docstring.Anything else `laya.Agent` accepts is reachable through `agent_kwargs`, which is merged intoevery checkpoint the Router builds:@@ -413,9 +416,30 @@ class Router(HookRegistry):Router(agent_kwargs={"fast": True})`expected_sha256` there pins the same files on every checkpoint, which is what a single- resident checkpoint or a shared `tokenizer.json` wants. It is never discarded wholesale: where a- checkpoint also has digests of its own, from `sha256_digests` or from the environment, the two- maps are merged **file by file**, so a file only one of them names is still verified.+ resident checkpoint or a shared `tokenizer.json` wants. It is never discarded wholesale by a+ checkpoint's own digests: where one also has an entry, from `sha256_digests` or from a+ **per-checkpoint** `LAYA_SHA256_DIGESTS`, the two maps are merged **file by file**, so a file+ only one of them names is still verified.++ Two exceptions, both deliberate and both tested, because "merged file by file" is not the whole+ story and the difference is a supply-chain control:++ * A **flat** `LAYA_SHA256_DIGESTS` -- `{artifact: digest}` rather than `{model: {...}}` -- is+ not a layer here at all. `verify_digests` applies it itself, but only when nothing else pins+ (`if expected is None`), so ANY `expected_sha256` reaching `Agent`, from here or from a+ checkpoint entry, means the flat variable is not consulted for that load. Verified on real+ files: a flat variable pinning `model.safetensors` plus an `agent_kwargs` map pinning+ `tokenizer.json` loads a tampered `model.safetensors`. Use the per-checkpoint shape, or name+ every file you care about in one map, if you need both. This is unchanged from `main`.+ * An explicit `{}` or `None` entry MASKS what would otherwise apply -- that is what "load this+ one unverified" has to mean, and `test_an_explicit_none_entry_masks_a_flat_environment_map`+ pins it.++ And the precedence is per-checkpoint over shared regardless of where each came from, so a+ per-checkpoint entry synthesised from `LAYA_SHA256_DIGESTS` wins over an `expected_sha256`+ passed here in code. An environment variable beating an explicit argument is worth stating+ plainly on a control like this; `test_an_environment_pin_overrides_the_shared_one_per_checkpoint`+ is where that is pinned.For a file both name, the per-checkpoint entry wins. The two are not equally specific: the`agent_kwargs` map reaches every checkpoint the Router builds, and `model.safetensors` is the onediff --git a/tests/test_revision_pinning.py b/tests/test_revision_pinning.pyindex 0fe3274a..31e9c816 100644--- a/tests/test_revision_pinning.py+++ b/tests/test_revision_pinning.py@@ -23,7 +23,7 @@ from laya.revisions import ( # noqa: E402snapshot_revision,verify_digests,)-from laya.router import Router # noqa: E402+from laya.router import Router, _digests_from_env, _merge_expected_digests # noqa: E402class _StopLoad(Exception):@@ -868,5 +868,56 @@ class RouterRevisionFallbackTests(unittest.TestCase):self.assertEqual(self._effective(kwargs, env="bbb"), "bbb")+class ReviewGapTests(unittest.TestCase):+ """Guards an adversarial review found unpinned: each mutant below survived every lane."""++ def test_a_non_dict_per_checkpoint_entry_is_handed_on_untouched(self):+ """`_merge_expected_digests` hands a non-dict on so `verify_digests` owns the message.++ Dropping the guard let a list of pairs be `dict.update`-ed into a map and silently accepted+ as digests. Both shapes still fail closed, but only one of them fails in the right words.+ """+ self.assertEqual(_merge_expected_digests({"a": "1" * 64}, "nope"), "nope")+ self.assertEqual(_merge_expected_digests({"a": "1" * 64}, [("a", "1" * 64)]),+ [("a", "1" * 64)])++ def test_a_non_dict_shared_map_is_handed_on_untouched(self):+ """The same for the shared half, which had the same missing coverage."""+ self.assertEqual(_merge_expected_digests("nope", None), "nope")+ self.assertEqual(_merge_expected_digests(["a"], None), ["a"])++ def test_a_blank_revision_suppresses_the_environment_through_agent(self):+ """`(revision or env).strip()`: a truthy-but-blank argument wins the `or`, then strips away.++ The Router drops a blank before it reaches here, and that is tested. `Agent`/`laya.load` do+ not, so a config line that ends up whitespace silently loses the deployment's pin and gets+ huggingface_hub's default. Undocumented and untested before: the mutant that makes a blank+ behave like an absent value survived every lane. Pinned as the behaviour that exists, so a+ change to it is a decision rather than an accident.+ """+ with patch.dict(os.environ, {"LAYA_REVISION": "deadbeef"}, clear=False):+ self.assertEqual(resolve_revision("some/repo", None), "deadbeef")+ self.assertEqual(resolve_revision("some/repo", ""), "deadbeef")+ self.assertIsNone(resolve_revision("some/repo", " "))+ self.assertIsNone(resolve_revision("some/repo", "\t"))+ self.assertEqual(resolve_revision("some/repo", " aaa "), "aaa")++ def test_a_flat_environment_map_is_masked_by_any_other_pin(self):+ """The documented exception, asserted so the class docstring cannot drift from it again.++ `verify_digests` reads a flat `LAYA_SHA256_DIGESTS` only `if expected is None`, so anything+ reaching `Agent` as `expected_sha256` means the flat variable is not consulted. An earlier+ revision of the class docstring said the two were "merged file by file", which is true of+ the per-checkpoint shape and false of this one.+ """+ with patch.dict(os.environ,+ {"LAYA_SHA256_DIGESTS": json.dumps({"model.safetensors": "a" * 64})},+ clear=False):+ self.assertEqual(_digests_from_env(["english"]), {}) # flat: not a layer here+ merged = _merge_expected_digests({"tokenizer.json": "b" * 64}, None)+ self.assertEqual(merged, {"tokenizer.json": "b" * 64})+ self.assertNotIn("model.safetensors", merged)++if __name__ == "__main__":unittest.main()