Backends
torch.node.js supports two GPU backends with the same unified API. While the default is Dawn (Googles Chromium WebGPU engine), you can optionally use wgpu-native (Rust-based WebGPU) for specific use cases.

Dawn (Default)
The default backend uses Google Dawn, the exact same engine that powers WebGPU in the Chrome browser.
import torch from '@torchjsorg/torch-node';
// Uses Dawn by default
const tensor = torch.zeros([2, 3]);Advantages
- Full Parity: Matches Chrome browser behavior exactly.
- Robust: Benefit from Googles extensive testing and performance optimization.
- Polling: Handles GPU polling automatically without manual intervention.
wgpu-native
An alternative backend built on wgpu-native, the Rust implementation used by Firefox.
import torch from '@torchjsorg/torch-node/wgpu-native';
// Uses wgpu-native backend
const tensor = torch.zeros([2, 3]);Advantages
- Synchronous Validation: Catch shader errors immediately during execution.
- Resource Control: Offers finer control over WebGPU adapter reuse.
- Rust Speed: Extremely low overhead for high-frequency operations.
Backend Selection
| Backend | Best For | Engine |
|---|---|---|
| Dawn | Production, Chrome parity | C++ / Chromium |
| wgpu-native | Debugging, Firefox parity | Rust / wgpu |
Environment Configuration
You can force specific adapter behavior using environment variables:
# Request a specific hardware vendor
WGPU_ADAPTER_NAME="NVIDIA";
# Enable extra validation layers for debugging
WGPU_VALIDATION=1;