From 0973c9d149b0ca43bd24b8696a3378093808c90d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dominik=20Lakato=C5=A1?= Date: Wed, 30 Sep 2020 19:48:50 +0200 Subject: [PATCH 1/3] fix any Promise type backend (e.g. WASM) initialization done inside Angular app --- tfjs-core/src/engine.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tfjs-core/src/engine.ts b/tfjs-core/src/engine.ts index 7a579d8a12b..2254fae4ee0 100644 --- a/tfjs-core/src/engine.ts +++ b/tfjs-core/src/engine.ts @@ -291,7 +291,7 @@ export class Engine implements TensorTracker, DataMover { try { const backend = registryFactoryEntry.factory(); // Test if the factory returns a promise. - if (Promise.resolve(backend) === backend) { + if (backend && typeof backend.then === 'function') { const promiseId = ++this.pendingBackendInitId; const success = backend From 9f6db5a7c17c2abf17371b89313498d575a44180 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dominik=20Lakato=C5=A1?= Date: Wed, 30 Sep 2020 20:52:34 +0200 Subject: [PATCH 2/3] fix type checking problem --- tfjs-core/src/engine.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tfjs-core/src/engine.ts b/tfjs-core/src/engine.ts index 2254fae4ee0..dcbb30b5e1e 100644 --- a/tfjs-core/src/engine.ts +++ b/tfjs-core/src/engine.ts @@ -291,7 +291,8 @@ export class Engine implements TensorTracker, DataMover { try { const backend = registryFactoryEntry.factory(); // Test if the factory returns a promise. - if (backend && typeof backend.then === 'function') { + if (backend && !(backend instanceof KernelBackend) + && typeof backend.then === 'function') { const promiseId = ++this.pendingBackendInitId; const success = backend From 50588f86a998f87d6a4f5c65c0d185b8d6f70718 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dominik=20Lakato=C5=A1?= Date: Thu, 1 Oct 2020 15:08:03 +0200 Subject: [PATCH 3/3] fix explained in comment fixes #3864 --- tfjs-core/src/engine.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/tfjs-core/src/engine.ts b/tfjs-core/src/engine.ts index dcbb30b5e1e..afc462294b6 100644 --- a/tfjs-core/src/engine.ts +++ b/tfjs-core/src/engine.ts @@ -290,7 +290,11 @@ export class Engine implements TensorTracker, DataMover { try { const backend = registryFactoryEntry.factory(); - // Test if the factory returns a promise. + /* Test if the factory returns a promise. + Done in a more liberal way than + previous 'Promise.resolve(backend)===backend' + as we needed to account for custom Promise + implementations (e.g. Angular) */ if (backend && !(backend instanceof KernelBackend) && typeof backend.then === 'function') { const promiseId = ++this.pendingBackendInitId;