-
Notifications
You must be signed in to change notification settings - Fork 74k
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
C++ API producing incorrect model metaparams #34277
Comments
@liyunlu0618 : Upon further investigation of this problem I noticed that the number of detected nodes, inputs and outputs is independent from the model architecture. Varying the input/output size and/or the number of layers do not affect the output of |
This is expected behavior, the |
@jdduke |
Ah, sorry, I didn't notice the output values from your first post. Can I ask how you're building the C++ API? Are you building it as a shared library then using it in your own app? Does your model work with our minimal C++ example? |
No worries. I am using the devel-py3 docker image to generate the libtensorflowlite.so library. I built it with the extended runtime because not all my used ops were supported by tflite. I had an issue regarding the build here: #33980 I built your minimal.cc example and executed it with my model. Notice that I did not provide inputs/read outputs. Upon inspection, this look reasonable to me:
If I can anymore provide information, do not hesitate to leave a message. I want to get this fixed ASAP. |
I suspect the issue here may just be to poor C++ ABI stability when using different compile flags or options across shared library boundaries, particularly if you're using a very different pipeline for your client app. I'd be curious if you see the same issues when using the C API as supported by this shared library using a slightly lower level API ( here is an example). We're seeing more and more issues that users are having trying to use the C++ API over a shared library boundary, and I think we'll probably focus on prioritizing the stable C ABI/API and perhaps offering a lightweight C++ wrapper on top of that for convenience. We definitely appreciate the feedback and want to get this resolved. I'll reopen this issue for tracking purposes. |
@jdduke 1.) I tried to build the extended runtime via 2.) I had to add another two libraries to get my project to compile. The first was 3.) I copy pasted the test code you provided for me and all I did was to change the paths to my tflite model. It is the same model that generated the output above. The build was successful. However, I get the following, unsatisfying output when running the executable:
The last line is German (my mothertongue), but I do not know the exact translation. Basically, my computer tries to access memory addresses that it is not allowed to access (memory access error maybe?) Also, the extended runtime was not built apparently. Can you deduce from this log where the problem might be coming from? Thanks! |
We actually deprecated that build flag a while back. Let me see about re-introducing it in a more targeted fashion for the C/C++ shared libraries. |
Is there any possibility to build the c library with native operators enabled? Or do I have to roll back to an image that still has the flag? |
If you want to try locally, you can roll back e57a567#diff-866c5e896c5bfd544d4e642ed2e3d2bd, and try again with your build command. |
I was able to build it by rolling back to the parent commit of The main thing is the retrieval of the outputs which bothers me. For example, take line 67 which should return the ByteSize of the output tensor. I expect this to be 90 * sizeof(float) = 360 byte, but I get 0 bytes. HTML-Visualization Also, the executable dies at the same point (with a little more information this time):
gdb provides a little more information:
|
The delegate test failure is more or less expected, though it shouldn't seg fault. In your test, did you explicitly call |
I do not know if this happens under the hood, but my test is the exact file that you provided. So the whole test case is
So it gets called twice. Is this correct, and when exactly is allocation necessary? |
That looks correct. Whenever an input tensor (or tensors) is resized, an explicit allocation is required. I'll try to repro locally. |
Ah, right, so that resize call is kind of nonsensical for this graph. If you remove
from the test, it should proceed. Note that some of the other expectations are bogus for that vae.tflite model, but you should at least get meaningful output shapes. This test passes:
|
Just one other questions, do you really need the random normal generation in your inference graph? We've seen that sometimes these random ops are used (and useful) with training, but they then get carried forward into the inference graph, without adding as much value. |
I am tasked with the training and deployment of a variational autoencoder. The model tries to learn the params of a distribution as its encoded representation. To generate samples for decoding, samples have to be drawn from said distribution. This is emulated by utilizingbthe so-called reparametrization trick, whichbrequires to generate random numbers from a {0,1} normal distribution. As far as I can tell, using random numbers is inevitable. BUT: If you know of another way to do this, I would happily drop the random part. |
I see, good to know. I think we've seen enough use-cases for the RandomStandardNormal op that it's probably time to make it a proper builtin. In the meantime, can I ask what platform you'll be deploying to? |
Your code snippet works for me, so thanks for that. I was also able to find out what causes the SegFault. In the Delegate test, I first added the interpreter holder from your example with the SegFault still occuring. Turns out, when adding
I get the following output now:
I am not sure how this impacts the usage of my model, but I will report back if I encounter any anomalies. Also, I'm planning on deploying this on ARM64 and x86_64 systems, which both run some kind of UNIX-like OS. I am glad to hear that you consider implementing this. I have created a feature request a while back that addresses the issue: #33341 If I can provide any help for this task, do not hesitate to message me. |
@jdduke
Unfortunately, I do not know if this the correct approach nor do I know if ARM is supported. It states android_arm64 is supported, but I doubt this is what I am looking for. EDIT:
Any help is appreciated. Thanks! |
@DocDriven Hi I am Jae from TFLite team and I want to help you. To follow the long threads, I want to list up the issues. please feel free to correct me if i am wrong.
|
Hi @jaeyoo , your list is correct. Concerning issue 2, this would eliminate my need for a working library with the Also, I tested the flag you suggested. I am on commit e57a567~1 and had to downgrade my bazel installation to 0.26.1. Without the
It seems to be a valid option, but it is missing the toolchain. |
We haven't done much validation of cross-compilation with bazel for generic aarch64 internally, but I can file an internal ticket for tracking. There's a similar thread on #34520 for validating generic arm64 builds, which might be useful. |
I am not building for Android, just a custom board with an ARM64 processor. I was trying to follow one tutorial referenced in the thread you mentioned (https://github.com/xifengcun/tensorflow-aarch64-crossbuild). I decided to not use the chroot/debootstrap approach and applied the steps to the build container within docker. It seems that the tutorial was intended for an older release of bazel, as some attributes within
and got the output
So I simply removed the presumably deprecated(?) attributes What I ended up with are the following errors:
I am afraid that I do not have a clue how to deal with the I think it should be able to work inside a Docker container, also it would be easier to ship than using a chroot environment. |
This remains useful for testing and development. Restore the ability to inject support for TF ops in TFLite using `--define=with_select_tf_ops=true`. See also issue #34277. PiperOrigin-RevId: 313873470 Change-Id: I6b68cd863efc17f5ae0667c0d2c9d68958d6e4ad
This remains useful for testing and development. Restore the ability to inject support for TF ops in TFLite using `--define=with_select_tf_ops=true`. See also issue #34277. PiperOrigin-RevId: 313887137 Change-Id: Ia7c737b76705d5718895311c9694ffd91164040b
@DocDriven Could you please check in latest TF version and let us know the update. Thanks! |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you. |
Closing as stale. Please reopen if you'd like to work on this further. |
System information
Describe the current behavior
An autoencoder model consisting only of standard keras Dense layers is converted into a tflite model. This model can be loaded and inspected with the Python API. The output there is consistent with the output from the visualize.py script.
When loading the very same model with the C++ API, I get ridicolous large results for the number of inputs/outputs/nodes.
The C++ functions that were used to inspect the model are:
This produces the following output:
The code to create the tflite model to inspect can be found on my repo (https://github.com/DocDriven/tflite-cpp-api-tests). All relevant files are named
simple_ae.*
.I suspect the C++ API to be broken at some point, as the models seem to be fine. Same results for TF 1.x and TF2.0. Trying different models yields the exact same ridicolous values, independently from their size.
The text was updated successfully, but these errors were encountered: