Skip to main content

ClikaRT::nn::Sequential

class

Header: ClikaRT/nn/containers.h
Inherits: ClikaRT::nn::Module

Runs its steps in order, each fed the previous step's output.

A step is a module (registered under its position as its name, so named_children() and named_parameters() walk it: 0.weight, 1.bias) or a plain callable, which registers no child. The chain stops at the first failing step and returns that failure.

auto mlp = std::make_shared<ClikaRT::nn::Sequential>(
ClikaRT::nn::Linear::make(768, 3072),
std::make_shared<ClikaRT::nn::GELU>(),
ClikaRT::nn::Linear::make(3072, 768));
auto y = (*mlp)(x);

Types​

using Step​

using Step = std::function<Result<Tensor>(Tensor)>

One step: from the current tensor to the next, or to the failure that stops the chain.

Declared in ClikaRT/nn/containers.h, line 47

Member functions​

Sequential()​

Sequential() =default

Declared in ClikaRT/nn/containers.h, line 49

Sequential(shared_ptr<Ms>...)​

template <``class... Ms``>
explicit Sequential(std::shared_ptr<Ms>... modules)

Constructs from modules, appended in argument order.

Declared in ClikaRT/nn/containers.h, line 53

push_back(shared_ptr<M>)​

template <``class M, std::enable_if_t<std::is_base_of<nn::Module, M>::value, int> = 0``>
Sequential& push_back(std::shared_ptr<M> module)

Appends a module. It is registered under its position ("0", "1", ...) and runs through its forward_impl(Tensor).

Declared in ClikaRT/nn/containers.h, line 61

push_back(Step)​

Sequential& push_back(Step step)

Appends a callable step (a lambda, a function). It registers no child and holds no weights.

Declared in ClikaRT/nn/containers.h, line 73

size()​

std::size_t size() const

The number of steps, modules and callables alike.

Declared in ClikaRT/nn/containers.h, line 79

empty()​

bool empty() const

True when no step was appended.

Declared in ClikaRT/nn/containers.h, line 81

modules()​

const std::vector<std::shared_ptr<Module>>& modules() const

The modules appended so far, in order (callable steps are not modules and do not appear here).

Declared in ClikaRT/nn/containers.h, line 84

forward()​

Tensor forward(Tensor input) const

forward_impl, unwrapped: raises ClikaRT::Error on failure.

Declared in ClikaRT/nn/containers.h, line 102

operator()()​

Tensor operator()(Tensor input) const

Same as forward.

Declared in ClikaRT/nn/containers.h, line 106