Skip to content

Commit 9e09de7

Browse files
authored
Add NoGradGuard to libtorch execution (#263)
1 parent 7d99147 commit 9e09de7

File tree

1 file changed

+2
-0
lines changed

1 file changed

+2
-0
lines changed

src/libtorch_c/torch_c.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,10 +218,12 @@ void torchRunModule(ModuleContext* ctx, const char* fnName,
218218
}
219219

220220
if (ctx->module) {
221+
torch::NoGradGuard guard;
221222
torch::jit::script::Method method = ctx->module->get_method(fnName);
222223
method.run(stack);
223224
}
224225
else {
226+
torch::NoGradGuard guard;
225227
torch::jit::Function& fn = ctx->cu->get_function(fnName);
226228
fn.run(stack);
227229
}

0 commit comments

Comments
 (0)