LJTSG commited on
Commit
8a927ce
Β·
verified Β·
1 Parent(s): eb39e28

Upload README.md with huggingface_hub

Browse files
Files changed (1) hide show
  1. README.md +104 -0
README.md ADDED
@@ -0,0 +1,104 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ library_name: wllama
3
+ tags:
4
+ - gemma
5
+ - gemma-4
6
+ - webgpu
7
+ - browser-inference
8
+ - mixture-of-experts
9
+ - moe
10
+ - strix-halo
11
+ - unified-memory
12
+ - wllama
13
+ - first-of-its-kind
14
+ language:
15
+ - en
16
+ license: apache-2.0
17
+ pipeline_tag: text-generation
18
+ base_model: google/gemma-4-26b-a4b-it
19
+ ---
20
+
21
+ # Gemma-4-26B-A4B in the Browser via WebGPU
22
+
23
+ **Gemma-4-26B-A4B-it (MoE, 3.8B active params per token) running in a browser tab via WebGPU at 23 tokens/second.** 20GB GGUF loaded into WebGPU memory on AMD Strix Halo iGPU (64GB unified memory).
24
+
25
+ ## What This Is
26
+
27
+ A working setup for running Gemma-4-26B-A4B-it in the browser using [wllama](https://github.com/ngxson/wllama) (WASM binding for llama.cpp) with a **patched WebGPU backend** that fixes a buffer aliasing bug in the GLU/GeGLU shader.
28
+
29
+ This is, to our knowledge as of May 2026, the **largest model successfully run in a browser via WebGPU** β€” 20GB of Q5_K_XL weights loaded into 31.5GB of available WebGPU memory on a consumer iGPU.
30
+
31
+ ## Key Findings
32
+
33
+ ### WebGPU Memory on Strix Halo
34
+ - **31.5 GB** available to a single Chrome tab (tested empirically)
35
+ - 64GB unified memory, no discrete GPU needed
36
+ - `maxBufferSize` reports 2GB per buffer, but total allocation far exceeds this
37
+
38
+ ### Performance
39
+ - **23 tokens/second** decode speed
40
+ - **~2 minutes** model loading (20GB via byte-range fetch)
41
+ - **Quiet operation** β€” same model through llama-server Vulkan thrashes the machine; browser WebGPU (D3D12 path) runs silently
42
+
43
+ ### The Bug We Fixed
44
+ llama.cpp's WebGPU backend (`ggml-webgpu.cpp`) has a buffer aliasing bug in the GLU shader that crashes all Gemma-4 MoE models. The GeGLU operation binds overlapping regions of the same GPU buffer as separate writable storage bindings β€” Vulkan allows this, WebGPU forbids it.
45
+
46
+ **The fix:** When `src0` and `src1` tensor views overlap (share the same backing buffer), force the NO_SPLIT shader variant which reads both halves from a single binding with offset computation. This follows the same pattern as PRs [#22266](https://github.com/ggml-org/llama.cpp/pull/22266) (RMS_NORM_MUL) and [#22456](https://github.com/ggml-org/llama.cpp/pull/22456) (SSM_SCAN).
47
+
48
+ **Files changed:**
49
+ - `ggml-webgpu-shader-lib.hpp` β€” Added overlap detection to GLU pipeline key
50
+ - `ggml-webgpu.cpp` β€” Skip separate src1 binding when overlapping
51
+ - `glu.wgsl` β€” Added INPLACE mode for src0/dst overlap case
52
+
53
+ ## Quick Start
54
+
55
+ ```bash
56
+ # 1. Clone this repo
57
+ git clone https://huggingface.co/LJTSG/gemma-webgpu
58
+
59
+ # 2. Split your Gemma GGUF into <2GB chunks
60
+ llama-gguf-split --split-max-size 512M /path/to/gemma-4-26B-A4B.gguf ./model_splits/gemma-26b
61
+
62
+ # 3. Start the server
63
+ node serve_gemma.js
64
+
65
+ # 4. Open http://localhost:8150
66
+ # Click "Load Model" β†’ wait for 20GB download β†’ "Generate"
67
+ ```
68
+
69
+ **Requirements:**
70
+ - Gemma-4-26B-A4B-it GGUF (Q5_K_XL or Q4_K_M)
71
+ - Node.js
72
+ - Chrome/Edge with WebGPU support
73
+ - GPU with **20+ GB** accessible via WebGPU (tested: AMD Strix Halo iGPU, 64GB unified)
74
+
75
+ ## Why Browser WebGPU?
76
+
77
+ On AMD Strix Halo (and likely other unified memory iGPU systems):
78
+ - **Vulkan path** (llama-server): fights the driver for GPU memory, thrashes, machine runs hot and loud
79
+ - **WebGPU path** (browser): goes through D3D12, the path AMD optimizes for. Silent, smooth, same speed
80
+
81
+ The browser's managed WebGPU context is genuinely better for sustained inference on iGPU hardware than native Vulkan.
82
+
83
+ ## Files
84
+
85
+ - `index.html` β€” Test page with Load/Generate buttons
86
+ - `serve_gemma.js` β€” Node.js server with Range requests + CORS/COEP/COOP headers
87
+ - `memory_test.html` β€” WebGPU memory ceiling allocation test
88
+ - `wllama-patch/` β€” The GLU aliasing fix (diff against wllama v3.4.1)
89
+
90
+ ## Related Work
91
+
92
+ - [LJTSG/mamba-webgpu](https://huggingface.co/LJTSG/mamba-webgpu) β€” First browser-native Mamba/SSM inference (hand-written WGSL shaders)
93
+ - [wllama](https://github.com/ngxson/wllama) β€” WASM binding for llama.cpp with WebGPU support
94
+ - [Llamas on the Web](https://reeselevine.github.io/llamas-on-the-web/) β€” WebGPU backend for llama.cpp
95
+
96
+ ## License
97
+
98
+ Apache 2.0
99
+
100
+ ## Credits
101
+
102
+ Built by Joshua ([@LJTSG](https://huggingface.co/LJTSG)) and Claude (Anthropic Opus 4.6).
103
+ Model: [google/gemma-4-26b-a4b-it](https://huggingface.co/google/gemma-4-26b-a4b-it).
104
+ Runtime: [wllama](https://github.com/ngxson/wllama) by ngxson, with patched WebGPU backend.