入门指南
欢迎使用 Tiny-DL-Inference!本指南将帮助你开始使用这款高性能 WebGPU 深度学习推理引擎。
什么是 Tiny-DL-Inference?
Tiny-DL-Inference 是一个生产就绪、零依赖的深度学习推理引擎,基于 WebGPU 构建。它通过从零开始实现神经网络算子,展示了对 AI 加速和异构计算的深入理解。
快速导航
安装
bash
npm install tiny-dl-inference1
bash
pnpm add tiny-dl-inference1
bash
yarn add tiny-dl-inference1
首次推理
以下是一个最小示例:
typescript
import { GPUContext, Tensor, ReLUOperator } from 'tiny-dl-inference';
// 初始化 GPU 上下文
const context = new GPUContext();
await context.init();
// 创建输入张量
const input = Tensor.fromArray(context,
new Float32Array([1.0, -2.0, 3.0, -4.0]),
[1, 4, 1, 1]
);
// 运行 ReLU 激活
const relu = new ReLUOperator(context);
const output = await relu.forward([input]);
// 获取结果
const result = await output.download();
console.log(result); // Float32Array([1, 0, 3, 0])
// 清理资源
input.destroy();
output.destroy();
context.destroy();1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
下一步
浏览器支持
Tiny-DL-Inference 需要 WebGPU 支持。详情请参见 浏览器兼容性。