Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tfjs converter cannot parse complex64 as dtype #8080

Closed
Lutra-Fs opened this issue Nov 23, 2023 · 5 comments · Fixed by #8083
Closed

tfjs converter cannot parse complex64 as dtype #8080

Lutra-Fs opened this issue Nov 23, 2023 · 5 comments · Fixed by #8083
Assignees

Comments

@Lutra-Fs
Copy link
Contributor

Lutra-Fs commented Nov 23, 2023

System information

  • Have I written custom code (as opposed to using a stock example script provided in TensorFlow.js):
  • OS Platform and Distribution (e.g., Linux Ubuntu 16.04): Windows 11 23590.1000 and WSL Arch
  • TensorFlow.js installed from (npm or script link): npm
  • TensorFlow.js version (use command below): 4.13.0
  • Browser version: Microsoft Edge 121.0.2220.3
  • Tensorflow.js Converter Version: 4.13.0

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 kymatio/kymatio#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 Lutra-Fs added the type:bug Something isn't working label Nov 23, 2023
@Lutra-Fs Lutra-Fs changed the title tfjs converter cannot parse complex64 tensors as dtype tfjs converter cannot parse complex64 as dtype Nov 23, 2023
@gaikwadrahul8 gaikwadrahul8 self-assigned this Nov 24, 2023
@Lutra-Fs
Copy link
Contributor Author

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
Copy link
Contributor

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
Copy link
Contributor Author

PR opened

@gaikwadrahul8
Copy link
Contributor

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

Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants