pytorch/benchmarks/static_runtime
Don Jang 9cb65df79f [Static Runtime] Fallback to disabling manage_output_tensors instead of crashing when wrong API is used (#67939)
Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/67939

With `manage_output_tensor` enabled, a client of `StaticRuntime` requires to call it via  `PyTorchPredictor::predict_managed_result`. If the client uses `PyTorchPredictor::operator()`  the client will experience a crash (intended behavior not to  leak memory of managed output tensors). This mistake can cause a catastrophic failure in production if that happens (by gatekeeper, config changes, etc).

Considering the complexity in how `PyTorchPredictor` is used in different settings, the chances that this bug can hit production is non-zero.

This change introduces `StaticRuntime::disableManageOutputTensor` to disable `manage_output_tensor` feature when a client mistakenly uses `PyTorchPredictor::operator()` instead of crashing. When `StaticRuntime` is invoked via `PyTorchPredictor::operator()`, it first calls  `StaticRuntime::disableManageOutputTensor` to disable the feature, so that it can get non-managed output tensors to pass to the client safely.

A slight perf degradation is expected by forcefully disabling `manage_output_tensors`, but its robustness value outweighs a catastrophic failure of crashes at a high rate.

Test Plan: Added a unittest `StaticRuntime, DisableManageOutputTensors` to cover the newly added code.

Reviewed By: swolchok

Differential Revision: D32219731

fbshipit-source-id: caf5c910b34726c570e17435ede7d888443e90cf
2021-11-11 17:31:07 -08:00
..
CMakeLists.txt [Static Runtime] Test isOptimizableContainerType and getAlwaysAliveValues (#65849) 2021-10-04 20:46:07 -07:00
deep_wide_pt_bench.cc [NOOP][clangformat][codemod] Enable CLANGFORMAT for some folders in caffe2/* (#67746) 2021-11-03 12:23:14 -07:00
deep_wide_pt.cc [NOOP][clangformat][codemod] Enable CLANGFORMAT for some folders in caffe2/* (#67746) 2021-11-03 12:23:14 -07:00
deep_wide_pt.h [NOOP][clangformat][codemod] Enable CLANGFORMAT for some folders in caffe2/* (#67746) 2021-11-03 12:23:14 -07:00
test_static_module.cc [Static Runtime] Fallback to disabling manage_output_tensors instead of crashing when wrong API is used (#67939) 2021-11-11 17:31:07 -08:00
test_static_runtime.cc [SR] Native implementation for aten::split (#67476) 2021-11-10 10:23:03 -08:00
test_utils.cc [SR] Enforce checks for resizing of the internal buffer in MemoryPlanner in unit tests (#67941) 2021-11-09 16:07:40 -08:00
test_utils.h [SR] Enforce checks for resizing of the internal buffer in MemoryPlanner in unit tests (#67941) 2021-11-09 16:07:40 -08:00