Repository navigation
Run training and aggregation in a worker with page-owned WebRTC - #1287
Merged
Merged
Conversation
ale18V
force-pushed
the
feat/training-worker-page-client-alternative
branch
from
November 11, 2026 16:29
5c926c6 to
1b7f078
Compare
JulienVig
approved these changes
Nov 18, 2026
JulienVig
left a comment
Collaborator
There was a problem hiding this comment.
Great! Only minor comments
Comment on lines
+58
to
+65
| for await (const log of epochGenerator) { | ||
| send({ type: "batch", log }); | ||
| if (stopRequested) break; | ||
| } | ||
| if (stopRequested) { | ||
| stopped = true; | ||
| break; | ||
| } |
Collaborator
There was a problem hiding this comment.
You could use a labeled statement here to avoid breaking multiple times
Collaborator
Author
There was a problem hiding this comment.
Addressed in #1295. Added a labeled break, so Stop now exits the nested training loops directly.
ale18V
force-pushed
the
feat/training-worker-page-client-alternative
branch
from
November 25, 2026 11:23
ceff1dd to
620e3f3
Compare
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 & why
Training on the main thread can freeze the UI for large models. The worker now owns training, aggregation, weight serialization, and round coordination, while a peer-transport adapter connects page-owned WebRTC peers through signaling events and opaque bytes.
The benchmark in #1297 recorded 195 cases across three repetitions on Chrome 154/Linux, with the following one-peer median round-trip times for a complete WebRTC payload and its echoed response:
In the small CPU training-and-exchange workload, the median maximum page-timer lag fell from 36.1 ms to 1.1 ms, although the 64 MiB bridged WebRTC cases still had 58.2 ms median maximum lag. These results support the worker design's responsiveness benefit with modest measured exchange overhead, while remaining limited to one machine/browser, loopback networking, and a small CPU training workload.
Technical plan
training.worker.tsruns Disco with WebGL and CPU fallback, using the existing dataset loaders on files and labels passed by the page.peer_transport.tsconnects page-owned peers to the worker through a MessagePort; an injectable peer factory lets DecentralizedClient use this transport without changing its training protocol.worker_messages.tshandles startup, progress, errors, cancellation, and the final model, while TrainerDashboard manages the worker lifecycle and UI. Labeled inputs emit a singledatasetSource, using a temporary dataset for early CSV validation; evaluation constructs its own dataset and retains image filenames. Local validation covers webapp unit tests, lint, formatting, TypeScript checks, and the production build; browser E2E tests also run in CI.Deviations from plan
Following review, replaced the PageClient round-level bridge with peer transport and moved training dataset loading into the worker.
Todo
Explore ownership-aware buffer transfer to reduce copying: the isolated 64 MiB bridge round trip took about 57 ms versus near-clock-resolution transfer-only controls, suggesting copying/allocation dominates at large payload sizes. Validate other browsers/hardware, remote-network/full Disco sessions, and larger GPU models before generalizing the benchmark results. Measure peak memory and the final-model saving path separately.
Closes #758