1. Moai's blog >
  2. python >
  3. Torch
python pytorch

Torch

About calcuration of gradient

How not to calculate gradient

Use no_grad

For example;

with torch.no_grad():
    y = x*2

We can use as decorator

@torch.no_grad()
def doubler(x):
    return x*2

Use .detach() -> ?

Use .reaquires_grad -> ?

reference

  • Pytorchの「.detach()」と「with no_grad():」と「.requires_grad = False」の違い
  • PyTorchの新しい推論モードについて