onnxruntime/include/onnxruntime/core/framework
pengwa 87b14ac7e4
Release backward inputs per static graph ref count (#20804)
### Release backward inputs per static graph ref count

For the output buffer marked as external output:
1. Remove the additional ref count we used for avoiding reusing buffer.
Instead, when we find reuse input/output buffer, we will make sure the
reused buffer not not generated by nodes that has external outputs.
2. Remove the ref count of pybind feed inputs, which exists all the time
until the run_backward completed. Instead, passing a mutuble feeds, and
we clean the feeds vector once that is copied into session states and
not needed any more before run the graph sequencentially.

#### Before the change:

One of the backward inputs is 3.9GB, it lives until the backward ends. 

![image](https://github.com/microsoft/onnxruntime/assets/10530022/e71e2072-eaaa-4be3-a39f-0ca74b507265)

#### With the change:
The 3.9GB is released when the last node depending on that tensor
completed.


![image](https://github.com/microsoft/onnxruntime/assets/10530022/7b27d01f-c675-4faf-9a3e-f886b31b2afe)


Be noted: the peak did not change though, we have more work to do to
reduce on the peak.


#### Others

It is found there are few tests that were updated to use incorrect
expected values in previous code refactoring
a81faee41e (diff-9e8fbae7d3dff24106cd17564949f320e943cb3048eae07813c7de144f140419L382).

This PR tries to fix them back, and I think now all test cases are back
to normal.

### Motivation and Context
<!-- - Why is this change required? What problem does it solve?
- If it fixes an open issue, please link to the issue here. -->
2024-06-14 14:33:01 +08:00
..
alloc_kind.h
allocator.h Expose Reserve() in OrtAllocator to allow custom allocators to work when session.use_device_allocator_for_initializers is specified. (#19904) 2024-03-28 12:28:37 -07:00
buffer_deleter.h Multi-stream execution support (#13495) 2022-12-15 07:39:29 -08:00
customregistry.h
data_types.h [CPU EP] Int4 support for QuantizeLinear, DequantizeLinear, and Transpose (#20362) 2024-05-30 18:56:24 -07:00
data_types_internal.h [CPU EP] Int4 support for QuantizeLinear, DequantizeLinear, and Transpose (#20362) 2024-05-30 18:56:24 -07:00
endian.h
execution_provider.h Enable CUDA EP unit testing on Windows (#20039) 2024-03-27 13:32:36 -07:00
float8.h implement isinf20 and isnan20 (#17874) 2023-10-24 10:58:54 -07:00
float16.h [C#, CPP] Introduce Float16/BFloat16 support and tests for C#, C++ (#16506) 2023-07-14 10:46:52 -07:00
framework_common.h
framework_provider_common.h Add TRT plugins support using custom ops (#13847) 2023-04-18 20:24:32 -07:00
func_api.h Run clang-format in CI (#15524) 2023-04-18 09:26:58 -07:00
int4.h Fix compiler error when onnxruntime_DEBUG_NODE_INPUTS_OUTPUTS is enabled (#20889) 2024-05-31 18:07:53 -07:00
kernel_def_builder.h Release backward inputs per static graph ref count (#20804) 2024-06-14 14:33:01 +08:00
kernel_registry.h Remove onnxruntime_PYBIND_EXPORT_OPSCHEMA definition from onnxruntime (#15776) 2023-05-03 13:08:35 -07:00
op_kernel.h [wasm] upgrade emsdk to 3.1.44 (#17069) 2023-08-10 16:08:36 -07:00
op_kernel_context.h ExecutionProvider API refactor - replace OrtMemoryInfo with OrtDevice (#15618) 2023-05-01 10:06:00 -07:00
op_kernel_info.h Make session configuration options available to kernels via OpKernelInfo (#18897) 2024-01-13 10:02:43 +10:00
op_node_proto_helper.h MLAS AArch64 quantized int4 Gemm kernel (#18031) 2023-11-15 09:31:54 -08:00
ort_value.h Two fixes involving minimal builds (#17000) 2023-08-23 16:01:22 +10:00
ortdevice.h ExecutionProvider API refactor - replace OrtMemoryInfo with OrtDevice (#15618) 2023-05-01 10:06:00 -07:00
ortmemoryinfo.h Run clang-format in CI (#15524) 2023-04-18 09:26:58 -07:00
provider_options.h
provider_options_utils.h
provider_shutdown.h
run_options.h Enable CUDA EP unit testing on Windows (#20039) 2024-03-27 13:32:36 -07:00
sparse_tensor.h Run clang-format in CI (#15524) 2023-04-18 09:26:58 -07:00
stream_handles.h Add new API KernelContext_GetScratchBuffer (#19809) 2024-03-13 19:41:15 -07:00
tensor.h [CPU EP] Int4 support for QuantizeLinear, DequantizeLinear, and Transpose (#20362) 2024-05-30 18:56:24 -07:00
tensor_shape.h Make TensorShapeVector to use InlinedVector<Int64_t> to reduce on template instantiations (#18519) 2023-11-21 14:13:50 -08:00
to_tensor_proto_element_type.h [CPU EP] Int4 support for QuantizeLinear, DequantizeLinear, and Transpose (#20362) 2024-05-30 18:56:24 -07:00