Skip to main content

ClikaRT::nn::ConvTranspose

class

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

A bound, weight-packing transposed convolution, the public face of the runtime's packed conv-transpose, exposed as an nn::Module leaf. Unlike the stateless ops::conv_transpose* free functions (which re-pack the weight on every call), a ConvTranspose binds its weight ONCE and packs it into the backend's kernel layout; every forward reuses that packed weight. Build one per layer at load, reuse it every step.

The lifecycle (uniform across every weight-bearing nn module):

  1. make(in, out, kernel, options, ...), the ONE constructor: declares storage-free weight / bias slots under their canonical names.
  2. set_weights(w[, b]) (tensors in hand) or load_state_dict(...) (a checkpoint, by dotted name) binds the slots.
  3. forward(x) packs ON FIRST CALL (once, thread-safe), then serves the packed form every step. initialize() remains available as an optional warm-up.

Layout: activations are channels-last [N, D1..Dn, C]; the weight is INPUT-channel-first [in_channels, K1..Kn, out_channels/groups], the flip of Conv's OHWI, matching the transposed-conv convention. The kernel size vector fixes the spatial rank. Held via std::shared_ptr (an nn::Module leaf); copy/move are pinned by the base.

N-dimensional transposed-convolution module (learnable upsampling).

Channels-last; the weight is the transpose-flip of Conv's: input-channel-first [C_in, K.., O/groups] (C_in == weight[0], C_out == weight[-1] * groups), the module form of ops::conv_transpose1d/2d/3d. The module owns its weights: construct with make(...), or declare shapes and bind a checkpoint via load_state_dict. After the first forward (or initialize()) the weight lives ONLY in the backend's packed form (one resident copy); to(dtype) restores, casts, and repacks on the next forward.

auto up = ClikaRT::nn::ConvTranspose::make(W, b); // W: [C_in, K.., O/groups]
auto y = up->forward(x);

Static member functions

make()

static std::shared_ptr<ConvTranspose> make(
    std::int64_t in_channels,
    std::int64_t out_channels,
    Span<const std::int64_t> kernel,
    Span<const std::int64_t> stride = {},
    Span<const std::int64_t> padding = {},
    Span<const std::int64_t> output_padding = {},
    Span<const std::int64_t> dilation = {},
    std::int64_t groups = 1,
    bool bias = false,
    std::optional<ops::Activation> activation = std::nullopt,
    DataType dtype = DataType::Float32,
    Device device = Device::cpu()
)

Defaults: stride / padding / output_padding / dilation = empty (unit stride, no crop, zero output padding, unit dilation), groups = 1, bias = false (no bias slot), activation = none, dtype = Float32, device = CPU, so the three counts alone make a plain unit-stride transposed convolution.

Throws

  • ClikaRT::Error: as stated above.

Declared in ClikaRT/nn/conv_transpose.h, line 90

Member functions

~ConvTranspose()

~ConvTranspose() override

Declared in ClikaRT/nn/conv_transpose.h, line 104

set_weights()

void set_weights(Tensor weight, OptionalTensor bias = {})

Bind the declared slots positionally: weight (input-channel-first [in, K.., out/groups]) and, when the module was made with one, bias ([out]). The declared placement wins (the tensors move to it); shapes must match the declaration. Re-binding after a pack drops the pack; the next forward re-packs from the new weights. Raises ClikaRT::Error on a geometry mismatch or a bias without a declared bias slot.

Declared in ClikaRT/nn/conv_transpose.h, line 114

initialize_impl()

virtual Result<void> initialize_impl() override

Optional warm-up: run the first-forward pack NOW (idempotent, thread-safe). Every declared slot must hold a real (loaded) tensor; a still-fake slot is a clean error. After the pack the weight slot is released (the packed form is the single resident copy), so named_parameters() enumerates only the unpacked slots (the bias); a re-bind re-inserts and the next pack re-releases.

Declared in ClikaRT/nn/conv_transpose.h, line 124

to_impl(StreamOrDevice)

virtual Result<void> to_impl(StreamOrDevice where) override

Move to a placement or cast to a dtype; same contract as Conv: packed moves rebuild on the target; a dtype cast restores the raw weight from the pack, casts, and re-packs on the next forward.

Declared in ClikaRT/nn/conv_transpose.h, line 129

to_impl(DataType)

virtual Result<void> to_impl(DataType dtype) override

Declared in ClikaRT/nn/conv_transpose.h, line 130

forward()

Tensor forward(Tensor x) const

Apply the bound weight: x [N, D1..Dn, in] -> [N, O1..On, out] (then bias + activation if configured). The first call packs (once, thread-safe); every later call reuses the pack. Raises ClikaRT::Error on a shape/dtype mismatch or a still-fake slot.

Declared in ClikaRT/nn/conv_transpose.h, line 137