FE-1314: Run experiment runs in parallel across workers - #9162
Draft
kube wants to merge 1 commit into
Draft
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
1 Skipped Deployment
|
An experiment ran every run in a single worker, using one core however many the machine had. Runs are independent, so they now split across one worker per logical core minus one, capped at the run count — measured at ~4x on 8 shards. Sharding cannot change results: seeds derive from the run's global index rather than its position in a shard, and per-frame statistics recombine through the metric accumulator monoids, so output is byte-identical at every shard count. Scalar frames carry their pre-reduction accumulator state, since a mean of means is not a mean.
kube
force-pushed
the
cf/fe-1314-run-experiment-runs-in-parallel-across-workers
branch
from
August 8, 2026 01:02
0b5348e to
986094b
Compare
4 tasks
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.
🌟 What is the purpose of this PR?
An experiment ran every one of its runs in a single Web Worker, so a 1000-run experiment used one core however many the machine had.
Runs are independent — separate seed, separate RNG state, separate frame buffers, no shared mutable state — so they can be split across workers. This shards them, by default one worker per logical core minus one so the editor stays responsive.
Measured on the SIR example, 2000 runs, 10-core machine: ~4.1× at 8 shards, with byte-identical merged output at every shard count.
🔗 Related links
🔍 What does this change?
Sharding must not change what an experiment reports. Two things make that hold:
frameValueon a scalar metric frame is already reduced and cannot be merged — a mean of means is not a mean — so frames now carry their pre-reduction accumulator state, which the metric monoids (empty/merge) recombine.No
SharedArrayBufferis needed: the app is not cross-origin isolated, and message-passing shards over independent runs need no shared memory.flowchart LR E[Experiment: N runs] --> P{shard plan} P -->|runs 0..k| W1[Worker 1] P -->|runs k..2k| W2[Worker 2] P -->|runs 2k..N| W3[Worker 3] W1 & W2 & W3 -->|per-frame accumulator state| M[merge monoid] M --> R[frame finalised at the slowest shard]Pre-Merge Checklist 🚀
🚢 Has this modified a publishable library?
This PR:
📜 Does this require a change to the docs?
The changes in this PR:
🕸️ Does this require a change to the Turbo Graph?
The changes in this PR:
Several experiments running at once each take the same number of workers, so they compete for cores and all slow down. Progress reports the slowest shard's position, so the bar never runs ahead of the results behind it.
🐾 Next steps
Stacked on top of this: place token capacity (FE-1237), a swappable backend interface (FE-1341), and the WebGPU backend (FE-1340).
🛡 What tests cover this?
shard-plan.test.tscovers the split;metrics/merge.test.tscovers monoid recombination;experiment.test.tscovers the shard watermark and that output is identical at every shard count. Benchmarks underbenchmarks/sharded-experiment*.mjs.❓ How to test this?
main, and that CPU use spans several cores.experimentShardCountset to 1, then unset — the reported distributions should be identical.