You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
[TensorRT EP] Enhance EP context configs in session options and provider options (#19154)
Several changes:
1. To align with other EPs' setting of EP context configs in session
options, for example [QNN
EP](#18877), EP context
configs for TRT EP can be configured through:
1. Session Options: `ep.context_enable`, `ep.context_file_path` and
`ep.context_embed_mode`
2. Provider Options: `trt_dump_ep_context_model`,
`trt_ep_context_file_path` and `trt_dump_ep_context_embed_mode`
3. Above setting has 1:1 mapping and provider options has higher
priority over session options.
```
Please note that there are rules for using following context model related provider options:
1. In the case of dumping the context model and loading the context model,
for security reason, TRT EP doesn't allow the "ep_cache_context" node attribute of EP context node to be
the absolute path or relative path that is outside of context model directory.
It means engine cache needs to be in the same directory or sub-directory of context model.
2. In the case of dumping the context model, the engine cache path will be changed to the relative path of context model directory.
For example:
If "trt_dump_ep_context_model" is enabled and "trt_engine_cache_enable" is enabled,
if "trt_ep_context_file_path" is "./context_model_dir",
- if "trt_engine_cache_path" is "" -> the engine cache will be saved to "./context_model_dir"
- if "trt_engine_cache_path" is "engine_dir" -> the engine cache will be saved to "./context_model_dir/engine_dir"
```
2. User can decide the naming of the dumped "EP context" model by using
`trt_ep_context_file_path`, please see GetCtxModelPath() for more
details.
3. Added suggested comments from
#18217
* Please note that there are rules for using following context model related provider options:
54
+
*
55
+
* 1. In the case of dumping the context model and loading the context model,
56
+
* for security reason, TRT EP doesn't allow the "ep_cache_context" node attribute of EP context node to be
57
+
* the absolute path or relative path that is outside of context model directory.
58
+
* It means engine cache needs to be in the same directory or sub-directory of context model.
59
+
*
60
+
* 2. In the case of dumping the context model, the engine cache path will be changed to the relative path of context model directory.
61
+
* For example:
62
+
* If "trt_dump_ep_context_model" is enabled and "trt_engine_cache_enable" is enabled,
63
+
* if "trt_ep_context_file_path" is "./context_model_dir",
64
+
* - if "trt_engine_cache_path" is "" -> the engine cache will be saved to "./context_model_dir"
65
+
* - if "trt_engine_cache_path" is "engine_dir" -> the engine cache will be saved to "./context_model_dir/engine_dir"
66
+
*
67
+
*/
68
+
inttrt_dump_ep_context_model{0}; // Dump EP context node model
69
+
constchar*trt_ep_context_file_path{nullptr}; // Specify file name to dump EP context node model. Can be a path or a file name or a file name with path.
70
+
inttrt_ep_context_embed_mode{0}; // Specify EP context embed mode. Default 0 = context is engine cache path, 1 = context is engine binary data
// For security purpose, in the case of running context model, TRT EP won't allow
262
+
// engine cache path to be the relative path like "../file_path" or the absolute path.
263
+
// It only allows the engine cache to be in the same directory or sub directory of the context model.
264
+
if (IsAbsolutePath(cache_path)) {
265
+
returnORT_MAKE_STATUS(ONNXRUNTIME, EP_FAIL, "For security purpose, the ep_cache_context attribute should be set with a relative path, but it is an absolute path: " + cache_path);
266
+
}
267
+
if (IsRelativePathToParentPath(cache_path)) {
268
+
returnORT_MAKE_STATUS(ONNXRUNTIME, EP_FAIL, "The file path in ep_cache_context attribute has '..'. For security purpose, it's not allowed to point outside the directory.");
269
+
}
270
+
271
+
// The engine cache and context model (current model) should be in the same directory
0 commit comments