# @tensorflow/tfjs-backend-webgpu

> This package adds a GPU accelerated [WebGPU](https://www.w3.org/TR/webgpu/) backend to TensorFlow.js. It currently supports the following models: - BlazeFace - BodyPix - Face landmarks detection - HandPose - MobileNet - PoseDetection - Universal sentence

Latest version **4.22.0** (published 2024-10-21) · Apache-2.0 license · 0 weekly downloads

## Install

```sh
npm install @tensorflow/tfjs-backend-webgpu
pnpm add @tensorflow/tfjs-backend-webgpu
yarn add @tensorflow/tfjs-backend-webgpu
bun add @tensorflow/tfjs-backend-webgpu
```

## Health

**Score 55/100 (C)** — status: stable.

Positive: has types; esm support; no vulnerabilities; high quality score; popular repo.

Warnings: low downloads; large bundle.

Negative: stale.

## Facts

| | |
|---|---|
| Version | 4.22.0 |
| Published | 2024-10-21 |
| First published | 2019-08-26 |
| Weekly downloads | 0 |
| License | Apache-2.0 |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 1 |
| Unpacked size | 16.8 MB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 19143 |
| Maintainers | delhibabu, laxma4675, fengwuyao, linchan, pyu10055, caisq, annxingyuan, linazhao128, mattsoulanille, jinjingforever |

## Links

- npm: https://www.npmjs.com/package/@tensorflow/tfjs-backend-webgpu
- Repository: https://github.com/tensorflow/tfjs
- Homepage: https://github.com/tensorflow/tfjs#readme
- Issues: https://github.com/tensorflow/tfjs/issues
- npm.io page: https://npm.io/package/@tensorflow/tfjs-backend-webgpu

## Dependencies (1)

- [@tensorflow/tfjs-backend-cpu](https://npm.io/package/@tensorflow/tfjs-backend-cpu.md) 4.22.0

## Recent versions

- 4.22.0 (latest) — 2024-10-21
- 4.23.0-rc.0 (next) — 2025-01-08
- 0.0.1-alpha.6 (beta) — 2021-06-04
- 4.22.0-rc.0 — 2024-10-14
- 4.21.0 — 2024-09-03
- 4.21.0-rc.0 — 2024-08-26
- 4.20.0 — 2024-06-03
- 4.20.0-rc.0 — 2024-05-28
- 4.19.0 — 2024-04-30
- 4.19.0-rc.0 — 2024-04-24
- 4.18.0 — 2024-04-17
- 4.18.0-rc.0 — 2024-04-11
- 4.17.0 — 2024-01-30
- 4.17.0-rc.0 — 2024-01-23
- 4.16.0 — 2024-01-11
- … 34 more at https://npm.io/package/@tensorflow/tfjs-backend-webgpu/versions

## README

# Usage

This package adds a GPU accelerated [WebGPU](https://www.w3.org/TR/webgpu/)
backend to TensorFlow.js. It currently supports
the following models:
- BlazeFace
- BodyPix
- Face landmarks detection
- HandPose
- MobileNet
- PoseDetection
- Universal sentence encoder
- AutoML Image classification
- AutoML Object detection
- Speech commands

Google Chrome started to support WebGPU by default in M113 on May 2, 2023.


## Importing the backend

### Via NPM

```js
// Import @tensorflow/tfjs or @tensorflow/tfjs-core
import * as tf from '@tensorflow/tfjs';
// Add the WebGPU backend to the global backend registry.
import '@tensorflow/tfjs-backend-webgpu';
// Set the backend to WebGPU and wait for the module to be ready.
tf.setBackend('webgpu').then(() => main());
```

### Via a script tag

```html
<!-- Import @tensorflow/tfjs or @tensorflow/tfjs-core -->
<script src="https://cdn.jsdelivr.net/npm/@tensorflow/tfjs/dist/tf.min.js"> </script>

<!-- Add the WebGPU backend to the global backend registry -->
<script src="https://cdn.jsdelivr.net/npm/@tensorflow/tfjs-backend-webgpu/dist/tf-backend-webgpu.js"></script>
<script>
// Set the backend to WebGPU and wait for the module to be ready
tf.setBackend('webgpu').then(() => main());
</script>
```

# FAQ

### When should I use the WebGPU backend?
The mission of WebGPU backend is to achieve the best performance among all
approaches. However, this target can not be met overnight, but we are committed
to supporting it with rapid and continuous performance improvement. Many
exciting features, like FP16, DP4A, will be brought in soon.

### How many ops have you implemented?
See [`register_all_kernels.ts`](https://github.com/tensorflow/tfjs/blob/master/tfjs-backend-webgpu/src/register_all_kernels.ts)
for an up-to-date list of supported ops. We love contributions. See the
[contributing](https://github.com/tensorflow/tfjs/blob/master/CONTRIBUTING.md#adding-functionality)
document for more info.

### Do you support training?
Maybe. There are still a decent number of ops that we are missing in WebGPU that
are needed for gradient computation. At this point we are focused on making
inference as fast as possible.

### Do you work in node?
Yes. If you run into issues, please let us know.

### How do I give feedback?
We'd love your feedback as we develop this backend! Please file an issue
[here](https://github.com/tensorflow/tfjs/issues/new).

# Development

## Building

```sh
yarn build
```

## Testing
Currently the Canary channel of Chrome is used for testing of the WebGPU
backend:

```sh
yarn test  # --test_env=CHROME_CANARY_BIN=/path/to/chrome
```

---
_Source: https://npm.io/package/@tensorflow/tfjs-backend-webgpu · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
