Skip to content

Commit 3d38e4f

Browse files
gchanansoumith
authored andcommitted
Acquire GIL before THPVariable_wrap (pytorch#1625)
* Acquire GIL before THPVariable_wrap. * mutex not required when GIL is held. * Remove unused mutex.
1 parent fa93653 commit 3d38e4f

File tree

1 file changed

+1
-2
lines changed

1 file changed

+1
-2
lines changed

torch/csrc/autograd/python_engine.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ static PythonEngine engine;
3737
PyObject *THPEngineClass = NULL;
3838

3939
struct CallbackContext {
40-
std::mutex mutex;
4140
std::string error;
4241
THPObjectPtr outputs;
4342
// Used to determine which callback arguments should be used to
@@ -182,7 +181,7 @@ PyObject *THPEngine_run_backward(THPEngine *self, PyObject *args, PyObject *kwar
182181
callbacks.emplace(entry.first.get(), [&ctx, &fn_info](Function* _unused, variable_list& grads) {
183182
auto& saved_outputs = fn_info.first;
184183
bool is_leaf = fn_info.second;
185-
std::lock_guard<std::mutex> guard(ctx.mutex);
184+
AutoGIL gil;
186185
for (auto& saved_out : saved_outputs) {
187186
PyTuple_SET_ITEM(ctx.outputs.get(), saved_out.second,
188187
THPVariable_Wrap(grads[saved_out.first]));

0 commit comments

Comments
 (0)