Skip to content

Document WebGPU feasibility and browser training benchmarks - #1240

Draft
ale18V wants to merge 10 commits into
mainfrom
research/issue-575-webgpu
Draft

ale18V wants to merge 10 commits into
mainfrom
research/issue-575-webgpu

Conversation

@ale18V

@ale18V ale18V commented Oct 2, 2026 •

Copy link
Copy Markdown
Collaborator

What & why

WebGPU is feasible for DISCO and ready for opt-in support across Local, Federated, and Decentralized topologies (Closes #575). This builds on top of the merged Tiny Shakespeare task (#1244).

  • Integration: Added @tensorflow/[email protected] to webapp. WebGPU is available as an opt-in via ?backend=webgpu with automated fallback to WebGL on failure.
  • Full End-to-End Validation & Convergence:
    • Local (Titanic): 10/10 epochs in 11.45s, IndexedDB model saving verified.
    • Federated (Titanic, 3 peers: 1 WebGPU + 2 Node): 5 rounds, reached 87.2% validation accuracy. Mixed-backend aggregation (browser WebGPU + Node CPU/C++) verified.
    • Decentralized (MNIST, 3 peers: 1 WebGPU + 2 Node): 10 rounds over WebRTC data channels, reached 100% validation accuracy (loss $5.72 \times 10^{-7}$).
    • Federated nanoGPT (Shakespeare, 3 peers: 1 WebGPU + 2 Node): 8 rounds, 312 aggregated gradient updates cluster-wide, loss monotonically converged from 10.83 down to 5.72 (perplexity reduced from 50,257 to ~350).
  • Correctness & TFJS WebGPU Bug Root Causes:
    • argMax Rank Mismatch: The GPT prediction shape mismatch previously hypothesized to be linked to closed upstream issue WebGPU: TransposeProgram WGSL shader fails with type mismatch on Chrome 141+ (Tint IR rewrite) tensorflow/tfjs#8638 was actually caused by TFJS's WebGPU kernel ArgMinMaxProgram (argminmax_webgpu.ts:30), which forces scalar reduction outputs from [] to [1], causing probs.argMax() on a 1D vector to return rank-1 rather than a rank-0 scalar. Fixed in DISCO's GPT.#predictSingle() using .asScalar().
    • tf.multinomial WGSL Shader Bug: For single-token sampling (batch=1, samples=1), WebGPU's MultinomialProgram WGSL shader evaluates UV coordinates coords / outShape as (0.0, 0.0). The shader's PRNG function evaluates to 0.0 unconditionally, causing sampling to always collapse to token index 0 (top-1 mode token \n). Fixed in DISCO by implementing CPU-assisted top-$k$ sampling.
    • (Note: Neither of these two WebGPU backend bugs currently has an open issue on tensorflow/tfjs; both are isolated and ready to be reported upstream with reproduction testcases.)
  • Recommendation: Keep WebGL as the default in production and enable WebGPU via opt-in (?backend=webgpu), as implemented.

The tested Linux setup used these Chrome GPU flags:

--enable-unsafe-webgpu --use-angle=vulkan --enable-features=Vulkan --disable-software-rasterizer

Technical documentation

Comprehensive benchmark timings, multi-peer convergence logs, and WebGPU kernel analyses are documented in:

@ale18V ale18V changed the title Document WebGPU feasibility and GPT training results Document WebGPU feasibility and cross-browser training benchmarks Oct 2, 2026
@ale18V ale18V changed the title Document WebGPU feasibility and cross-browser training benchmarks Document WebGPU feasibility and browser training benchmarks Oct 2, 2026
@ale18V
ale18V force-pushed the research/issue-575-webgpu branch from d42fa17 to e16c449 Compare October 2, 2026 16:42
@ale18V
ale18V force-pushed the research/issue-575-webgpu branch from e16c449 to 31f801d Compare October 2, 2026 18:48
@ale18V
ale18V changed the base branch from main to feat/issue-1243-shakespeare October 2, 2026 18:48
@ale18V
ale18V force-pushed the research/issue-575-webgpu branch from 31f801d to e6ca6e2 Compare October 3, 2026 11:06
@ale18V
ale18V added this pull request to stack #1245 October 3, 2026 11:14
@ale18V
ale18V force-pushed the research/issue-575-webgpu branch from caa6adf to c9c4e0e Compare October 5, 2026 16:05
Base automatically changed from feat/issue-1243-shakespeare to main October 5, 2026 16:21
@ale18V
ale18V force-pushed the research/issue-575-webgpu branch from c9c4e0e to 991f3c4 Compare October 5, 2026 16:21
ale18V added 6 commits October 6, 2026 14:58
…report

- Install @tensorflow/[email protected] in webapp
- Configure opt-in WebGPU selection via query param with WebGL fallback in main.ts
- Enable hardware WebGPU/Vulkan flags in Cypress browser launch options
- Support multi-peer federated and decentralized test servers for collaborative runs with 3+ participants
- Add E2E tests for backend selection, local Titanic on WebGPU, federated Titanic with 3 peers on WebGPU, and decentralized MNIST with 3 peers on WebGPU
- Document full training runs, convergence metrics, and cross-backend stability in docs/WEBGPU_FULL_RUNS.md
…ax shape bug

- Add 3-participant federated Shakespeare test harness (webapp/run_federated_experiment.ts)
- Record training loss curves and aggregation results in federated_shakespeare_webgpu_report.json
- Document root cause of GPT inference shape discrepancy: tfjs-backend-webgpu argMax on 1D tensor yields rank-1 shape [1] instead of rank-0 scalar []
- Update docs/WEBGPU_FULL_RUNS.md with Shakespeare federated training and text generation findings
@JulienVig

Copy link
Copy Markdown
Collaborator

On my MacBook Air with M2 chip:

Model M2 WebGL / WebGPU M2 speedup AMD 860M speedup (docs)
Titanic 22.3 / 6.3 ms 3.57× 1.38×
MNIST 63.7 / 26.0 ms 2.45× 1.08×
LUS 26.2 / 16.8 ms 1.55× 1.49×
Dog 37.7 / 20.0 ms 1.89× 1.61×
CIFAR MobileNet 179.8 / 40.2 ms 4.47× 1.21×
GPT nano 1153.7 / 176.3 ms 6.54× 3.24×

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

look if we can benefit from WebGPU support

2 participants