Fastai Regression model with observation weight

Is it possible to have a costume mean squared error function with sample weight for each observation?

I am able to utilize the standard fastai training loop and I am able to implement this costume loss in PyTorch.

How to put that to fastai learner object on tabular data?

I know keras has this already implemented in the .fit method where sample_weight argument present.

def weighted_mse_loss(input, target, weight):
    return torch.sum(weight * (input - target) ** 2)

from fastai.tabular.all import *
import seaborn as sns

df = sns.load_dataset('tips')
df = df.assign(sample_weight = np.random.normal(size = df.shape[0], loc = 10, scale = 2))

y = ['total_bill']
cont = ['tip']
cat = ['sex', 'smoker', 'day', 'time', 'size']

procs = [Normalize, Categorify]

df["Y"] = np.log(df[y] + 1)

MIN = df["Y"].min()
MAX = df["Y"].max()

splits =  RandomSplitter(valid_pct=0.2)(range_of(df))

to = TabularPandas(
    df,
    procs=procs,
    cat_names=cat,
    cont_names=cont,
    y_names="Y",
    splits=splits,
    y_block=RegressionBlock(n_out = 1),
)

dls = to.dataloaders(
    bs=64, shuffle_train=True
)

config = tabular_config(
        embed_p=0.05, 
        y_range=[0, MAX * 1.1],
        bn_final=False,
        ps=[0.05, 0.05, 0.05],
    )

learner = tabular_learner(
        dls,
        layers=[1000, 500, 250],
        config=config,
        wd=0.2,
        metrics=[rmse,],
    )

learner.fit_one_cycle(40, lr_max = 0.01,
                          wd = 0.1)