Check model for control flow or dynamic output shapes

Hi everyone!

I’ve been having this warning in the browser console:

“This model execution did not contain any nodes with control flow or dynamic output shapes. You can use model.execute() instead.”

So I have switched from .executeAsync to .execute and effectively the warning goes away. If I open
the TF.js documentation for executeAsync from: TensorFlow.js API
it reads: “…use this method when your model contains control flow ops.”

Now my problem is that I don’t really know beforehand if the model that I’m working with has or does
not have control flow. So, is there a way after calling tf.loadGraphModel to effectively test
if I can call execute instead of executeAsync?

I’ve checked the warning in the source code but it seems to me that this test is buried deep
inside the TF.js internals, I can see it at line 581 from tfjs-converter/src/executor/graph_executor.ts
that the test does: if (dynamicNode == null && !isFunctionExecution) { ... } to issue the warning to the console.

Thanks in advance,

You are all right, the testing is internal and I do not think TFJS has an external function for you to test directly. Right now, the best approach is to use execute directly and, if it does not work, then use executeAsync. If execute works, it means your models do not have control flow ops.

In the other words, try to use execute unless you get an error like ‘your model has control flow, please use executeAsync’, because execute is more performant.