From 64bbe4603dc38c5e14a3d43be1cd6cfd1aa7c5f9 Mon Sep 17 00:00:00 2001 From: Alban Desmaison Date: Wed, 20 Nov 2019 10:49:21 -0500 Subject: [PATCH] Update autograd blitz --- beginner_source/blitz/autograd_tutorial.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/beginner_source/blitz/autograd_tutorial.py b/beginner_source/blitz/autograd_tutorial.py index b5e89fa918e..98e70a251d6 100644 --- a/beginner_source/blitz/autograd_tutorial.py +++ b/beginner_source/blitz/autograd_tutorial.py @@ -174,7 +174,7 @@ ############################################################### # You can also stop autograd from tracking history on Tensors -# with ``.requires_grad=True`` by wrapping the code block in +# with ``.requires_grad=True`` either by wrapping the code block in # ``with torch.no_grad():`` print(x.requires_grad) print((x ** 2).requires_grad) @@ -182,6 +182,15 @@ with torch.no_grad(): print((x ** 2).requires_grad) +############################################################### +# Or by using ``.detach()`` to get a new Tensor with the same +# content but that does not require gradients: +print(x.requires_grad) +y = x.detach() +print(y.requires_grad) +print(x.eq(y).all()) + + ############################################################### # **Read Later:** #