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
go lane floor 4552 -> 5697; digest golden replay helper; doc notes
Adeshina Lasisi5eb0260d28c4
diff --git a/.github/workflows/go.yml b/.github/workflows/go.ymlindex 168775a3..18a3d3f7 100644--- a/.github/workflows/go.yml+++ b/.github/workflows/go.yml@@ -130,12 +130,12 @@ jobs:LAYA_GO_FIXTURES: ${{ github.workspace }}/.go-goldensLAYA_CHECKPOINTS: ${{ github.workspace }}/laya-java/.work/checkpointsrun: go test -race -count=1 -json ./... > "$RUNNER_TEMP/go-test.json"- # A FLOOR, not the exact count. 4552 is what this lane reports with the router lifecycle on- # top of main (go 1.27.1, go 1.22.12 and the committed goldens), so it also catches a+ # A FLOOR, not the exact count. 5697 is what this lane reports with the router digest pins on+ # top of the router lifecycle (go 1.27.1, go 1.22.12 and the committed goldens), so it also catches a# package going missing. Restore "exactly" on the next green run.- name: No test was skippedif: ${{ !cancelled() }}- run: python laya-go/scripts/check_test_json.py "$RUNNER_TEMP/go-test.json" --min-tests 4552+ run: python laya-go/scripts/check_test_json.py "$RUNNER_TEMP/go-test.json" --min-tests 5697# go.mod declares go 1.22, so that is what a consumer may build with.- name: Run the tests on the oldest supported Go@@ -147,7 +147,7 @@ jobs:run: go test -count=1 -json ./... > "$RUNNER_TEMP/go-test-oldest.json"- name: No test was skipped on the oldest Go eitherif: ${{ !cancelled() }}- run: python laya-go/scripts/check_test_json.py "$RUNNER_TEMP/go-test-oldest.json" --min-tests 4552+ run: python laya-go/scripts/check_test_json.py "$RUNNER_TEMP/go-test-oldest.json" --min-tests 5697- uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2if: ${{ failure() }}diff --git a/laya-go/router/digests_golden_test.go b/laya-go/router/digests_golden_test.goindex 06d0b059..1dffbf62 100644--- a/laya-go/router/digests_golden_test.go+++ b/laya-go/router/digests_golden_test.go@@ -45,6 +45,50 @@ func setEnv(t *testing.T, v any) {os.Setenv("LAYA_SHA256_DIGESTS", fixtures.Str(t, v))}+// replayDigestRow checks one router_digests row against the Router and says whether it was an+// error row.+func replayDigestRow(t *testing.T, row fixtures.Object) (isErr bool) {+ t.Helper()+ setEnv(t, row.Must("env"))+ var opts []router.Option+ if arg := perModel(t, row.Must("argument")); arg != nil {+ opts = append(opts, router.WithSHA256Digests(arg))+ }+ r, err := router.New(opts...)+ if want, bad := row.Get("error"); bad {+ if err == nil || err.Error() != fixtures.Str(t, want) {+ t.Fatalf("New error = %v, want %q", err, want)+ }+ return true+ }+ if err != nil {+ t.Fatalf("New: %v", err)+ }+ table := map[router.Checkpoint]map[string]string{}+ for k, v := range perModel(t, row.Must("table")) {+ table[router.Checkpoint(k)] = v+ }+ got := r.SHA256Digests()+ if len(got) != len(table) {+ t.Fatalf("table = %v, want %v", got, table)+ }+ for k, want := range table {+ g, ok := got[k]+ if !ok || (g == nil) != (want == nil) || (want != nil && !reflect.DeepEqual(g, want)) {+ t.Fatalf("table[%s] = %#v, want %#v", k, g, want)+ }+ }+ shared := files(t, row.Must("shared"))+ for _, m := range fixtures.Obj(t, row.Must("expected")) {+ want := files(t, m.Value)+ got, err := r.ExpectedSHA256(m.Key, shared)+ if err != nil || (got == nil) != (want == nil) || (want != nil && !reflect.DeepEqual(got, want)) {+ t.Fatalf("ExpectedSHA256(%s) = %#v, %v, want %#v", m.Key, got, err, want)+ }+ }+ return false+}+func TestRouterDigestsGolden(t *testing.T) {root := fixtures.Load(t, "go_extra.json")rows := fixtures.List(t, root.Must("router_digests"))@@ -55,43 +99,8 @@ func TestRouterDigestsGolden(t *testing.T) {for i, rv := range rows {row := fixtures.Obj(t, rv)t.Run(strconv.Itoa(i), func(t *testing.T) {- setEnv(t, row.Must("env"))- var opts []router.Option- if arg := perModel(t, row.Must("argument")); arg != nil {- opts = append(opts, router.WithSHA256Digests(arg))- }- r, err := router.New(opts...)- if want, bad := row.Get("error"); bad {+ if replayDigestRow(t, row) {errs++- if err == nil || err.Error() != fixtures.Str(t, want) {- t.Fatalf("New error = %v, want %q", err, want)- }- return- }- if err != nil {- t.Fatalf("New: %v", err)- }- table := map[router.Checkpoint]map[string]string{}- for k, v := range perModel(t, row.Must("table")) {- table[router.Checkpoint(k)] = v- }- got := r.SHA256Digests()- if len(got) != len(table) {- t.Fatalf("table = %v, want %v", got, table)- }- for k, want := range table {- g, ok := got[k]- if !ok || (g == nil) != (want == nil) || (want != nil && !reflect.DeepEqual(g, want)) {- t.Fatalf("table[%s] = %#v, want %#v", k, g, want)- }- }- shared := files(t, row.Must("shared"))- for _, m := range fixtures.Obj(t, row.Must("expected")) {- want := files(t, m.Value)- got, err := r.ExpectedSHA256(m.Key, shared)- if err != nil || (got == nil) != (want == nil) || (want != nil && !reflect.DeepEqual(got, want)) {- t.Fatalf("ExpectedSHA256(%s) = %#v, %v, want %#v", m.Key, got, err, want)- }}})}diff --git a/laya-go/router/digests_test.go b/laya-go/router/digests_test.goindex 2f22a43a..d749fce4 100644--- a/laya-go/router/digests_test.go+++ b/laya-go/router/digests_test.go@@ -222,7 +222,9 @@ func TestExpectedSHA256Merge(t *testing.T) {if _, leaked := shared["x"]; leaked {t.Fatal("the result must be a fresh map")}- if again, _ := r.ExpectedSHA256("english", nil); again["x"] != "" {+ only, _ := r.ExpectedSHA256("english", nil) // no shared pin: the entry itself is tempting to return+ only["x"] = "y"+ if _, leaked := r.SHA256Digests()["english"]["x"]; leaked {t.Fatal("the result must not alias the table")}var ue *router.UnknownModelErrordiff --git a/laya-go/router/doc.go b/laya-go/router/doc.goindex cba4d981..d277557e 100644--- a/laya-go/router/doc.go+++ b/laya-go/router/doc.go@@ -51,7 +51,8 @@// names the hook's Go type. Digests: SHA256Digests is a copy, where Python's sha256_digests is a// public dict that can be edited after construction; a non-string digest in a nested// LAYA_SHA256_DIGESTS is an error from New, where Python hands it to the agent; two spellings of one-// checkpoint in WithSHA256Digests resolve in name order, where Python uses the dict's order. Not+// checkpoint in WithSHA256Digests resolve in name order, and several unknown names report the first in name order, where Python uses+// the dict's order. Not// ported, because the factory owns them: agent_kwargs and its reserved-name check (a factory passes// typed agent options), revision and revisions (no hub download), preload=True (New has no context,// call Preload), per-checkpoint lang_temperatures (a factory passes agent.WithLangTemperatures).diff --git a/laya-go/scripts/gen_go_fixtures.py b/laya-go/scripts/gen_go_fixtures.pyindex 3407cf92..124a38cd 100644--- a/laya-go/scripts/gen_go_fixtures.py+++ b/laya-go/scripts/gen_go_fixtures.py@@ -1824,15 +1824,35 @@ def _lifecycle_case(label, router_kwargs, hooks, ops):return record+def digests_row(env, argument, pin):+ """One router_digests row: Router(sha256_digests=argument) under LAYA_SHA256_DIGESTS=env (None:+ unset), and the map each checkpoint would be built with given the shared `pin`."""+ from unittest import mock+ from laya.router import Router, _digest_entry, _merge_expected_digests++ row = {"env": env, "argument": argument, "shared": pin}+ with mock.patch.dict(os.environ, {}, clear=False):+ os.environ.pop("LAYA_SHA256_DIGESTS", None)+ if env is not None:+ os.environ["LAYA_SHA256_DIGESTS"] = env+ try:+ router = Router(sha256_digests=argument)+ except ValueError as exc:+ row["error"] = str(exc)+ else:+ row["table"] = {k: router.sha256_digests[k] for k in sorted(router.sha256_digests)}+ row["expected"] = {+ name: _merge_expected_digests(pin, _digest_entry(router.sha256_digests, name))+ for name in ("english", "multilingual", "typed-decisions")}+ return row++def router_digests_family():"""What the real Router holds and merges for per-checkpoint SHA-256 pins: theLAYA_SHA256_DIGESTS layering (flat, nested, mixed, malformed), the `sha256_digests` argument(explicit None masks), the `agent_kwargs["expected_sha256"]` channel and the merge. Each row iseither an error text from Router(...) or the table plus, per checkpoint, the map_merge_expected_digests hands Agent (null: none passed). No model runs."""- from unittest import mock- from laya.router import Router, _digest_entry, _merge_expected_digests-a, b, c, d, e = ("%s" % ch * 64 for ch in "abcde")english = {"model.safetensors": a}multi = {"model.safetensors": b}@@ -1862,26 +1882,7 @@ def router_digests_family():{"typed": {"tokenizer.json": e}},]shared = [None, {}, shared_pin, {"model.safetensors": c}, {"model.safetensors": c, "tokenizer.json": d}]- rows = []- for env in envs:- for argument in arguments:- for pin in shared:- with mock.patch.dict(os.environ, {}, clear=False):- os.environ.pop("LAYA_SHA256_DIGESTS", None)- if env is not None:- os.environ["LAYA_SHA256_DIGESTS"] = env- row = {"env": env, "argument": argument, "shared": pin}- try:- router = Router(sha256_digests=argument)- except ValueError as exc:- row["error"] = str(exc)- else:- row["table"] = {k: router.sha256_digests[k] for k in sorted(router.sha256_digests)}- row["expected"] = {- name: _merge_expected_digests(pin, _digest_entry(router.sha256_digests, name))- for name in ("english", "multilingual", "typed-decisions")}- rows.append(row)- return rows+ return [digests_row(env, argument, pin) for env in envs for argument in arguments for pin in shared]def lifecycle_family():