TypeError: V() got an unexpected keyword argument 'requires_grad'

I am doing SGD on linear regression. I referred to this book, https://github.com/fastai/fastai/blob/master/courses/dl1/lesson6-sgd.ipynb

It gives me below error, while I do exact code in python module/source file. I checked it multiple time to see if I missed an obvious thing.

Traceback (most recent call last):
File “C:/Users/Mahesh.Bhosale/PycharmProjects/Pytorch_learning/pytorch_tutorials/linear_regression.py”, line 22, in
a = V(np.random.randn(1), requires_grad=True)
TypeError: V() got an unexpected keyword argument ‘requires_grad’

Hers my code:

#matplotlib inline
from fastai.learner import *

def lin(a, b, x):
return a * x + b

def gen_fake_data(n, a, b):
x = np.random.uniform(0, 1, n)
y = lin(a, b, x) + 0.1 * np.random.normal(0, 3, n)
return x, y

def mse(pred, y): return ((pred - y) ** 2).mean()

def mse_loss(a, b, x, y): return mse(lin(a, b, x), y)

if __name__ == ‘__main__’:
a = V(np.random.randn(1), requires_grad=True)
b = V(np.random.randn(1), requires_grad=True)
x, y = gen_fake_data(100000, 3., 8.)
x, y = V(x), V(y)
lr = 1e-3
loss = mse_loss(a, b, x, y)
for t in range(10000):
loss = mse_loss(a, b, x, y)
if t % 1000 == 0: print(loss.data[0])

theres no typo, _ name _ is considered as bold. So please bear with it.

you can throw a “\” before underscores to escape them

Thanks, changed it now.

Does anybody has any idea? Help is much appreciated.