- composer.functional.select_using_loss(input, target, model, loss_fun, keep=0.5, scale_factor=1)#
Prunes minibatches as a subroutine of
SelectiveBackprop. Computes the loss function on the provided training examples and runs minibatches according to the difficulty. The fraction of the minibatch that is kept for gradient computation is specified by the argument
0 <= keep <= 1.
To speed up SB’s selection forward pass, the argument
scale_factorcan be used to spatially downsample input tensors. The full-sized inputs will still be used for the weight gradient computation.
input (Tensor) – Input tensor to prune.
target (Tensor) – Output tensor to prune.
model (Callable) – Model with which to predict outputs.
loss_fun (Callable) – Loss function of the form
loss(outputs, targets, reduction='none'). The function must take the keyword argument
reduction='none'to ensure that per-sample losses are returned.
keep (float, optional) – Fraction of examples in the batch to keep. Default:
scale_factor (float, optional) – Multiplier between 0 and 1 for spatial size. Downsampling requires the input tensor to be at least 3D. Default:
(torch.Tensor, torch.Tensor) – The pruned batch of inputs and targets
This function runs an extra forward pass through the model on the batch of data. If you are using a non-default precision, ensure that this forward pass runs in your desired precision. For example:
>>> import torch >>> from composer.algorithms.selective_backprop import select_using_loss >>> with torch.cuda.amp.autocast(True): ... X_new, y_new = select_using_loss( ... X_sb, ... y_sb, ... lin_model, ... loss_fun, ... keep=0.5, ... scale_factor=1 ... )