Attribut Error: 'LinearRegressionModel' object has no attribute 'weights'

Hi, I’m new to PyTorch. Please Help. I did a basic linear regression. Here’s my code.
weight = 0.7
bias = 0.3
start = 0
end = 1
step = 0.02
X = torch.arange(start, end, step).unsqueeze(dim=1)
y = weight * X + bias

train_split = int(0.8 * len(X))
X_train, y_train = X[:train_split], y[:train_split]
X_test, y_test = X[train_split:], y[train_split:]

class LinearRegressionModel(nn.Module):
def init(self):
super().init()
self.weights = nn.Parameter(torch.randn(1,
requires_grad = True,
dtype = torch.float))
self.bias = nn.Parameter(torch.randn(1,
requires_grad = True,
dtype = torch.float))

def forward(self, x: torch.Tensor) -> torch.Tensor:          
    return self.weights * x + self.bias

torch.manual_seed(42)
model_0 = LinearRegressionModel()
model_0.state_dict()

with torch.inference_mode():
y_predicts = model_0(X_test)
y_predicts

Full error:
AttributeError Traceback (most recent call last)
in
1 ##predict y_test with X_test
2 with torch.inference_mode():
----> 3 y_predicts = model_0(X_test)
4 y_predicts

2 frames
/usr/local/lib/python3.7/dist-packages/torch/nn/modules/module.py in getattr(self, name)
1206 return modules[name]
1207 raise AttributeError(“‘{}’ object has no attribute ‘{}’”.format(
→ 1208 type(self).name, name))
1209
1210 def setattr(self, name: str, value: Union[Tensor, ‘Module’]) → None:

AttributeError: ‘LinearRegressionModel’ object has no attribute ‘weights’

here’s the work on colab.research.google

I don’t have access to your notebook so cannot reproduce and debug the issue. Your code is also not formated properly so I’m also unsure if a syntax error might be causing the issue. Could you check if you are able to access the .weight attribute directly? If that’s not working could you check if the parameter initialization is skipped for some reason?

Thank you for your swift reply. Here are the screenshots of my code. I even suspect its a case of system python error as I’m getting much errors lately. I would be extremely grateful if you could help me with his.

Thank you

Also i forgot to mention that I’m getting the same error when i tried to access .weight attribute