tensorflow / tfjs

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

Request to add support for SparseReorder and SegmentSum ops [tensorflowjs_converter] #7781

Open borinstein opened 1 year ago

borinstein commented 1 year ago

System information

Describe the feature and the current behavior/state.

Unsupported Ops: SegmentSum and SparseReorder

Hi TF.js team,

We have a TF SavedModel which we'd like to convert, using the tensorflowjs_converter, for use with TF.js.

When attempting to run the following code to convert the model...

tensorflowjs_converter \
    --input_format=tf_saved_model \
    --output_format=tfjs_graph_model \
    --signature_name=serving_default \
    --saved_model_tags=serve \
    /path/to/saved_model \
    /path/to/tfjs_model

...we get the following error:

Traceback (most recent call last):
  File "/Users/borinste/.venv/py37/bin/tensorflowjs_converter", line 8, in <module>
    sys.exit(pip_main())
  File "/Users/borinste/.venv/py37/lib/python3.7/site-packages/tensorflowjs/converters/converter.py", line 827, in pip_main
    main([' '.join(sys.argv[1:])])
  File "/Users/borinste/.venv/py37/lib/python3.7/site-packages/tensorflowjs/converters/converter.py", line 831, in main
    convert(argv[0].split(' '))
  File "/Users/borinste/.venv/py37/lib/python3.7/site-packages/tensorflowjs/converters/converter.py", line 818, in convert
    weight_shard_size_bytes, metadata_map)
  File "/Users/borinste/.venv/py37/lib/python3.7/site-packages/tensorflowjs/converters/converter.py", line 539, in _dispatch_converter
    metadata=metadata_map)
  File "/Users/borinste/.venv/py37/lib/python3.7/site-packages/tensorflowjs/converters/tf_saved_model_conversion_v2.py", line 988, in convert_tf_saved_model
    frozen_graph_dir=frozen_graph_dir)
  File "/Users/borinste/.venv/py37/lib/python3.7/site-packages/tensorflowjs/converters/tf_saved_model_conversion_v2.py", line 854, in _convert_tf_saved_model
    experiments=experiments)
  File "/Users/borinste/.venv/py37/lib/python3.7/site-packages/tensorflowjs/converters/tf_saved_model_conversion_v2.py", line 152, in optimize_graph
    ', '.join(unsupported))
ValueError: Unsupported Ops in the model before optimization
SparseReorder, SegmentSum

Please see saved_model.zip for a toy model which can be used to reproduce the error.

Question: per the guidance at https://www.tensorflow.org/js/tutorials/conversion/import_saved_model#supported_operations, would it be possible to add support for these two ops to TensorFlow.js?

Please let me know if you need any more information.

Thanks in advance!

Will this change the current api? How? It will add SparseReorder and SegmentSum

Who will benefit with this feature? Anyone who wishes to convert and use a model contain SparseReorder or SegmentSum ops

Any Other info.

gaikwadrahul8 commented 1 year ago

Hi, @borinstein

Apologize for the delayed response and I checked official documentation which ops we support currently for tensorflowjs_converter and I see there is tf.unsortedSegmentSum op available I'm not sure whether it will fulfil requirement of this op SegmentSum and for other op SparseReorder at the moment we don't support so that op will be considered as feature request so May I know are you looking both the ops as feature request in the tensorflowjs_converter ? Thank you!

borinstein commented 1 year ago

Hi, @gaikwadrahul8.

Thanks for the very rapid response!

Yes, we were hoping that adding both the SegmentSum and SparseReorder ops could be considered as a feature request in the tensorflowjs_converter.

I believe that we encounter SegmentSum in our graph by use of tf.nn.safe_embedding_lookup_sparse with sum specified as the combiner; I'm not sure how we could eliminate the use of the SegmentSum and still use that embedding approach, but I'd definitely be open to suggestions!

gaikwadrahul8 commented 1 year ago

Hi, @borinstein

Alright, thank you for the confirmation and now I'm assigning this feature request to dedicated developer team and they'll take appropriate action from their end on the basis of priority and bandwidth so at the moment we're unable to give estimated time for this feature request. Thank you!

borinstein commented 1 year ago

@gaikwadrahul8 thank you very much for considering this request!