tensorflow / tfjs

A WebGL accelerated JavaScript library for training and deploying ML models.
https://js.tensorflow.org
Apache License 2.0
18.46k stars 1.92k forks source link

GraphModel contains a node with dynamic op, so model.predict gives error #7564

Closed sickopickle closed 1 year ago

sickopickle commented 1 year ago

Please make sure that this is a bug. As per our GitHub Policy, we only address code/doc bugs, performance issues, feature requests and build/installation issues on GitHub. tag:bug_template

System information

Describe the current behavior

When I try to do model.predict(), I get the following error:

Error: This execution contains the node 'StatefulPartitionedCall/model/bidirectional_2/forward_lstm_2/PartitionedCall/while/exit/_370', which has the dynamic op 'Exit'. Please use model.executeAsync() instead. Alternatively, to avoid the dynamic ops, specify the inputs [StatefulPartitionedCall/model/bidirectional_2/forward_lstm_2/PartitionedCall/TensorArrayV2Stack/TensorListStack]

I didn't know what specifying the inputs meant, so I asked chatGPT, which told me to do model.predict({'StatefulPartitionedCall/model/bidirectional_2/forward_lstm_2/PartitionedCall/TensorArrayV2Stack/TensorListStack':input);

I tried this, and it gave me the same error except with backward_lstm_2 instead of forward_lstm_2, so I changed it to model.predict({'StatefulPartitionedCall/model/bidirectional_2/forward_lstm_2/PartitionedCall/TensorArrayV2Stack/TensorListStack':input, 'StatefulPartitionedCall/model/bidirectional_2/backward_lstm_2/PartitionedCall/TensorArrayV2Stack/TensorListStack':input};

This then resolved the previous errors, but gave me this new error:

Error in matMul: inner shapes (12) and (256) of Tensors with shapes 3,12 and 256,149 and transposeA=false and transposeB=false must match.

I know that the input shape of the LSTM layer is 256, which is probably the reason for this. I do not understand what the original error message of "specify the inputs" refers to, and when I tried to use executeAsync, the output was something like this: {"_A": null, "_x": 0, "_y": 0, "_z": null}.

Describe the expected behavior

Able to do model.predict() succesfully. Additionally, why is there no predictAsync? It is part of the docs, but when I run it, it says it does not exist / undefined.

Standalone code to reproduce the issue

I cannot upload binary and json files for my model, it seems, but the error comes from the Bidirectional LSTMs, so it should reproduce from any BLSTM model.

Other info / logs Include any logs or source code that would be helpful to diagnose the problem. If including tracebacks, please include the full traceback. Large logs and files should be attached.

gaikwadrahul8 commented 1 year ago

Hi, @sickopickle

Aplogize for the delayed response and Could you please help me with command which you're using for tfjs-convertor ? I found similar issue #4579 and if you convert the model with --control_flow_v2=true that error should go away please check this comment so could you please try to convert model with --control_flow_v2=true and let us know whether is it resolving your issue or not ?

If issue still persists please let us know with error log if you get different error log ? Thank you!

google-ml-butler[bot] commented 1 year ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed in 7 days if no further activity occurs. Thank you.

google-ml-butler[bot] commented 1 year ago

Closing as stale. Please @mention us if this needs more attention.

google-ml-butler[bot] commented 1 year ago

Are you satisfied with the resolution of your issue? Yes No

sickopickle commented 1 year ago

I did set the control flow v2 as true. It still did not work.

shamoqianting commented 2 months ago

Hi, @sickopickle

Aplogize for the delayed response and Could you please help me with command which you're using for tfjs-convertor ? I found similar issue #4579 and if you convert the model with --control_flow_v2=true that error should go away please check this comment so could you please try to convert model with --control_flow_v2=true and let us know whether is it resolving your issue or not ?

If issue still persists please let us know with error log if you get different error log ? Thank you!

encounter same issue Error: This execution contains the node 'StatefulPartitionedCall/assert_equal_9/Assert/AssertGuard/branch_executed/_142', which has the dynamic op 'Merge'. Please use model.executeAsync() instead. Alternatively, to avoid the dynamic ops, specify the inputs [StatefulPartitionedCall/NoOp] I tried to use --control_flow_v2=true option when I use tensorflowjs-converter. But it didn't work.