tfjs: Can not convert TensorFlow model to TensorFlowJS: Unsupported Ops in the model before optimization

Hi, I work on VS Code and we are trying to use TensorFlow for automatic programming language classification based on file content. To be concise, we need this working in a browser, thus we would like to use TensorFlowJS, and we would like to reuse this TensorFlow model https://github.com/yoeo/guesslang/tree/master/guesslang/data/model We are trying to convert this Model to a TensorFlowJs model using your conversion scripts and we are hitting the following issue:

$ tensorflowjs_wizard
2021-03-17 23:39:53.238316: W tensorflow/stream_executor/platform/default/dso_loader.cc:60] Could not load dynamic library 'libcudart.so.11.0'; dlerror: libcudart.so.11.0: cannot open shared object file: No such file or directory
2021-03-17 23:39:53.238359: I tensorflow/stream_executor/cuda/cudart_stub.cc:29] Ignore above cudart dlerror if you do not have a GPU set up on your machine.
Welcome to TensorFlow.js Converter.
? Please provide the path of model file or the directory that contains model files.
If you are converting TFHub module please provide the URL. /workspaces/tfjs-notebooks/master/guesslang-master/guesslang/data/model/saved_model.pb
? What is your input model format? (auto-detected format is marked with *) Tensorflow Saved Model *
? What is tags for the saved model? serve
? What is signature name of the model? signature name: predict
? Do you want to compress the model? (this will decrease the model precision.) No compression (Higher accuracy)
? Please enter shard size (in bytes) of the weight files? 4194304
? Do you want to skip op validation?
This will allow conversion of unsupported ops,
you can implement them as custom ops in tfjs-converter. No
? Do you want to strip debug ops?
This will improve model execution performance. Yes
? Do you want to enable Control Flow V2 ops?
This will improve branch and loop execution performance. Yes
? Do you want to provide metadata?
Provide your own metadata in the form:
metadata_key:path/metadata.json
Separate multiple metadata by comma.
? Which directory do you want to save the converted model in? /workspaces/tfjs-notebooks/src/new_model
? The output already directory exists, do you want to overwrite it? Yes
converter command generated:
tensorflowjs_converter --control_flow_v2=True --input_format=tf_saved_model --metadata= --saved_model_tags=serve --signature_name=predict --strip_debug_ops=True --weight_shard_size_bytes=4194304 /workspaces/tfjs-notebooks/master/guesslang-master/guesslang/data/model /workspaces/tfjs-notebooks/src/new_model
15:34
but alas...
ValueError: Unsupported Ops in the model before optimization
SparseFillEmptyRows, StringToHashBucketFast, SparseReshape, SparseSegmentSum, SparseSegmentMean
  1. Is it even possible to convert this model to TensorFlowJS?
  2. Do we have something misconfigured

I am a TensorFlow beginner so I apologise for not the nicest issue. Any help is appreciated. Thank you fyi @tylerLeonhardt

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Reactions: 1
  • Comments: 29

Most upvoted comments

@isidorn @TylerLeonhardt The execution issue has been fixed, and the model is compatible with TFJS now. you can try out the demo here https://storage.googleapis.com/tfjs-testing/guesslang-demo/index.html Since the model is fairly small and involves dynamic shaped string tensors, it is actually faster on CPU backend. Currently the demo is compiled with the latest code from the master branch of TFJS, we will release a new version next week, after that you should be able to use the npm package directly.

Closing this issue since the model has been fully supported with 3.7.0, please keep us posted on your progresses. cheers, happy Friday.

Super cool ✨ Next week I will try to look into integrating this into vscode, the week after I am on vacation, so I might look into it once I get back. Though maybe @TylerLeonhardt jumps on this in the meantime

Should we close this issue and continue the discussion in our repo? https://github.com/microsoft/vscode/issues/118455

Thanks a lot πŸ‘

@isidorn All ops are supported, we are investigating some issues with the model execution, will try to update here as it progresses.

@isidorn @TylerLeonhardt The extension looks very nice, and now we understood more about your use case, we will add those missing ops and keep you posted.

@tyler I just tried out your extension and this works great! Awesome job πŸ‘ @pyu10055 thanks again for making this possible!

I have commented with some ideas on what we should do in order to ship this to all our users ✨ https://github.com/microsoft/vscode/issues/118455

@TylerLeonhardt @isidorn we have just released 3.7.0, please take a look at the updated demo

@TylerLeonhardt should be this week.

@isidorn Nice, we are heavy users of VSCode, thank you for the great tool. We have done some research on the SparseTensor ops, I think it will be fairly straightforward for us to add those missing ops. Initial estimation would be around May timeframe.

I just published a new version of my extension: https://marketplace.visualstudio.com/items?itemName=TylerLeonhardt.auto-language

Just to β€œget it working” I pull in the model.json you have hosted: https://github.com/TylerLeonhardt/vscode-autountitledlanguage/blob/main/src/extension.ts#L97

but interestingly, I did originally try downloading the model.json but it looks like tf.loadGraphModel( does not allow me to pass it a file path or a file:// uri. It says the Uri is not absolute. Any ideas around this? Any other way to provide the model.json to tfjs?

@TylerLeonhardt tensorflow_wizard should work, also there is tensorflow_converter, if you familiar with the params.

@pyu10055 this is amazing, I just tried out the demo! We will look into this on the VS Code side next milestone, for more details on our side you can follow this issue https://github.com/microsoft/vscode/issues/118455

Thanks a lot πŸ‘ πŸ‘

Pls no bot πŸ™