WebGPU Execution Provider
The WebGPU Execution Provider enables GPU-accelerated inference in web browsers using the WebGPU API, providing high-performance machine learning inference directly in the browser.When to Use WebGPU EP
Use the WebGPU Execution Provider when:- You’re building web applications with ML inference
- You need GPU acceleration in the browser
- You want better performance than WebAssembly CPU execution
- Your users have modern browsers with WebGPU support
- You’re deploying client-side ML applications
- You want to reduce server costs by running inference on client devices
Key Features
- GPU Acceleration: Leverage user’s GPU for fast inference
- Cross-Platform: Works on Windows, macOS, Linux, ChromeOS
- Modern API: Based on next-generation graphics API
- Better Performance: 5-10x faster than WebAssembly CPU
- Privacy-Friendly: Inference runs locally, no data sent to server
- Progressive Enhancement: Fallback to CPU when GPU unavailable
Prerequisites
Browser Support
WebGPU is supported in: Desktop:- Chrome/Edge 113+ (Windows, macOS, Linux, ChromeOS)
- Safari 18+ (macOS)
- Firefox (experimental, enable via flag)
- Chrome Android 113+ (limited support)
- Safari iOS 18+ (limited support)
Checking Browser Support
Development Environment
- Node.js: 16+ (for building)
- ONNX Runtime Web: Latest version
- Modern bundler: Webpack, Vite, or Rollup
Installation
NPM Package
CDN (Development)
Building Your App
Basic Usage
JavaScript/TypeScript
With Fallback
React Example
Configuration Options
Session Options
WebGPU-Specific Options
Environment Configuration
Performance Optimization
Model Loading
Batch Processing
Warm-up
Tensor Management
Deployment
Webpack Configuration
Vite Configuration
Service Worker
Common Use Cases
Image Classification
Object Detection
Real-Time Video Processing
Browser Compatibility
| Browser | Version | Support | Notes |
|---|---|---|---|
| Chrome | 113+ | ✅ Full | Best support |
| Edge | 113+ | ✅ Full | Same as Chrome |
| Safari | 18+ | ✅ Good | macOS only |
| Firefox | - | ⚠️ Experimental | Enable flag |
| Chrome Android | 113+ | ⚠️ Limited | Some devices |
| Safari iOS | 18+ | ⚠️ Limited | Recent devices |
Troubleshooting
WebGPU Not Available
CORS Issues
Performance Monitoring
Memory Issues
Performance Comparison
Typical performance on modern laptop (relative to CPU):| Provider | Speed | Use Case |
|---|---|---|
| WebGPU | 5-10x | GPU available |
| WebAssembly (SIMD) | 2-3x | CPU only, modern browser |
| WebAssembly | 1x | Baseline |
Next Steps
- Learn about model optimization for web
- Explore web assembly optimization
- Check WebGPU specification