Clear iobinding outputs (#6774)

This commit is contained in:
ashbhandare 2021-02-25 11:50:43 -08:00 committed by GitHub
parent 8e200e13fe
commit b05403d877
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -283,6 +283,11 @@ class ORTModule(torch.nn.Module):
# Append gradients of initializer to results
results += [_ort_output_to_torch_tensor(backward_output)
for backward_output in backward_outputs[num_user_input_grads:]]
# The OrtValue has a shared_ptr to the data. At this point there are two shared_ptrs to the data, one through the
# OrtValue in the output iobinding, and the other through the copy in OrtDLManagedTensor.
# The following call clears the iobinding output, reducing the use_count to 1, so that once torch finishes computation
# on the DLpack tensors, the memory can be freed.
self._training_io_binding.clear_binding_outputs()
return tuple(results)
return _ortmodule_output_transformation.populate_user_output_from_schema_and_outputs(self._original_module_output_schema,