From 03ed7dce2ba711e14f987aae71e65cb7e855ee1c Mon Sep 17 00:00:00 2001 From: Jiajia Qin Date: Mon, 22 May 2023 14:34:43 +0800 Subject: [PATCH] Recover the default backend --- tfjs-core/src/ops/tensor.ts | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tfjs-core/src/ops/tensor.ts b/tfjs-core/src/ops/tensor.ts index a495e7523b5..9b664e07a07 100644 --- a/tfjs-core/src/ops/tensor.ts +++ b/tfjs-core/src/ops/tensor.ts @@ -55,6 +55,7 @@ import {makeTensor} from './tensor_ops_util'; * const customBackend = new tf.MathBackendWebGL(customCanvas); * tf.registerBackend('custom-webgl', () => customBackend); * } + * const savedBackend = tf.getBackend(); * await tf.setBackend('custom-webgl'); * const gl = tf.backend().gpgpu.gl; * const texture = gl.createTexture(); @@ -94,6 +95,7 @@ import {makeTensor} from './tensor_ops_util'; * // so: * * const tex = a.dataToGPU(); + * await tf.setBackend(savedBackend); * ``` * * ```js @@ -146,6 +148,7 @@ import {makeTensor} from './tensor_ops_util'; * return gpuReadBuffer; * } * + * const savedBackend = tf.getBackend(); * await tf.setBackend('webgpu').catch( * () => {throw new Error( * 'Failed to use WebGPU backend. Please use Chrome Canary to run.')}); @@ -166,6 +169,7 @@ import {makeTensor} from './tensor_ops_util'; * b.dispose(); * result.dispose(); * aBuffer.destroy(); + * await tf.setBackend(savedBackend); * ``` * @param values The values of the tensor. Can be nested array of numbers, * or a flat array, or a `TypedArray`, or a `WebGLData` object, or a