Skip to content

WebGPU spike: can the browser engine use the GPU? - #52

Merged
setoelkahfi merged 8 commits into
developmentfrom
spike/webgpu
Nov 28, 2026
Merged

setoelkahfi merged 8 commits into
developmentfrom
spike/webgpu

Conversation

@setoelkahfi

Copy link
Copy Markdown
Collaborator

This is a spike, not a feature to ship. It records whether onde's browser engine can use the GPU through WebGPU instead of running candle on the CPU (wasm simd128, single-threaded, as in #50). Everything lives under spikes/webgpu/ and does not touch the product crates.

Stacked on #50 (base feature/web-engine) so the diff shows only the spike files.

What's here

  • Two harnesses: candle wgpu (FerrisMind fork) and wllama (llama.cpp's WebGPU backend), plus a candle CPU baseline.
  • A GitHub Actions workflow (webgpu-spike.yml) that builds the wasm, downloads and caches the model, and benchmarks every path on macos-26 and ubuntu-latest. It runs only on workflow_dispatch and on pushes to spike/webgpu, so normal CI is untouched.
  • findings.md with the full results table, the pinned versions, the fork patches, and a recommendation.

Everything ran on GitHub-hosted runners. Local GPU runs panicked the laptop three times (Chrome exhausted 50 GB on a 24 GB machine), which is written up in findings.md.

Results

path prefill decode correctness
candle CPU wasm (current path) ~29 s 4.9 tok/s 19/20
wllama, GPU offload 111 ms 26.7 tok/s output mismatch
wllama, CPU only 587 ms 4.7 tok/s matches
candle wgpu (fork) varies 0.2-2.6 tok/s Chrome map_async failures, slow on WebKit

wllama with GPU offload was roughly 250x faster at prefill and 5x faster at decode than the current CPU path on the macos-26 runner. But its output did not match the CPU reference on that runner's paravirtual GPU. The native Metal path differed from native CPU on the same VM too, so this may be a VM artifact rather than a real bug.

Recommendation

Pursue wllama, park the candle wgpu fork. The next step is a run on real Apple Silicon to settle the correctness question, tracked in #51.

@setoelkahfi setoelkahfi self-assigned this Nov 17, 2026

@sigit-code-review sigit-code-review Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This spike adds a self-contained spikes/webgpu/ experiment that measures whether the browser engine can reach the GPU via WebGPU. It ships two harnesses — a candle wgpu fork (wgpu-candle) and wllama — plus a candle CPU wasm baseline, with a shared Cache Storage loader, a static dev server, a Playwright driver, a per-process RSS/time guard (added after a 49 GB Chrome OOM), CI fetch/bench scripts, and a report.mjs aggregator that compares generated tokens/text against the native CPU reference. The SHA-256 pinning of the model is good, and the guard is the right response to the earlier runaway allocation. Two issues worth addressing before relying on the wllama cell and the correctness reference.


Automated review by siGit Code Review · commit e18d853 · see the review dashboard

Comment thread spikes/webgpu/package.json Resolved
Comment thread spikes/webgpu/ci/fetch-model.sh Resolved
@sigit-code-review

Copy link
Copy Markdown

siGit Code Review couldn't finish this review: the model's reply could not be read. Mention @sigit-code-review to try again.


Automated review by siGit Code Review · commit c377def · see the review dashboard

Base automatically changed from feature/web-engine to development November 18, 2026 07:32
@sigit-code-review

Copy link
Copy Markdown

siGit Code Review couldn't finish this review: the model service was unavailable. Mention @sigit-code-review to try again.


Automated review by siGit Code Review · commit 93d9881 · see the review dashboard

@sigit-code-review

Copy link
Copy Markdown

This change's diff (57 changed files) is over the size budget for an automated review, so siGit Code skipped it. Splitting the change into smaller changes will get each part a review.


Automated review by siGit Code Review · commit 20a8139 · see the review dashboard

@sigit-code-review

Copy link
Copy Markdown

This change's diff (61 changed files) is over the size budget for an automated review, so siGit Code skipped it. Splitting the change into smaller changes will get each part a review.


Automated review by siGit Code Review · commit eb45e2c · see the review dashboard

@sigit-code-review sigit-code-review Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The spike adds three benchmark harnesses under spikes/webgpu/ — a candle CPU wasm baseline, a candle-wgpu (FerrisMind fork) harness, and a wllama (llama.cpp WebGPU) harness — plus the CI plumbing to run them: a model fetcher with SHA-256 pinning, a static server, a Playwright driver with an RSS/time guard born from the 2026-11-17 laptop panic, per-cell and native bench scripts, and a report aggregator. The earlier tokenizer-checksum finding is addressed (fetch-model.sh now pins and verifies tokenizer.json), and the wllama node_modules import is covered by the workflow's out-of-band install, so those threads are closed. The remaining issues are in the driver/report path: the run-page.mjs comment about not awaiting __start is wrong for wllama (Playwright awaits the returned promise), and the error paths drop window.__partial, which report.mjs relies on for GPU-event reporting of exactly the failing cells the spike cares about.


Automated review by siGit Code Review · commit 93d9881 · see the review dashboard

Comment thread spikes/webgpu/run-page.mjs Resolved
Comment thread spikes/webgpu/run-page.mjs Resolved

@sigit-code-review sigit-code-review Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This spike adds a full WebGPU evaluation harness under spikes/webgpu/, including two browser harnesses (candle-wgpu and wllama), a CPU baseline, benchmarking scripts, and a CI workflow that runs on GitHub-hosted runners. The spike is fully isolated from product code, with all dependencies and results local to the spike directory. The model and tokenizer are SHA-checked, and the harnesses all use the same Cache Storage entry for model bytes. The workflow builds, runs, and benchmarks each path, and the results are summarized in findings.md and a markdown table. Previous findings about missing tokenizer checks and out-of-band npm installs are addressed in the current diff.


Automated review by siGit Code Review · commit 8723e3c · see the review dashboard

setoelkahfi and others added 6 commits November 28, 2026 13:32
Adds the cpu-baseline and wgpu-candle browser harnesses, the fork patch,
the earlier local M4 results (labeled as pre-incident) and a workflow that
builds and benchmarks on macos-26 and ubuntu-latest.

wgpu-candle now awaits synchronize_async() after load, every prefill chunk
and every decode token, so the fork can free in-flight buffers on wasm.
guard.mjs watches every descendant of the driver, kills the browser past
4 GB per process or the time limit, and records peak RSS in the result.
The model comes from HF in CI (SHA-256 checked, cached); serve.mjs reads
it from MODEL_DIR, and the fork path deps are relative to a sibling
checkout instead of an absolute home path.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-Authored-By: siGit Code v1.7.10 <noreply@sigit.si>
Co-Authored-By: OndeCode v1.1.2 <noreply@ondeinference.com>
With one match, pattern downloads put the files straight into artifacts/,
so report.mjs found no native-* directory: the first run's table had no
native rows and every token comparison said "no ref". Give the artifact
its own path.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-Authored-By: siGit Code v1.7.10 <noreply@sigit.si>
Co-Authored-By: OndeCode v1.1.2 <noreply@ondeinference.com>
…meout

The Chrome wgpu cell on macos-26 was cancelled at the 20-minute job
timeout right after its bench rung lost the device, so the rest of the
run was never recorded. The rung caps add up to 26 minutes, so the
browser job now allows 35.

run() takes a drain_every argument (the page reads ?drain=N, the native
bench reads DRAIN_EVERY). The matrix adds wgpu-candle cells on macos-26
with drain 8 and 32 to show what the per-token drain costs in decode
speed; the guard still caps memory.

worker.js hooks GPUAdapter.requestDevice to record device.lost and
uncaptured errors, and report.mjs lists them per cell, because the Rust
side only surfaces "batch failed validation".

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-Authored-By: siGit Code v1.7.10 <noreply@sigit.si>
Co-Authored-By: OndeCode v1.1.2 <noreply@ondeinference.com>
wllama 3.13.0 (llama.cpp compiled to wasm, with its WebGPU backend)
reads the same GGUF from the same Cache Storage entry and runs through
the same browser matrix: macos-26 Chrome and WebKit, ubuntu Chrome, plus
n_gpu_layers=0 cells as its own CPU path. CI installs it from npm at the
pinned version; its wasm is fetched from jsDelivr at that version,
because the npm package does not ship it.

wllama exposes streamed text, not token ids, so report.mjs compares its
output with native CPU on the first 60 characters. run-cell.sh takes an
extra query string, serves wllama with cross-origin isolation, and
run-page.mjs no longer awaits the page's start hook.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-Authored-By: siGit Code v1.7.10 <noreply@sigit.si>
Co-Authored-By: OndeCode v1.1.2 <noreply@ondeinference.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: siGit Code v1.6.6-acp <noreply@sigit.si>
fetch-model.sh checked the model hash but only printed the tokenizer's, so a republished tokenizer.json would have changed the token-match reference without failing the job. It now checks the hash that all 22 downloads in runs 44087888201 and 44142779991 printed, and removes the file on a mismatch. findings.md lists the pin.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-Authored-By: siGit Code v1.7.10 <noreply@sigit.si>
Co-Authored-By: OndeCode v1.1.2 <noreply@ondeinference.com>

@sigit-code-review sigit-code-review Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Still looks good to me.

setoelkahfi and others added 2 commits November 28, 2026 14:10
actionlint has been failing the branch's "Lint workflows" check on them.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-Authored-By: siGit Code v1.7.10 <noreply@sigit.si>
Co-Authored-By: OndeCode v1.1.2 <noreply@ondeinference.com>
The spike is finished and its results are recorded in findings.md. The
matrix is 15 cells on hosted macOS runners, and two of them fail by
design, so running it on every push to the branch only left each new head
red. workflow_dispatch stays for anyone who wants to rerun it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: siGit Code v1.7.10 <noreply@sigit.si>
Co-Authored-By: OndeCode v1.1.3 <noreply@ondeinference.com>

@sigit-code-review sigit-code-review Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Small follow-up to the WebGPU spike workflow since the last review: the push trigger for spike/webgpu is removed so the matrix now runs only via workflow_dispatch (the added comment explains why — two cells fail by design and every push went red), the stage listing switches from ls -lR | head to find, and the wllama npm spec gets quoted. All three earlier threads (package.json dependency, tokenizer checksum, run-page await semantics, native_bench usage string) are addressed or settled and nothing here reopens them. The trigger removal is intentional and documented; the find replacement is fine under GitHub Actions' default bash -e (no pipefail, so a SIGPIPE from head can't fail the step).


Automated review by siGit Code Review · commit f53faca · changes since edb5ac1 · see the review dashboard

@setoelkahfi
setoelkahfi removed this pull request from stack #53 November 28, 2026 13:14
@setoelkahfi
setoelkahfi added this pull request to stack #66 November 28, 2026 13:15
@setoelkahfi
setoelkahfi merged commit 4b35fe6 into development Nov 28, 2026
21 checks passed
@setoelkahfi
setoelkahfi deleted the spike/webgpu branch November 28, 2026 13:31
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.

3 participants