Hello,
I’m new to Pytorch, so I’m sorry if it’s a trivial question: suppose we have a loss function  , and we want to get the value of , which means, get the gradient of loss function w.r.t. model parameters at a specified value.
I read a few posts of getting the gradient w.r.t. the parameters using params.grad method after loss.backward(), such as:

  
    
    
    How to get the gradient of output w.r.t. model parameters? autograd
  
  
    I want to get the gradient of output w.r.t. model parameters. For example, y = xW where x is a vector of size 1x5, and W is a vector of size 5x1, and W is model parameter. I don’t have a loss function, just want to get the gradient of y w.r.t W. Obviously, in this case, dy/dW should be x. However, using pytorch backward, the value I got is wrong. What’s the reason? Here is my code. 
import torch
import numpy as np
import torch.nn as nn
import torch.nn.functional as torchF
from torch.autograd imp…
  


It gives gradient of the loss fucntion w.r.t. the current value of the model parameters, but I still couldn’t get  at any specified  I want. Could you suggest me a way to do that?
Thanks!