Skip to content

serve --pm-router laya: Laya picks the expert before the PM's first round - #434

Merged
bong-water-water-bong merged 4 commits into
mainfrom
1bit/pm-laya-router
Oct 16, 2026
Merged

bong-water-water-bong merged 4 commits into
mainfrom
1bit/pm-laya-router

Conversation

@bong-water-water-bong

Copy link
Copy Markdown
Collaborator

Adds serve --pm-router laya. In --pm mode, the engine's Laya router now classifies the request before the PM's first round and picks the expert, instead of leaving the choice to the PM model.

  • config/pm-experts.json gets a pm.routes table that maps a Laya class to an expert (code -> code, long_doc -> code-heavy, prose -> reasoning, short -> none), plus pm.routes_min_confidence. Below the floor, the decision goes back to the PM.
  • app/pm.cpp validates the table and refuses a route that names an unlisted expert, a non-string route, a non-object table, or a floor outside 0..1. The reply carries pm.routing with the class, score and router time.
  • The routed expert is injected as a hint the PM acts on. Its tool result comes back through the normal delegate path, so the final answer is composed from a real tool result.
  • Without --pm-router, --pm behaves as before (pm_route test unchanged).

Tests: new pm_routes (unit) and pm_laya_route (needs a Laya checkpoint). Full ctest on Strix Halo: 34/34 passed. laya_classify still passes its 95.5% gate.

Live run on Strix Halo: a short arithmetic request routed to none and was answered by the PM. A coding request routed to code (score 0.41, about 174 ms in the router), and the PM delegated to Qwen3-Coder-30B-A3B on hrx through Lemonade. A general question routed to none.

Known limitation: Laya's confidence on long-form prose is low (0.09-0.23 on the labelled prose cases), so with the default floor those go back to the PM rather than to reasoning.

🤖 Generated with Claude Code

…ore the PM's first round

