Skip to content

Adding some Boosted tree ops to the 'allowed' list #50801

Closed

Description

@Koushik667

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

System information

  • TensorFlow version (you are using):2.4
  • Are you willing to contribute it (Yes/No):Yes/will need some help

Describe the feature and the current behavior/state.

Currently, we cant convert tensorflow boosted tree model to tensorflow lite using tf.lite.TFLiteConverter.from_saved_model even after having
converter.target_spec.supported_ops = [
tf.lite.OpsSet.TFLITE_BUILTINS, # enable TensorFlow Lite ops.
tf.lite.OpsSet.SELECT_TF_OPS
# enable TensorFlow ops.
]
I am getting this error,

`ConverterError: :0: error: loc("boosted_trees"): 'tf.BoostedTreesEnsembleResourceHandleOp' op is neither a custom op nor a flex op
:0: error: loc("boosted_trees/BoostedTreesPredict"): 'tf.BoostedTreesPredict' op is neither a custom op nor a flex op
:0: error: loc("boosted_trees/head/predictions/str_classes"): 'tf.AsString' op is neither a custom op nor a flex op
:0: error: failed while converting: 'main': Ops that need custom implementation (enabled via setting the -emit-custom-ops flag):
tf.AsString {device = "", fill = "", precision = -1 : i64, scientific = false, shortest = false, width = -1 : i64}
tf.BoostedTreesEnsembleResourceHandleOp {container = "", device = "", shared_name = "boosted_trees/"}
tf.BoostedTreesPredict {device = "", logits_dimension = 7 : i64, num_bucketized_features = 18 : i64}

`
Will this change the current api? How?
Not sure

Who will benefit with this feature?

Anyone who want to use boosted tree tensorflow lite model will be benifted.

Any Other info.
Thanks to @MeghnaNatraj and @abattery for responding to case #50667 .After referring this [https://www.tensorflow.org/lite/guide/op_select_allowlist#add_tensorflow_core_operators_to_the_allowed_list], i have raised this feature request to add the unsupported ops.

