Customized forward function in the base strategy #901
Replies: 6 comments 1 reply
-
This is already possible, either by subclassing:
or, in a somewhat hackish, but perfactly working way, by overriding the forward method:
|
Beta Was this translation helpful? Give feedback.
-
@AntonioCarta True, thanks. The hack looks good though but it's still a hack. I'm going with this one for now. This is not something urgent for now but could be considered for the "general" BaseStrategy" in the future since a strategy can have different forward behaviors depending on the model. |
Beta Was this translation helpful? Give feedback.
-
We can close this issue for now. |
Beta Was this translation helpful? Give feedback.
-
Should I move it to the Discussions tab instead? |
Beta Was this translation helpful? Give feedback.
-
IMO the solution for this problem already exists. Strategies are implemented as plugins, so you can add them to your custom loop without subclassing N times. The problem that I see with your proposals is that we are adding a bit of indirection without much benefits. And it's not just one function. If you do it for |
Beta Was this translation helpful? Give feedback.
-
Yea, this should work perfectly for the strategies implemented as a plugin, but not all strategies are/can be implemented as plugins. In the end, this would be a question of which method would be more convenient for the user and would also allow more flexibility with less code: @vlomonaco I think I should've created a discussion instead of an issue. We can have a discussion with potential features for the base strategy and keep this one on the list for later consideration if it is interesting enough. |
Beta Was this translation helpful? Give feedback.
-
Feature request:
The base strategy always uses
avalanche_forward
inside itsforward
function. This can be limiting when the strategy's model has more than one output, for example,(hidden_feats, prediction)
. Also, it feeds thetask_labels
to the model only if it is an instance ofMultiTaskModule
, so if the model is single-head, it still has to inherit fromMultiTaskModule
to receivetask_labels
(for any purpose like task-based conditioning). There could be other cases where post-processing the model's output is needed.One solution would be defining an attribute called something like
foward_func
in the constructor of the base strategy initialized by its arguments and setting it asavalanche_forward
by default. Then the mainforward
function would change as below:What do you think about adding this change?
Beta Was this translation helpful? Give feedback.
All reactions