Getting Error when defining an instance of the LinearRegressionModel class #502
-
I have created the following LinearRegeressionModel class as defined in the course: class LinearRegressionModel(nn.Module): # <-- almost everything in Pytorch inherets from nn.Module
def __init__(self):
super().__init__()
self.weights = nn.Parameter(torch.randn((1,),
dtype=torch.float,
requires_grad=True
))
self.bias = nn.Parameter(torch.randn((1,),
dtpye=torch.float,
requires_grad=True
))
# Forward method to define the computation in the model
def forward(self, x: torch.Tensor) -> torch.Tensor: # x is input data
return self.weights * x + self.bias Whenever I try and define an instance of this class, for example: model = LinearRegressionModel() I get a weird error message that I don't understand: TypeError: randn() received an invalid combination of arguments - got (tuple, requires_grad=bool, dtpye=torch.dtype), but expected one of:
* (tuple of ints size, *, torch.Generator generator, tuple of names names, torch.dtype dtype, torch.layout layout, torch.device device, bool pin_memory, bool requires_grad)
* (tuple of ints size, *, torch.Generator generator, Tensor out, torch.dtype dtype, torch.layout layout, torch.device device, bool pin_memory, bool requires_grad)
* (tuple of ints size, *, Tensor out, torch.dtype dtype, torch.layout layout, torch.device device, bool pin_memory, bool requires_grad)
* (tuple of ints size, *, tuple of names names, torch.dtype dtype, torch.layout layout, torch.device device, bool pin_memory, bool requires_grad) Can someone help me out? |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments
-
Okay, I reloaded the notebok because I geniuinely could not find anything wrong with the class, and it worked. I guess Colab was being weird or something. |
Beta Was this translation helpful? Give feedback.
-
There is a typo error in the argument of self.bias fix it from (dtpye = torch.float to dtype = torch.float) |
Beta Was this translation helpful? Give feedback.
-
Glad to hear you got it fixed @NonExistentialism (even if it seems like magic!) And @Surya-Abhinai is correct, the only thing I could see was the typo in the |
Beta Was this translation helpful? Give feedback.
There is a typo error in the argument of self.bias fix it from (dtpye = torch.float to dtype = torch.float)