Reduce¶
- class continual.Reduce(reduce='sum')[source]¶
Reduce multiple input streams to a single using the selected function
For instance, here is how it is used to sum streams in a residual connection:
residual = co.Sequential( co.Broadcast(2), co.Parallel( co.Conv3d(32, 32, kernel_size=3, padding=1), co.Delay(2), ), co.Reduce("sum"), )
A user-defined can be passed as well:
from functools import reduce def my_sum(inputs): return reduce(torch.Tensor.add, inputs[1:], inputs[0]) residual = co.Sequential( co.Broadcast(2), co.Parallel( co.Conv3d(32, 32, kernel_size=3, padding=1), co.Delay(2), ), co.Reduce(my_sum), )
- Parameters:
reduce (Union[str, Callable[[Sequence[Tensor]], Tensor]]) – Reduce function. Either one of [“sum”, “channel”, “mul”, “max”] or user-defined function mapping a sequence of tensors to a single one.