tensorflow / tfjs

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

tfjs converter cannot parse complex64 as dtype #8080

Closed Lutra-Fs closed 9 months ago

Lutra-Fs commented 9 months ago

System information

Describe the current behavior currently if a model has tf.cast(x, tf.complex64) it could be exported correctly but the browser/nodejs throws an error with

Uncaught (in promise) Error: Failed to cast to unknown dtype null
    at cast_ (cast.ts:45:11)
    at Object.cast__op (operation.ts:51:22)
    at executeOp20 (transformation_executor.ts:33:23)
    at operation_executor.ts:101:38
    at engine.ts:469:20
    at _Engine.scopedRun (engine.ts:480:19)
    at _Engine.tidy (engine.ts:467:17)
    at tidy (globals.ts:192:17)
    at operation_executor.ts:100:20
    at executeOp21 (operation_executor.ts:119:7)

See also https://github.com/kymatio/kymatio/issues/980. That issue's author meets the same issue.

Describe the expected behavior model runs without error

Standalone code to reproduce the issue Provide a reproducible test case that is the bare minimum necessary to generate the problem. If possible, please share a link to Colab/CodePen/any notebook.

I am trying to build one with the minimal info. Our Python code is in https://github.com/techlauncher-mlai-edge-physics/neural_net_physics_tf. I will update this field after I create the link. the tfjs model if helps: FNO2dLite_from_saved_model.zip a minimal tfjs model.json build with only a cast call. accepts [-1,10] shape. tfjs_test_model.zip

Other info / logs I am aware of https://github.com/tensorflow/tfjs/blob/master/tfjs-converter/src/operations/operation_mapper.ts#L482 and it seems like the DT_COMPLEX64 is not handled in that function, so a null will always return.

Lutra-Fs commented 9 months ago

add proper handling for DT.COMPLEX64 in https://github.com/tensorflow/tfjs/blob/master/tfjs-converter/src/operations/operation_mapper.ts?rgh-link-date=2023-11-23T20%3A35%3A02Z#L482 fix the issue. I am interested in submitting a PR but have no idea which test needs to be written to test this case.

gaikwadrahul8 commented 9 months ago

Hi, @Lutra-Fs

Thank you for bringing this issue to our attention and I was trying to replicate the same issue from my end and I'm also getting the same error message which you mentioned above in issue template, It seems like we haven't complex64 as dtype if I'm not wrong for reference I have added error log below

If you want to submit PR to take care of this issue please feel free to do it and please refer this file which may help you to write test cases for this issue, once you submit PR our team may help or guide you to write test cases if possible. Thank you.

(base) gaikwadrahul-macbookpro:tfjs-node-3.10 gaikwadrahul$ node index.js
testing keras model...
[ 1, 10 ]
/Users/gaikwadrahul/Desktop/tfjs-node-testing-to-update-doc/tfjs-node-3.10/node_modules/@tensorflow/tfjs-converter/dist/tf-converter.node.js:12836
        throw new Error("Failed to cast to unknown dtype ".concat(dtype));
              ^

Error: Failed to cast to unknown dtype null
    at cast_ (/Users/gaikwadrahul/Desktop/tfjs-node-testing-to-update-doc/tfjs-node-3.10/node_modules/@tensorflow/tfjs-converter/dist/tf-converter.node.js:12836:15)
    at Object.cast__op [as cast] (/Users/gaikwadrahul/Desktop/tfjs-node-testing-to-update-doc/tfjs-node-3.10/node_modules/@tensorflow/tfjs-converter/dist/tf-converter.node.js:12217:29)
    at executeOp$1 (/Users/gaikwadrahul/Desktop/tfjs-node-testing-to-update-doc/tfjs-node-3.10/node_modules/@tensorflow/tfjs-converter/dist/tf-converter.node.js:30075:25)
    at /Users/gaikwadrahul/Desktop/tfjs-node-testing-to-update-doc/tfjs-node-3.10/node_modules/@tensorflow/tfjs-converter/dist/tf-converter.node.js:30188:50
    at /Users/gaikwadrahul/Desktop/tfjs-node-testing-to-update-doc/tfjs-node-3.10/node_modules/@tensorflow/tfjs-core/dist/tf-core.node.js:4562:22
    at Engine.scopedRun (/Users/gaikwadrahul/Desktop/tfjs-node-testing-to-update-doc/tfjs-node-3.10/node_modules/@tensorflow/tfjs-core/dist/tf-core.node.js:4572:23)
    at Engine.tidy (/Users/gaikwadrahul/Desktop/tfjs-node-testing-to-update-doc/tfjs-node-3.10/node_modules/@tensorflow/tfjs-core/dist/tf-core.node.js:4561:21)
    at tidy (/Users/gaikwadrahul/Desktop/tfjs-node-testing-to-update-doc/tfjs-node-3.10/node_modules/@tensorflow/tfjs-core/dist/tf-core.node.js:8307:19)
    at /Users/gaikwadrahul/Desktop/tfjs-node-testing-to-update-doc/tfjs-node-3.10/node_modules/@tensorflow/tfjs-converter/dist/tf-converter.node.js:30188:24
    at executeOp (/Users/gaikwadrahul/Desktop/tfjs-node-testing-to-update-doc/tfjs-node-3.10/node_modules/@tensorflow/tfjs-converter/dist/tf-converter.node.js:30204:7)

Node.js v18.17.0
(base) gaikwadrahul-macbookpro:tfjs-node-3.10 gaikwadrahul$ 
Lutra-Fs commented 9 months ago

PR opened

gaikwadrahul8 commented 9 months ago

Hi, @Lutra-Fs

We really appreciate your submission of the PR addressing this issue. Our team will thoroughly review your PR and take the necessary actions accordingly. Thank you for your contribution

google-ml-butler[bot] commented 9 months ago

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