Activity

  1. added
    comp:lite
    TF 2.4
    comp:ops
    on Jul 16, 2021
  2. added
    stat:awaiting tensorflower
    and removed
    comp:ops
    on Jul 16, 2021
  3. Koushik667 commented on Jul 19, 2021

    @Koushik667
    Author

    In order to do code changes i have tried to build tensorflow from source in my mac , But it gave me an error in the last step where we install the wheel file of tensorflow through pip, i have raised the following case for this #50829 .Please let me know how i can proceed.

  4. Koushik667 commented on Jul 28, 2021

    @Koushik667
    Author

    Hello, i was able to build from source in a linux machine(Ubuntu 18.04.5). However i am getting this errror after i add the necessary ops required in the code.

    `Hello from TensorFlow C library version 2.6.0-rc1
    The elapsed time is 0.000060 seconds
    INFO: Created TensorFlow Lite delegate for select TF ops.
    2021-07-28 11:52:42.296825: I tensorflow/core/platform/cpu_feature_guard.cc:142] This TensorFlow binary is optimized with oneAPI Deep Neural Network Library (oneDNN) to use the following CPU instructions in performance-critical operations: SSE3 SSE4.1 SSE4.2 AVX AVX2 AVX512F FMA
    To enable them in other operations, rebuild TensorFlow with the appropriate compiler flags.
    INFO: TfLiteFlexDelegate delegate: 37 nodes delegated out of 117 nodes with 4 partitions.

    2021-07-28 11:52:42.331907: W tensorflow/core/framework/op_kernel.cc:1692] OP_REQUIRES failed at quantile_ops.cc:461 : Not found: Container localhost does not exist. (Could not find resource: localhost/boosted_trees/QuantileAccumulator/)
    ERROR: Container localhost does not exist. (Could not find resource: localhost/boosted_trees/QuantileAccumulator/)
    (while executing 'BoostedTreesQuantileStreamResourceGetBucketBoundaries' via Eager)
    ERROR: Node number 117 (TfLiteFlexDelegate) failed to invoke.`

    Attaching the diff file here : tf_diff.txt

    PS: I am using Tensorflow c api and the code is attached here: boosted_tree_tflite.c

    Thank you,
    Koushik

  5. MeghnaNatraj commented on Jul 28, 2021

    @MeghnaNatraj
    Contributor

    Here are a couple of suggested solutions:

    1. #28287#comment
    2. (related to 1.)StackOverflow: Solution A and StackOverflow: Solution B
    3. discusses possible cause

    Let me know if this works.

  6. Koushik667 commented on Jul 29, 2021

    @Koushik667
    Author

    Hi Meghna, Thanks for the response.
    I don't understand how i can use the 1 and 2 points you have mentioned as i am using a C API whereas they are using Python API for inference.
    About the 3rd link, i did not understand the following comment by @mrry :

    Thanks for tracking that down! I think this is a legitimate bug, introduced in 9f4118d. That change modifies most iterators to use the same Device, FunctionLibraryRuntime, and ResourceMgr as the op that created them, which enables the resource-capturing logic to be simplified, because handles are valid in both the caller and the callee.

    Does it mean i have to essentially train the model in the same device and then load the model in the same device for it to work?

  7. 2 remaining items

  8. abattery commented on Aug 3, 2021

    @abattery
    Contributor

    @Koushik667 could you share the reproducible steps for creating the above TensorFlow model to debug?

  9. Koushik667 commented on Aug 4, 2021

    @Koushik667
    Author

    Sure,

    I have created a sample program for the titanic dataset which takes only 2 input numerical features for simplicity.
    Attaching codes as .txt files as githhub is not allowing .c or .py attachments.

    Dataset csv files:
    train.csv
    eval.csv

    Here is the python program to create the tensorflow model which uses above csv files
    BoostedTree.txt

    Here is the converter code which converts TensorFlow model generated to TensorFlow lite :converter_code.txt

    Here is the diff file which applied after building from source : tf_diff.txt

    Here is the C code which loads and runs the tensorflow lite model :
    test.txt

    I run this code using this command:
    gcc -I../tensorflow/ test.c -Wl,-rpath=/home/luser/tensorflow/bazel-bin/tensorflow/lite/c/ -L/home/luser/tensorflow/bazel-bin/tensorflow/lite/c/ -ltensorflowlite_c -o test.o

    Also attaching tensorflow and tensorflow lite models in zip file :
    Archive.zip

  10. abattery commented on Aug 4, 2021

    @abattery
    Contributor

    Could you format the above script in a format of the CoLab if possible?

  11. Koushik667 commented on Aug 7, 2021

    @Koushik667
    Author

    @abattery Please let me know if you need anything from my side.

  12. Koushik667 commented on Aug 16, 2021

    @Koushik667
    Author

    Hi @abattery @MeghnaNatraj , Can you please let me know if this issue is solvable or not? or if it is a work in progress?

  13. Koushik667 commented on Aug 23, 2021

    @Koushik667
    Author

    @renjie-liu Any comments on this issue?

  14. renjie-liu commented on Aug 23, 2021

    @renjie-liu
    Contributor

    Adding Karim who may have a better idea

  15. Koushik667 commented on Sep 2, 2021

    @Koushik667
    Author

    @karimnosseir Any updates on this issue?

  16. Koushik667 commented on Oct 22, 2021

    @Koushik667
    Author

    Hi @MeghnaNatraj, Can you please comment on what can be done for this issue?

  17. terryheo commented on Apr 13, 2022

    @terryheo
    Member

    These ops were removed from TF so TFLite doesn't support it either.

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

Metadata

Metadata

Labels

TF 2.4comp:litestat:awaiting tensorflowertype:feature

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions