pytorch_tabular icon indicating copy to clipboard operation
pytorch_tabular copied to clipboard

Help: custom loss for model_sweep

Open MarselScheer opened this issue 9 months ago • 2 comments

Following https://pytorch-tabular.readthedocs.io/en/latest/tutorials/13-Using%20Model%20Sweep%20as%20an%20initial%20Model%20Selection%20Tool/ I was able to adapt the model sweep to my problem. But i would like to use a custom loss during model sweep. For tm = TabularModel(...) it was straight forward to leverage a custom loss via the fit()-interface: tm.fit(..., loss=my_custom_loss()). However, have the feeling that currently this is not possible for model_sweep().

Using pytorch_tabluar==1.1.1

MarselScheer avatar Feb 19 '25 20:02 MarselScheer

Hey @MarselScheer! I'm here to help you with your PyTorch Tabular issue. Let's work on getting your custom loss integrated into the model sweep.

Currently, the model_sweep() function in PyTorch Tabular version 1.1.1 does not explicitly support specifying a custom loss function directly. The function has certain limitations and constraints regarding customization, such as using predefined presets and common model arguments, but it does not provide a direct parameter for custom loss functions [1].

However, PyTorch Tabular does support hooks or callback mechanisms that can be used to inject custom behavior during the model sweep process. You can define a custom loss function by subclassing nn.Module and overriding the forward method, and then potentially use custom callbacks to integrate this into the training process [2][3].

For now, you might need to explore the source code or consider modifying it to include custom loss functions in the model sweep process.

To continue talking to Dosu, mention @dosu.


Help Dosu learn! Give it feedback: Great Response | Irrelevant Answer | Incorrect Sources | Too Verbose | Hallucination | Bug Report | Other

dosubot[bot] avatar Feb 19 '25 20:02 dosubot[bot]

@MarselScheer Model Sweep is a newer functionality and we haven't added support for custom losses yet. But it's a simple enough change. I'm going to mark this as a good first issue badge so that someone can contribute a PR for this

manujosephv avatar Mar 26 '25 02:03 manujosephv