torch.Tensor.Tensor.isWebGPU
Tensor.isWebGPU(): booleanCheck if tensor is on WebGPU device.
Returns true if this tensor is stored on the WebGPU device (GPU acceleration). This is useful for:
- Checking which device a tensor is on
- Verifying GPU initialization succeeded
- Conditional branching based on device
- Debugging device placement issues
- Device consistency: Operations between tensors on different devices will fail.
- GPU available: Check
torch.is_webgpu_available()before creating GPU tensors. - Immutable: Device cannot be changed after tensor creation - use
to(device)to move.
Returns
boolean– true if tensor is on WebGPU, false if on CPUExamples
await torch.init();
const x = torch.randn([3, 4]);
if (x.isWebGPU()) {
console.log('✓ Tensor is on GPU (accelerated)');
} else {
console.log('✗ Tensor is on CPU (fallback)');
}
// Check multiple tensors
const tensors = [x, y, z];
const allGPU = tensors.every(t => t.isWebGPU());
if (allGPU) {
console.log('All tensors on same device');
}See Also
- [PyTorch N/A (torch.js specific - PyTorch uses is_cuda)](https://pytorch.org/docs/stable/generated/N/A .html)
- isCPU - Check if tensor is on CPU
- torch.is_webgpu_available - Check if WebGPU is available
- device - Get the device name as string