--pm alone leaves the expert choice to the served model (app/pm.cpp), which does not delegate on
its own for a plain coding request. --pm-router laya asks the engine's existing Laya classifier
(laya/route.cpp, the same scorer and the same checkpoint selection as --laya) which request class
an incoming chat is, and looks that class up in the experts file's new pm.routes table
(config/pm-experts.json): code -> code, long_doc -> code-heavy, prose -> reasoning, short -> the
PM answers itself. A class the router is less sure of than pm.routes_min_confidence (default
0.16, the measured route policy's floor) is also left to the PM.

The engine then makes the delegate call itself, as one normal tool round, so the PM composes the
final answer from a real tool result; the reply's pm.routing object carries the class, the score,
the router's decision time and the expert when one was chosen. The default router is unchanged,
so --pm on its own behaves exactly as before; --pm-router needs --pm and takes model or laya.

Tests: tests/pm_routes_test.cpp (the class -> expert table, the confidence floor, the flag
values, and bad experts files), tests/pm_laya_route.sh (the real classifier plus the fake PM
backend and fake Lemonade: a labelled code request routes to the table's expert and the expert's
answer comes back, a labelled short request reaches no expert), tests/pm_route.sh gains the
--pm-router refusals. docs/pm.md documents the flag, the table and the class names.
@github-actions

github-actions Bot commented Oct 16, 2026 •

Copy link
Copy Markdown

PR Reviewer Guide 🔍

(Review updated until commit 5468076)

Here are some key observations to aid the review process:

⏱️ Estimated effort to review: 4 🔵🔵🔵🔵⚪
🧪 PR contains tests
🔒 No security concerns identified
⚡ Recommended focus areas for review

Incorrect Confidence Floor Check

The check for routes_min_confidence in load_config only validates that the value is within the range [0, 1], but does not ensure that it is a valid floating-point number. If a non-numeric string is passed, it could lead to unexpected behavior or a crash during the conversion to float.

c.routes_min_confidence = p.value("routes_min_confidence", c.routes_min_confidence);
if (c.routes_min_confidence < 0.0f || c.routes_min_confidence > 1.0f)
    throw std::runtime_error("--pm-experts: pm.routes_min_confidence must be between 0 and 1");
Potential Uninitialized Use of `classify` Function

In serve.cpp, when --pm-router laya is used, the pm_cfg.classify function is set only if laya_daemon is available or if a scorer is available. However, if neither condition is met, pm_cfg.classify remains uninitialized, which could lead to undefined behavior when the PM tries to use it.

Incorrect Handling of Empty Expert Names in Routes

The code in load_config checks that each route value is a string, but it does not explicitly handle the case where an empty string is provided as an expert name. While the code correctly treats an empty string as a signal to leave the decision to the PM, it might be clearer to explicitly validate this behavior or document it more clearly.

for (const auto& [label, value] : p["routes"].items()) {
    if (!value.is_string())
        throw std::runtime_error("--pm-experts: pm.routes." + label + " must be an expert name or an empty string");
    c.routes[label] = value.get<std::string>();
}

`ctest` runs whatever binaries the build step produced, so the new pm_routes test reported
"Not Run" in CI — build/pm_routes_test was never built (the workflow lists every target a test
invokes, and pm_routes_test was missing from it). Add it next to the other app/ unit tests.

Reproduced from a clean build directory with the workflow's own configure line, target list and
ctest: 31/31 tests passed, pm_routes among them.
@github-actions

Copy link
Copy Markdown

Persistent review updated to latest commit 2b6a872

@github-actions

Copy link
Copy Markdown

Persistent review updated to latest commit 354f42a

@bong-water-water-bong
bong-water-water-bong enabled auto-merge (squash) October 16, 2026 22:57
@github-actions

Copy link
Copy Markdown

Persistent review updated to latest commit 5468076

@bong-water-water-bong
bong-water-water-bong merged commit e9b9a83 into main Oct 16, 2026
8 checks passed
@bong-water-water-bong
bong-water-water-bong deleted the 1bit/pm-laya-router branch October 16, 2026 23:41
bong-water-water-bong added a commit that referenced this pull request Oct 18, 2026
…awn_worker, census, #433) (#446)

* docs: the 2026-10-17/18 merges (HRX pins, DwarfStar, PM router and spawn_worker, census, #433)

The docs still described the pre-2026-10-18 line.

- README status: HRX pinned to AMD e3e6a976 + llama.cpp 8d9ce2c1a with the measured gate numbers;
  DwarfStar pinned to 5b013dc1bb75 (1BP v5) and its hardware check; the PM gains --pm-router laya
  and --pm-spawn-url; the census numbers of 2026-10-17.
- docs/PORTING.md: the HRX pin (step 2), the Laya source/revision bump (step 4), the 2026-10-17
  census (step 5).
- docs/registry.md: the 2026-10-17 census table, against registry/census.json, and the current
  unmapped list.
- docs/hrx.md: the engine#433 finding next to the other HRX0 known issues (no abort in 60 fresh
  loads; the 458-token prompt cannot come from this model template).
- docs/dwarfstar.md: what the 2026-10-17 pin was checked on, and that serve cannot set ds4 expert
  cache size.
- .github/workflows/bump-hrx.yml: the loom-jit trap is now described as the step that guards it,
  with #441 as the validated hand move and #422 still open.

Facts from merged PRs #441, #429, #438, #439, #434, #436 and the hardware comments on #441 (TPIN)
and #429 (TDS4).

* docs/hrx.md: the LoomC-symbol guard, which is the loom-jit trap, and #441 as the validated hand move

The workflow comment that described the trap cannot be pushed with this token (no workflow scope),
so the fact lives where the pin process is documented: docs/hrx.md, next to the hold.

---------

Co-authored-by: pi-zayap2 <bcloud@localhost>
bong-water-water-bong added a commit that referenced this pull request Nov 20, 2026
42b544465 hrx: the fused F16 routed-FFN decodes the table with the layout it was written with (engine#2861) (#445)
cd5f6b570 hrx: revert #434's loomc builder rename, which moved the fork onto an API the pinned hrx-system predates (engine#2916) (#446)
d102fbe02 test-hrx-ops: accept the HIP add-on route for a kquant-covered few-token MUL_MAT, and give the routed-MoE row its verdict (engine#2774) (#447)
da1636929 hrx: a code object carries a content identity of its add-on tree (engine#2935) (#444)
3b7cbfb14 hrx: reuse the 2..8-token kquant kernel for 1-bit prefill, scoped by a measured format guard (engine#2832) (#443)
a7fd21ac9 hrx: the routing layout follows the consumer, so the plan keeps one table (engine#2861) (#438)
db6c8a9b3 Revert "hrx: select the existing 2..8-token kquant reuse kernel above the add-on's prefill matcher (engine#2832)" (#442)
b021440f3 tests: a whole run of device cases answers 77 too, not 0 (engine#2912, the other half) (#441)
f3db40313 tests: a skipped device case answers 77, not 0 (engine#2912) (#439)
1ac44fc38 hrx: select the existing 2..8-token kquant reuse kernel above the add-on's prefill matcher (engine#2832) (#440)

registry/architectures.json regenerated by tools/registry_build.py; --check, --check-pins and copyright
--check pass on the staged tree. hw-gate starts by itself for a pin-moving PR (engine#2759).

Co-authored-by: bong-water-water-bong <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant