Weird output with tfjs on wasm backend (with no warnings)

This could be a bug with the wasm backend, or it could be me doing something silly.

In the following snippet tfjs proudces garbage output as shown in this screenshot.
Screenshot (2849)

Using the WebGL or CPU backend however produces the below screenshot, which is the expected result (see this If this was the cause of using some unsupported op then I’d expect a warning or error logged, but currently nothing out of the ordinary is being written to the console.
Screenshot (2850)

Anyone have any idea what the matter is here?

Thanks for reaching out and welcome to the forum. So after consulting with the team it seems that you may be using an op that is partially implemented in WASM which is why you do not get an op not supported error - as technically it is supported, but not fully implemented yet so some parameters that are being sent to WebGL version are being thrown away / never used in the WASM version.

It seems your model is composed of the following ops:

Add: 51
AddN: 20
AddV2: 45
Const: 504
Conv2D: 22
Conv2DBackpropInput: 2
DepthwiseConv2dNative: 18
GatherV2: 40
Identity: 21
Maximum: 1
Mean: 82
Merge: 20
Minimum: 1
MirrorPad: 20
Mul: 86
Neg: 20
Pack: 4
Pad: 4
Placeholder: 1
Relu: 14
Rsqrt: 41
Shape: 23
Slice: 22
SquaredDifference: 41
StridedSlice: 14
Sub: 53
Switch: 60

This list was generated using your model.json file and then within tfjs-converter directory executing:

yarn model-summary path_to_model_json_file

My understanding is that one of these ops may be “partial” and this is why error is occuring.

For now if you are unable to change code to not use the offending op, your best bet is to force WebGL to ensure it always uses this for execution assuming WebGL is available (which it should be on most regular laptops/smartphones as 97.9% support on CanIUse).


Thank you for the prompt response Jason! Yeah using the webgl backend seems like the way to go. As this is targeted towards smartphones it unfortunately doesn’t solve my problem since on both safari and chrome on iOS it doesn’t run because webgl 2.0 isn’t supported. But that seems like something I’ll just have to wait for until the tensorflowjs webgl backend is more mature.

So for WebGL 2.0 support on iOS would be a request for Apple Safari / iOS folk :slight_smile:

That being said, the above is just a warning. TensorFlow.js will fall back to WebGL 1.0 in this case so you can still use WebGL on these browsers on iOS but it will use the 1.0 version instead.

1 Like