mirror of
https://github.com/Niko1221/Strata.git
synced 2026-12-03 19:03:30 +07:00
[PR #3194] [Engine] serve: per-layer expert routing metrics for /metrics ("routing_counts", opt-in) #4496
Labels
No labels
needs-format
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
Niko1221/Strata#4496
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
📋 Pull Request Information
Original PR: https://github.com/Niko1221/Strata/pull/3194
Author: @blange48
Created: 10/19/2026
Status: 🔄 Open
Base:
main← Head:routing-counts📝 Commits (5)
c82cd96serve: per-layer expert routing metrics (--routing-counts, "routing_counts" in the config, opt-in)d2defb7serve: each layer's 8 most routed experts as their own counters (strata:expert_routed_by_expert_total)9888cffdocs: per-layer expert routing metrics ("routing_counts")7ede4a3docs/monitoring: an Experts row in grafana-strata.json for the routing_counts metrics47e57d9routing counts: replace the last file on Windows too; all 8 tests run as a script; the counts are decode windows only📊 Changes
6 files changed (+599 additions, -3 deletions)
View changed files
📝
docs/DETAILS.md(+16 -1)📝
docs/monitoring/grafana-strata.json(+413 -0)📝
serve/prometheus.py(+23 -0)📝
serve/server.py(+52 -2)📝
serve/test_prometheus.py(+34 -0)📝
src/program/generate.cpp(+61 -0)📄 Description
Problem and result
Which experts do the requests actually use? Today the only way to see it is a
--dump-routingtrace (~4 KB per generated token, rewritten at every start) and an offline script. This PR adds a cheap view of the same data on/metrics, so Prometheus and Grafana can show it./metrics./metricsgets anexpertssection: per layer, the experts seen, the top 32's share, the entropy in bits and the top 10 experts;strata:expert_routed_total, the per-layer gaugesstrata:expert_seen,strata:expert_top32_shareandstrata:expert_entropy_bits(labellayer), andstrata:expert_routed_by_expert_totalfor each layer's 8 most routed experts (labelslayer,expert). That is ~530 series, not 24,576.Related discussion
#1547, closed in the 0.2.0 tracker reset. The
/reopencheck passed there, but GitHub would not reopen it after the rebase force-push, so this is the same branch as a new pull request. The earlier review (SuperDistance, Windows builds included) is in #1547.Approach
--routing-counts PATH,--routing-counts-every MIN): oneuint64counter per (layer, expert), incremented where the routing trace reads the ids (drive_pool/drive_pool_multi, every layer of every decode window, drafted tokens included; prompt reads are not counted). Nothing is written per token. The counts are saved as JSON every minute between requests (the same spot as the expert-profile save) and on QUIT, through a temporary file renamed over the last one withstd::filesystem::rename, so it replaces the old file on Windows too. A 48 × 512 file is ~55-85 KB."routing_counts": "<path>", optional"routing_counts_every"): passes the flags, andGET /metricsreads the file, cached on its mtime.docs/DETAILS.md, and an Experts row indocs/monitoring/grafana-strata.json.Validation
Passed:
python serve/test_prometheus.pyon this head (47e57d95, rebased on main): 8 tests OK (summary with counts, entropy, an empty layer, a missing file; gauges; per-expert counters, at most 8 per layer; config key to engine flags). macOS, Python 3.CUDA_ARCHITECTURES=120, Linux, docker), thenpytest servein that image: 864 passed, 18 skipped, 1 failed:test_lifeline.py::test_the_portable_watcher_ends_the_child_when_the_server_is_killed(the POSIX watcher path inside a container; this PR does not touch it, I have not checked whether it fails on v0.2.0-beta alone).--batch 8 --batch-groups 4. 384strata:expert_routed_by_expert_totalseries exported at every release check, a Grafana row on top. Throughput with and without the key, 1 / 4 / 8 clients (T=0.7, 300 tokens, warm pass): 147 / 269 / 394 against 143 / 268 / 392 tok/s, within run-to-run noise. The counts agreed with a--dump-routingtrace of the same traffic (layer 0's top experts 382, 300, 324 in both; every layer counted the same number of times).Failed:
Not run:
Limits
🤖 Generated with Claude Code
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.