Tfjs-node + webgl backend

Hi all,

In my project, I bundle some code as a client-side library which imports the webgl backend (i.e. import @tensorflow/tfjs-backend-webgl;). Separately, I have some unit tests (using Jest) which import the node backend (i.e. import "@tensorflow/tfjs-node;). These tests import the files which import webgl backend.

When running the tests, I get the kernel warnings for webgl already being registered, e.g.:

The kernel 'ZerosLike' for backend 'webgl' is already registered

Functionally, everything seems to work fine, it’s simply that this double-register warning is there.

So, what is the proper method of including a backend for the client-side code while being able to test using the node backend with double registering the client-side backend? Perhaps a more general question is, is it possible to use both tfjs-node and a backend without getting this double-register warning?

Hi @scott ,

I apologize for the delay. As per my understanding, you shouldn’t load @tensorflow/tfjs-backend-webgl and @tensorflow/tfjs-node at the same time because they use the same system resources. Likewise, loading the same tfjs package multiple times can cause issues, as the first instance reserves those resources. While your code might appear to function, it could behave unexpectedly in certain situations and potentially crash.

Please let me know if this helps clarify things

Thank You!!!