I have a question about a regression problem. I'v used mse loss for training a neural network for a regression problem. then used mean_squared_error for training set. I thinked this tow ( mse loss  and mean_squared_error) must be equal but they are not. does it make sense?
this is my code and results:

def train_simple_network(model, loss_func, training_loader, epochs=20, device='cpu'):
    optimizer = optim.SGD(model.parameters(), lr=0.001)
    model.to(device)
    training_loss = []
    for epoch in tqdm(range(epochs), desc='Epoch'):
        model.train()
        runinig_loss_item = 0
        for data in tqdm(training_loader, desc='Batch', leave=False):
            inputs, labels = data
            inputs, labels = inputs.to(device), labels.to(device)
            optimizer.zero_grad()
            outputs = model(inputs)
            loss = loss_func(outputs, labels)
            loss.backward()
            optimizer.step()
            runinig_loss_item += loss.item()
        # print(runinig_loss_item)
        training_loss.append(runinig_loss_item/len(training_loader))
    return training_loss

%load_ext autoreload
%autoreload 2
import torch
from torch.utils.data import DataLoader, Dataset
import numpy as np
import seaborn as sns
from utils import train_simple_network
import torch.nn as nn

X = np.linspace(0, 20, 200)
Y = X + 2 * np.sin(X) + np.random.normal(size = X.shape)
# sns.scatterplot(x=X, y=Y)
class SimpleRegressionDataset(Dataset):
    def __init__(self, X , Y):
        self.X = X
        self.Y = Y

    def __len__(self):
        return len(self.X)

    def __getitem__(self, idx):
        X_tensor = torch.tensor(self.X[idx], dtype=torch.float32)
        Y_tensor = torch.tensor(self.Y[idx], dtype=torch.float32)
        return X_tensor, Y_tensor

# simple_dataset = SimpleRegressionDataset(X, Y)
# print(len(simple_dataset), simple_dataset[100])
training_loader = DataLoader(SimpleRegressionDataset(X, Y), shuffle=True)

in_features = 1
out_features = 1   
loss_func = nn.MSELoss()
model = nn.Sequential(
    nn.Linear(1, 10),
    nn.Tanh(),
    nn.Linear(10, 1),
)

from sklearn.preprocessing import StandardScaler

out_in_scaler = StandardScaler()
scaled_X = out_in_scaler.fit_transform(X.reshape(-1, 1))
scaled_Y = out_in_scaler.fit_transform(Y.reshape(-1, 1))


training_loader = DataLoader(SimpleRegressionDataset(scaled_X, scaled_Y), shuffle=True)
mse = train_simple_network(model, loss_func, training_loader, epochs=100)

with torch.no_grad():
    Y_pred_scaled = model(torch.tensor(scaled_X.reshape(-1, 1), dtype=torch.float32)).numpy()

Y_pred = output_scaler.inverse_transform(Y_pred_scaled)


results:
mse =
[1.023870748447464,
 0.2671163232600338,
 0.19597473149441044,
 0.15922270592262522,
 0.13706707262668716,
 0.12302029377720373,
 0.11383748231469781,
 0.1073356195860606,
 0.10218998691161524,
 0.09915152149716847,
 0.09607437133355638,
 0.09444298381336778,
 0.09286972157484812,
 0.09071595246894958,
 0.089047651482133,
 0.0886119357138358,
 0.08871036550494296,
 0.08764986916468388,
 0.08677991817857673,
 0.08620585241987129,
 0.08686745251868558,
 0.08613377635985671,
 0.08616238967568961,
 0.08578674338965073,
 0.08560133192187493,
 0.08533940166824322,
 0.08503600988329708,
 0.08537882461127594,
 0.08523474404313447,
 0.08506491405840336,
 0.08490432237986624,
 0.08487024406589405,
 0.084391233893096,
 0.08503126377407398,
 0.08502885345951654,
 0.08455954154047732,
 0.08397995113395439,
 0.08463223793702354,
 0.08420754137229274,
 0.0846363911125809,
 0.08450806337037306,
 0.0847105791759128,
 0.08451568770943396,
 0.08429688383470975,
 0.08475039027018624,
 0.08448199396588735,
 0.08300730276154297,
 0.08503537875912798,
 0.0841942935620716,
 0.08466248787808013,
 0.08391215757667346,
 0.08425494102745461,
 0.08425762718509759,
 0.08410134604003033,
 0.08334092597263862,
 0.0841680642268011,
 0.0841893108845062,
 0.08405184759316242,
 0.084300991221466,
 0.08391731510652221,
 0.08423920904078841,
 0.08360601527992002,
 0.08413872819206518,
 0.08365430762488614,
 0.0841857871485172,
 0.08317131077015205,
 0.08407488609528173,
 0.08386122564456634,
 0.0837987562426224,
 0.08376333280949894,
 0.08391194159492443,
 0.08425473670806469,
 0.083896313497699,
 0.0839831742983688,
 0.08386543175059558,
 0.08417364596230073,
 0.08414706131392449,
 0.08172950554534736,
 0.0840540523069869,
 0.08396735578376649,
 0.08414163069510777,
 0.08335752278252812,
 0.08356107107905827,
 0.08408522712032208,
 0.08355142281905045,
 0.08296157085231534,
 0.08411017218826437,
 0.08364747512291729,
 0.08390301039026384,
 0.08274352994938454,
 0.08384015152390475,
 0.08353042426461797,
 0.0837409212639821,
 0.08334575597180105,
 0.08407027781686793,
 0.08375791544922322,
 0.08359114686244652,
 0.08321551232405121,
 0.08286556470786031,
 0.08375809011839323]

mean_squared_error(Y, Y_pred.ravel()) = np.float64(2.811515239004087)