def ridge_loss(Y,pred,w,lamb):
    pred_loss=torch.norm((Y-pred),p='fro')**2
    reg=torch.norm(w,p='fro')**2
    return((1/Y.size()[0])*pred_loss + lamb*reg)

def fit(lamb,X_pt,Y_pt,w,epochs = 5000, learning_rate = 0.1):
    w_pt=torch.tensor(w,requires_grad=True) 
    opt=torch.optim.Adam([w_pt], lr=learning_rate, betas=(0.9, 0.99), eps=1e-08, weight_decay=0, amsgrad=False)
    for epoch in range(epochs):
        pred = torch.matmul(X_pt,w_pt)
        loss = ridge_loss(Y_pt,pred,w_pt,lamb) 
        loss.backward()
        opt.step()      
        opt.zero_grad()  
     return w_pt

X_pt=torch.from_numpy(X) # xtrain
Y_pt=torch.from_numpy(Y) #ytrain  
Y_ptt=torch.from_numpy(Y_test) #xtest
X_ptt=torch.from_numpy(X_test) #ytest
w=np.random.rand(X.shape[1],Y.shape[1])
weight=fit(0.001,X_pt,Y_pt,w)

i am new to pytorch . i want to learn how to use custom loss functions in pytorch and in order to get started i wanted implement ridge regression and i find that my error values are very high than the sklearns implementation of ridge regression. can you please help me find out the mistake in writing my loss function .