Open sebffischer opened 1 month ago
We need to implement our own Selector
-like class (SelectParamNames
?) that allows us to select some of the parameters in a neural network. They will be HOFs.
select_names(character())
-> (fn: char vector of full param names -> subsetted vec of param names) (implement sanity checks... are the provided names valid)select_grep(...)
-> (fn: char vector of full param names -> subsetted vec of param names) (pass on all arguments to base::grep()
When finetuning a predefined image network on a downstream task, one often wants to freeze some weights for a given number of epochs/steps. As this is relatively common, we should offer a predefined callback (
"cb.freeze"
) to do enable this.The callback should be able to iteratively unfreeze layers after a given number of epochs / batches.
Background:
Each torch module represents its parameters as a named
list()
:When we want to unfreeze a specific weight, we can refer to it via its name in this list. Further, we can freeze a parameter in a network by setting its
$requires_grad
field toFALSE
:We can unfreeze a parameter the same way:
The callback needs to define
layer8
after the first epoch,layer7
after the third, and the rest after the third epoch.I can e.g. imagine this callback to have the parameters:
start
:: ASelector
(see theaffect_columns
parameter inmlr3pipelines
. that defines which weights will be trained from the start (maybe a better name exists for the parameter).unfreeze
: adata.table()
with columnweights
(alist()
column containingSelector
) and a columnepoch
ORbatch
. If we had something like:this should be interpreted as unfreezing the
module$parameters$some_layer
after the first epoch and the rest after the second layer. If the name in thedata.table
is"batch"
instead of"epoch"
, this should work just the same but aftern
batches instead of epochs