Repository navigation
feat(go): router sample on the presets package - #1395
Merged
NandhaKishorM merged 2 commits intoOct 28, 2026
Merged
Conversation
Port of examples/29_presets_model_router.py: presets.Router() over three requests, then the tier policy. internal/gateway holds the policy and the printing; its test compares 7 cases with a Python-recorded golden (scripts/gen_router_policy_golden.py). Real-weights output (english graph) is identical to the Python example's.
…mple Golden gains tools-overrides-hard, sensitive-overrides-hard and tools-just-under; swapping the tools/difficulty branches or moving difficulty first now fails TestPolicyAndRowMatchPython. The golden generator takes route_tier and the row expression from examples/29 with ast instead of a copy.
NandhaKishorM
added a commit
that referenced
this pull request
Oct 28, 2026
24 PRs. Vietnamese kept off the English checkpoint (#1392), deciding-window attribution preserved through end hooks (#1369), RemoteRouter identifying itself with a configurable User-Agent (#1396), ten more inputs refused where they enter (#1372, #1394, #1397, #1398, #1400, #1401, #1402, #1403, #1404, #1405, #1406), per-language temperatures and per-call budgets in .NET and Rust (#1370, #1371), .NET calibration files (#1384), the Go router lifecycle, SHA-256 pins and routed inference (#1374, #1379, #1395), a C++ foundation (#1399, #1407), and parity-lane sharding that replaces the budget headroom added for 0.4.16 (#1373, #1375). Verified before tagging: all 92 suites pass, 640 tests, up from 612. ruff clean on both lists. laya-ts 1251 tests across 44 files, tsc --noEmit clean. Every generated-artifact gate clean on CPython 3.12 / unicodedata 15.0.0: Java 20 families match laya (9 unverified), UnicodeTables matches CPython 15.0.0, LanguageTables matches laya/lang.py, three Go tables_gen.go match, both laya-cpp .inc files match. Version agrees across pyproject.toml, laya.__version__ and nix/package.nix. README carries 0.4.17 only. Security audit of the merge diff, 362766 added lines over 480 files: zero obfuscation, zero secrets, zero boundary hits, zero binaries, no mode or symlink changes, 20 of 20 actions SHA-pinned including the new cpp.yml, npm install hooks unchanged, and no third-party host in any added line (example.com 90, github.com 2, download.pytorch.org 1, docs.rs 1). The 12 dynamic-exec hits are the C++ test harness invoking its own checker through sys.executable, the Go sample generator reading laya's own example by AST at development time, and one comment in rust.yml. Held: #1364 (unchanged, it moves a cross-port contract), #1381 (a #[doc(hidden)] but pub Rust hook that would ship as public API able to replace the forward pass), #1386 (route_batch switched from self.route to self._route, silently bypassing subclass overrides the docstring promises), and nine stacked port PRs that conflict with each other and need linearizing (#1377, #1378, #1380, #1382, #1383, #1385, #1387, #1388, #1389, #1390). Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Owner
|
Merged. Building the router sample on the Generating the policy golden from a script, with the fixture committed next to the test, keeps the sample's expectations checkable instead of decorative. Shipped in 0.4.17. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
laya-go: router sample on the presets package
Adds
laya-go/samples/router, a runnable port ofexamples/29_presets_model_router.py: three requests go throughpresets.Router(), then a tier policy (sensitive or tools overrides difficulty) prints the side-by-side table, the policy lines and the closing notes. Same nested module asquickstartandbenchmark; the root stays cgo-free.Differences from Python
laya.router_questions()presets.Router(){"request": ...}dictlang.Object{{Key: "request", ...}}(a map would sort keys)*ScoreAnswer,*ChoiceAnswer,*NoulAnswer; a wrong type is an error, not a zeromax(items, key=value)describe, table, policydescribe)load("english")onnx.Open(graph)+agent.Open(os.DirFS(checkpoint), sess)Tests (
internal/gateway, no weights)TestPolicyAndRowMatchPython: 10 cases againsttestdata/policy.json. The golden is recorded bysamples/scripts/gen_router_policy_golden.py [--check], which extractsroute_tierand the table-row expression fromexamples/29_presets_model_router.pywithast(asserting both are present), so a change to the example fails--check. Three thresholds: difficulty 1.5 (at-edge and just-under),needs_tools0.5 (at-edge and just-under 0.4999),is_sensitive0.5 (at-edge, insidesensitive-overrides-tools; no just-under case). Branch order:tools-overrides-hard,sensitive-overrides-hard,sensitive-overrides-tools, plus a probability tie in the domain argmax.TestReadRejectsWrongAnswerTypes,TestReportShape.TestPolicyAndRowMatchPython:>= 1.5to> 1.5;is_sensitive >= 0.5to>; domain tie takes the last label; sensitive and tools branches swapped; tools and difficulty branches swapped; difficulty branch moved first.--min-testsfloor moves and the root lane is untouched.Real-weights e2e (english checkpoint,
onnx/englishgraph, ORT 1.30.0, arm64 CPU)The Python side runs the example's own source (loader swapped for
ONNXAgenton the same graph, banner anddescribedropped).ref.pyrewrites Python's headings into the Go form;diffof the two outputs after that reformat: empty (16 lines).Identical in Go and Python at the printed precision.
Related: router lifecycle #1374 (the router preset's lifecycle half is separate); siblings merged: #1306 to #1311.