-
Notifications
You must be signed in to change notification settings - Fork 3.1k
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
[TRT EP] Fix logic to reach cache encryption code. #17111
Conversation
…s no code execution path possible so that an encrypted TRT engine cache could be created when flags engine_cache_enable and engine_decryption_enable are true. Checking for the encrypted engine presence beforehand through the decrypt function should fix this.
/azp run Linux CPU CI Pipeline, Linux CPU Minimal Build E2E CI Pipeline, Linux GPU CI Pipeline, Linux GPU TensorRT CI Pipeline, Linux Nuphar CI Pipeline, Linux OpenVINO CI Pipeline, MacOS CI Pipeline, ONNX Runtime Web CI Pipeline, Windows CPU CI Pipeline, Windows GPU CI Pipeline |
/azp run Windows GPU TensorRT CI Pipeline, onnxruntime-binary-size-checks-ci-pipeline, onnxruntime-python-checks-ci-pipeline, orttraining-linux-ci-pipeline, orttraining-linux-gpu-ci-pipeline, orttraining-ortmodule-distributed |
/azp run Linux QNN CI Pipeline, Windows ARM64 QNN CI Pipeline |
Azure Pipelines successfully started running 2 pipeline(s). |
Azure Pipelines successfully started running 5 pipeline(s). |
Azure Pipelines successfully started running 9 pipeline(s). |
/azp run Linux CPU CI Pipeline, Linux CPU Minimal Build E2E CI Pipeline, Linux GPU CI Pipeline, Linux GPU TensorRT CI Pipeline, Linux Nuphar CI Pipeline, Linux OpenVINO CI Pipeline, MacOS CI Pipeline, ONNX Runtime Web CI Pipeline, Windows CPU CI Pipeline, Windows GPU CI Pipeline |
/azp run Windows GPU TensorRT CI Pipeline, onnxruntime-binary-size-checks-ci-pipeline, onnxruntime-python-checks-ci-pipeline, orttraining-linux-ci-pipeline, orttraining-linux-gpu-ci-pipeline, orttraining-ortmodule-distributed |
/azp run Linux QNN CI Pipeline, Windows ARM64 QNN CI Pipeline |
Azure Pipelines successfully started running 2 pipeline(s). |
Azure Pipelines successfully started running 5 pipeline(s). |
Azure Pipelines successfully started running 9 pipeline(s). |
@chilo-ms I tried to find out why some checks failed but can't figure it out. Please let me know if there's something for me to do. I'd really like this to make it into ORT 1.16 if possible. |
Sometimes the CIs might have intermittent failures. I restart the CI again to see. |
@simonjub thanks a lot for your contribution. it would also be nice to add some unit tests that can exercise these paths, so that we can ensure we don't break this new functionality. |
@jywu-msft I remember from our discussion in PR #15519 that your internal user for engine encryption already uses a different filename for the encrypted engine cache file and that only their encryption library knows it. If we implement the change that you propose (encrypted engine file explicitely named by the EP), that may break functionality for them, or at the very least force them to rename their existing encrypted engine files to take the new name into account. You do bring up a good point that it's not desirable to have both the encrypt and decrypt functions deployed. It can't really be avoided with models using dynamic shape inputs, though. It feels like the preferred use case for encryption IS the one when input shapes are static and the engine can be created offline. I am not familiar with onnxruntime's test suite, but I can look into adding unit tests and a basic encryption library. |
I think we should go ahead and implement explicit different filename for encrypted engine.
|
Okay. I started to work on it. In the case where an expected encrypted cache is missing and the deployed library does not have the encrypt function implemented, I'll just completely skip any cache creation. This means every time the session is created, the engine will be rebuilt without saving it to disk until the encrypted engine file is put in by the user. Does that sound good? |
I think it's okay for me. Just add a warning message to let user know why we skip cache creation. |
The decryption library can be distributed without the encrypt function for security reasons. Check if it is present before calling it.
I implemented the separate filename for encrypted engine to have ".encrypted" appended at the end. |
great. thanks! we'll take a look at the new code. |
Azure Pipelines successfully started running 9 pipeline(s). |
Azure Pipelines successfully started running 5 pipeline(s). |
@simonjub thanks! We discussed internally and came up with following table which lists different cases that need to be handled differently. Following table lists the different cases under the situation where engine cache enable option and engine decryption enable option are both on: |
Great analysis of all possible cases. I wonder if the decryption_function (false) possibility is likely to happen? Why would someone not always provide this? I can see why for encryption_function. |
It's highly unlikely to happen. |
If we agree that it does not make sense to provide a library to the EP without the decrypt function, I can add a check for this at that location you just pointed out and throw an exception if engine_decryption_ is a nullptr. That would change the second and fourth row in your table as an exception would be thrown early whether there is an encrypted cache on disk or not. |
When the TRT EP has engine encryption flag enabled, it must be provided a path to a library that exports the decrypt function. The EP will now throw an exception if decrypt is not found.
@jywu-msft I hope I didn't misinterpret your thumbs-up on my last message. I went ahead and added the exception if decrypt function is not implemented in the provided library. I verified that the exception is correctly thrown if the wrong library is provided. |
agree that it does not make sense to provide a library to the EP without the decrypt function and thanks for the change. |
/azp run Linux CPU CI Pipeline, Linux CPU Minimal Build E2E CI Pipeline, Linux GPU CI Pipeline, Linux GPU TensorRT CI Pipeline, Linux Nuphar CI Pipeline, Linux OpenVINO CI Pipeline, MacOS CI Pipeline, ONNX Runtime Web CI Pipeline, Windows CPU CI Pipeline, Windows GPU CI Pipeline |
/azp run Windows GPU TensorRT CI Pipeline, onnxruntime-binary-size-checks-ci-pipeline, onnxruntime-python-checks-ci-pipeline, orttraining-linux-ci-pipeline, orttraining-linux-gpu-ci-pipeline, orttraining-ortmodule-distributed |
Azure Pipelines successfully started running 9 pipeline(s). |
/azp run Linux QNN CI Pipeline, Windows ARM64 QNN CI Pipeline |
Azure Pipelines successfully started running 5 pipeline(s). |
Azure Pipelines successfully started running 2 pipeline(s). |
@simonjub |
just to set expectations, this probably won't make it into the ort 1.16 release. |
/azp run Linux CPU CI Pipeline,Linux CPU Minimal Build E2E CI Pipeline,Linux GPU CI Pipeline,Linux GPU TensorRT CI Pipeline,Linux OpenVINO CI Pipeline,Linux QNN CI Pipeline,MacOS CI Pipeline,ONNX Runtime Web CI Pipeline |
/azp run Windows ARM64 QNN CI Pipeline,Windows CPU CI Pipeline,Windows GPU CI Pipeline,Windows GPU TensorRT CI Pipeline,onnxruntime-binary-size-checks-ci-pipeline,orttraining-linux-ci-pipeline,orttraining-linux-gpu-ci-pipeline,orttraining-ortmodule-distributed |
Azure Pipelines successfully started running 8 pipeline(s). |
1 similar comment
Azure Pipelines successfully started running 8 pipeline(s). |
@chilo-ms @jywu-msft Successfully merged my branch with main just now. Thanks to you as well for taking the time to look into this and accepting the changes. I agree it was worth taking our time to make sure it was done right and the final solution is better than the initial proposal in the previous PR. It's fine if it doesn't make it into 1.16. Thanks again! |
### Description This is a followup to PR microsoft#15519 that is closed in favor of this one. ### Motivation and Context The current implementation of TRT cache has no code execution path possible so that an encrypted TRT engine cache could be created when flags engine_cache_enable and engine_decryption_enable are true. This was originally raised in issue microsoft#12551.
As I understand this thread there is now support for engine encryption but as far as I can tell there is no documentation for how to write an encryption dll. What its function's names should be, what parameters they have and its semantics. |
Also curious, if this support for a custom decryption library exists only for TRT EP or for vanilla ORT EP as well? |
Description
This is a followup to PR #15519 that is closed in favor of this one.
Motivation and Context
The current implementation of TRT cache has no code execution path possible so that an encrypted TRT engine cache could be created when flags engine_cache_enable and engine_decryption_enable are true. This was originally raised in issue #12551.